/** * The purpose of this test is to make sure that: When a TimedOutException is thrown out from * invoke method, the CassandraProxyClient will try at least maxAttempts times before throwing the * exception to the client. * * <p>A counter from the ThriftServer in BriskErrorDaemon tracks how many times the method has * been called. * * @throws Exception */ @Test public void testReconnect() throws Exception { EmbeddedBriskErrorServer.startBrisk(); Brisk.Iface client = CassandraProxyClient.newProxyConnection( "localhost", DatabaseDescriptor.getRpcPort(), true, ConnectionStrategy.STICKY); List<KsDef> ks = client.describe_keyspaces(); assertTrue(ks.size() > 0); try { client.get(ByteBufferUtil.EMPTY_BYTE_BUFFER, new ColumnPath("test"), ConsistencyLevel.ALL); fail("Expect a TimedoutException"); } catch (TimedOutException e) { // This is expected. } assertEquals( 11, client.get_count( ByteBufferUtil.EMPTY_BYTE_BUFFER, new ColumnParent("test"), new SlicePredicate(), ConsistencyLevel.ALL)); }
protected Configuration buildConfiguration() { Configuration conf = new Configuration(); conf.set(CassandraClientHolder.CONF_PARAM_HOST, "localhost"); conf.setInt(CassandraClientHolder.CONF_PARAM_PORT, DatabaseDescriptor.getRpcPort()); conf.setBoolean(CassandraClientHolder.CONF_PARAM_FRAMED, true); conf.set(CassandraClientHolder.CONF_PARAM_CONNECTION_STRATEGY, "STICKY"); conf.set("hive.metastore.warehouse.dir", "cfs:///user/hive/warehouse"); return conf; }
/** * When a cassandra server is not up, we expect that an IOException is thrown out from the method. */ @Test public void testNodeDown() { Brisk.Iface client = null; try { client = CassandraProxyClient.newProxyConnection( "localhost", DatabaseDescriptor.getRpcPort(), true, ConnectionStrategy.STICKY); fail("This should error"); } catch (IOException e) { } }
public void init(String keyspace) { outputHandler.output( String.format( "Starting client (and waiting %d seconds for gossip) ...", StorageService.RING_DELAY / 1000)); try { // Init gossip StorageService.instance.initClient(); Set<InetAddress> hosts = Gossiper.instance.getLiveMembers(); hosts.remove(FBUtilities.getLocalAddress()); if (hosts.isEmpty()) throw new IllegalStateException( "Cannot load any sstable, no live member found in the cluster"); // Query endpoint to ranges map and schemas from thrift String host = hosts.iterator().next().toString().substring(1); int port = DatabaseDescriptor.getRpcPort(); Cassandra.Client client = createThriftClient(host, port); List<TokenRange> tokenRanges = client.describe_ring(keyspace); List<KsDef> ksDefs = client.describe_keyspaces(); Token.TokenFactory tkFactory = StorageService.getPartitioner().getTokenFactory(); try { for (TokenRange tr : tokenRanges) { Range range = new Range(tkFactory.fromString(tr.start_token), tkFactory.fromString(tr.end_token)); for (String ep : tr.endpoints) { addRangeForEndpoint(range, InetAddress.getByName(ep)); } } } catch (UnknownHostException e) { throw new RuntimeException("Got an unknow host from describe_ring()", e); } for (KsDef ksDef : ksDefs) { Set<String> cfs = new HashSet<String>(); for (CfDef cfDef : ksDef.cf_defs) cfs.add(cfDef.name); knownCfs.put(ksDef.name, cfs); } } catch (Exception e) { throw new RuntimeException(e); } }