protected CassandraHostConfigurator getCHCForTest() { CassandraHostConfigurator chc = new CassandraHostConfigurator("127.0.0.1:9170"); chc.setMaxActive(2); return chc; } }
@Test(expected=IllegalArgumentException.class) public void testNullHostList() { new HConnectionManager(clusterName, new CassandraHostConfigurator()); }
@Test public void testSerialization() throws Exception { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9876"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(cassandraHostConfigurator); out.close(); byte[] serializedByteArray = bos.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(serializedByteArray); ObjectInputStream in = new ObjectInputStream(bin); CassandraHostConfigurator cassandraHostConfiguratorDeserialized = (CassandraHostConfigurator) in.readObject(); //TODO: define equality for CassandraHostConfigurator //assertSame(cassandraHostConfigurator, cassandraHostConfiguratorDeserialized); }
@Before public void setup() { cassandraHostConfigurator = new CassandraHostConfigurator("localhost"); connectionManager = Mockito.mock(HConnectionManager.class); cluster = Mockito.mock(ThriftCluster.class); Mockito.when(cluster.getConfigurator()).thenReturn(cassandraHostConfigurator); final KeyspaceDefinition kdef = Mockito.mock(KeyspaceDefinition.class); Mockito.when(kdef.getName()).thenReturn("TestKeyspace"); Mockito.when(cluster.describeKeyspaces()).thenReturn(new LinkedList<KeyspaceDefinition>() {{ add(kdef); }}); }
@Test(expected = IllegalArgumentException.class) public void testSettingInvalidExistingClassClientFactory() { CassandraHostConfigurator chc = new CassandraHostConfigurator("localhost"); chc.setClientFactoryClass(CassandraHostConfigurator.class.getCanonicalName()); } }
@Before public void setupCase() throws TTransportException, TException, IllegalArgumentException, NotFoundException, UnknownHostException, Exception { cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170"); connectionManager = new HConnectionManager(clusterName,cassandraHostConfigurator); }
@Test(expected = IllegalArgumentException.class) public void testSettingNotFoundClientFactory() { CassandraHostConfigurator chc = new CassandraHostConfigurator("localhost"); chc.setClientFactoryClass("NotARealClass"); }
protected void setupClient() { cassandraHostConfigurator = new CassandraHostConfigurator("127.0.0.1:9170"); configure(cassandraHostConfigurator); connectionManager = new HConnectionManager(clusterName,cassandraHostConfigurator); }
@Test public void testSimpleCassandraHostSetup() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170"); CassandraHost[] cassandraHosts = cassandraHostConfigurator.buildCassandraHosts(); assertEquals(1, cassandraHosts.length); }
@Test public void testHostnameOnlyDefaultPort() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost"); CassandraHost[] cassandraHosts = cassandraHostConfigurator.buildCassandraHosts(); assertEquals(CassandraHost.DEFAULT_PORT, cassandraHosts[0].getPort()); }
@Before public void setup() { // map cassandraHost --> arrayBlockingQueue of timestamp Longs // - if abq.size > size, && peekLast.get > time, add host to excludedMap<cassandraHost,timestampOfExclusion> for <suspendTime> ms // - background thread to sweep for exclusion time expiration every <sweepInterval> seconds // - getExcludedHosts calls excludedMap.keySet // // HTL with a three timeout trigger durring 500ms intervals CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170"); cassandraHostConfigurator.setHostTimeoutCounter(3); HConnectionManager connectionManager = new HConnectionManager("TestCluster", cassandraHostConfigurator); hostTimeoutTracker = new HostTimeoutTracker(connectionManager, cassandraHostConfigurator); }
@Test public void testSettingCorrectClientFactory() { CassandraHostConfigurator chc = new CassandraHostConfigurator("localhost"); chc.setClientFactoryClass(HKerberosSecuredThriftClientFactoryImpl.class.getSimpleName()); assertEquals(chc.getClientFactoryClass(), HKerberosSecuredThriftClientFactoryImpl.class); chc.setClientFactoryClass(HThriftClientFactoryImpl.class.getCanonicalName()); assertEquals(chc.getClientFactoryClass(), HThriftClientFactoryImpl.class); }
@Test public void testConfiguratorClockResolution() { // Define my own clock resolution. @SuppressWarnings("serial") class SequentialClockResolution implements ClockResolution { @Override public long createClock() { return System.currentTimeMillis() * -1; } } CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost"); cassandraHostConfigurator.setClockResolution(new SequentialClockResolution()); assertNotSame(CassandraHostConfigurator.DEF_CLOCK_RESOLUTION, cassandraHostConfigurator.getClockResolution()); }
@Test public void testCassandraHostSetupSplit() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170,localhost:9171,localhost:9172"); CassandraHost[] cassandraHosts = cassandraHostConfigurator.buildCassandraHosts(); assertEquals(3, cassandraHosts.length); assertEquals(9172, cassandraHosts[2].getPort()); }
@Test public void testConfiguratorPort() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost"); cassandraHostConfigurator.setPort(9177); CassandraHost[] cassandraHosts = cassandraHostConfigurator.buildCassandraHosts(); assertEquals(9177, cassandraHosts[0].getPort()); }
@Test public void testMarkHostDownWithNoRetry() { cassandraHostConfigurator = new CassandraHostConfigurator("127.0.0.1:9170"); cassandraHostConfigurator.setRetryDownedHosts(false); connectionManager = new HConnectionManager(clusterName, cassandraHostConfigurator); new CassandraHost("127.0.0.1", 9170); HClient client = connectionManager.borrowClient(); connectionManager.markHostAsDown(client.getCassandraHost()); assertEquals(0,connectionManager.getActivePools().size()); }
@Before public void setUp() throws Exception { super.setupClient(); KEYSPACE_DEV = new ThriftKsDef(new KsDef(KEYSPACE, "org.apache.cassandra.locator.SimpleStrategy", Arrays.asList(new CfDef[] { BLOB_CF_DEF }))); ((ThriftKsDef)KEYSPACE_DEV).setReplicationFactor(1); cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170"); cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator); keyspace = HFactory.createKeyspace(KEYSPACE, cassandraCluster); try { cassandraCluster.dropKeyspace(KEYSPACE); } catch (Exception e) { } cassandraCluster.addKeyspace(KEYSPACE_DEV); }
@Test public void testHostnameOnlyDefaultPortMultipleHosts() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("h1,h2,h3:1111"); CassandraHost[] cassandraHosts = cassandraHostConfigurator.buildCassandraHosts(); assertEquals(CassandraHost.DEFAULT_PORT, cassandraHosts[0].getPort()); assertEquals(CassandraHost.DEFAULT_PORT, cassandraHosts[1].getPort()); assertEquals(1111, cassandraHosts[2].getPort()); }
@Test public void testApplyConfig() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170"); cassandraHostConfigurator.setMaxActive(15); cassandraHostConfigurator.setMaxConnectTimeMillis(30000); cassandraHostConfigurator.setMaxLastSuccessTimeMillis(40000); CassandraHost extraHost = new CassandraHost("localhost:9171"); cassandraHostConfigurator.applyConfig(extraHost); assertEquals(15, extraHost.getMaxActive()); assertEquals(30000, extraHost.getMaxConnectTimeMillis()); assertEquals(40000, extraHost.getMaxLastSuccessTimeMillis()); }
@Before public void setupCase() { CassandraHostConfigurator chc = new CassandraHostConfigurator("127.0.0.1:9170"); chc.setMaxActive(2); cluster = getOrCreateCluster("MyCluster", chc); keyspace = createKeyspace(KEYSPACE, cluster); createMutator(keyspace, se) .addInsertion("getSliceTest_key3", cf, createColumn("birthyear1", 1974L, se, le)) .addInsertion("getSliceTest_key3", cf, createColumn("birthyear2", 1975L, se, le)) .addInsertion("getSliceTest_key3", cf, createColumn("birthyear3", 1976L, se, le)) .addInsertion("getSliceTest_key3", cf, createColumn("birthyear4", 1977L, se, le)) .addInsertion("getSliceTest_key3", cf, createColumn("birthyear5", 1978L, se, le)) .addInsertion("getSliceTest_key3", cf, createColumn("birthyear6", 1979L, se, le)) .execute(); }