NodeDiscovery { public void doAddNodes() { if (log.isDebugEnabled()) { log.debug("Node discovery running..."); } Set<CassandraHost> foundHosts = discoverNodes(); if (foundHosts != null && foundHosts.size() > 0) { log.info("Found {} new host(s) in Ring", foundHosts.size()); for (CassandraHost cassandraHost : foundHosts) { log.info("Addding found host {} to pool", cassandraHost); cassandraHostConfigurator.applyConfig(cassandraHost); connectionManager.addCassandraHost(cassandraHost); } } if (log.isDebugEnabled()) { log.debug("Node discovery run complete."); } } NodeDiscovery(CassandraHostConfigurator cassandraHostConfigurator, HConnectionManager connectionManager); void doAddNodes(); Set<CassandraHost> discoverNodes();  }
@Test public void testDoAdd() { List<TokenRange> tokens = createRange("localhost", "google.com"); Mockito.when(cluster.describeRing("TestKeyspace")).thenReturn(tokens); Mockito.when(cluster.getName()).thenReturn(TEST_CLUSTER_NAME); Mockito.when(connectionManager.getClusterName()).thenReturn(TEST_CLUSTER_NAME); Mockito.when(connectionManager.getHosts()).thenReturn(Sets.newHashSet(new CassandraHost("localhost",9160))); HFactory.setClusterForTest(cluster); NodeDiscovery q = new NodeDiscovery(cassandraHostConfigurator, connectionManager); q.doAddNodes(); Mockito.verify(connectionManager).addCassandraHost(new CassandraHost("google.com",9160)); }
@Test public void testMultipleAdded() { List<TokenRange> tokens = createRange("localhost", "google.com", "yahoo.com", "datastax.com"); Mockito.when(cluster.describeRing("TestKeyspace")).thenReturn(tokens); Mockito.when(cluster.getName()).thenReturn(TEST_CLUSTER_NAME); Mockito.when(connectionManager.getClusterName()).thenReturn(TEST_CLUSTER_NAME); Mockito.when(connectionManager.getHosts()).thenReturn(Sets.newHashSet(new CassandraHost("localhost",9160))); HFactory.setClusterForTest(cluster); NodeDiscovery q = new NodeDiscovery(cassandraHostConfigurator, connectionManager); q.doAddNodes(); Mockito.verify(connectionManager).addCassandraHost(new CassandraHost("google.com",9160)); Mockito.verify(connectionManager).addCassandraHost(new CassandraHost("yahoo.com",9160)); Mockito.verify(connectionManager).addCassandraHost(new CassandraHost("datastax.com",9160)); }