NodeDiscovery { public Set<CassandraHost> discoverNodes() { Cluster cluster = HFactory.getCluster(connectionManager.getClusterName()); if (cluster == null) { return null; } Set<CassandraHost> existingHosts = connectionManager.getHosts(); Set<CassandraHost> foundHosts = new HashSet<CassandraHost>(); if (log.isDebugEnabled()) { log.debug("using existing hosts {}", existingHosts); } try { for (KeyspaceDefinition keyspaceDefinition : cluster.describeKeyspaces()) { if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) { List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName()); for (TokenRange tokenRange : tokenRanges) { for (EndpointDetails endPointDetail : tokenRange.getEndpoint_details()) { if (dataCenterValidator == null || dataCenterValidator.validate(endPointDetail.getDatacenter())) { CassandraHost foundHost = new CassandraHost(endPointDetail.getHost(), cassandraHostConfigurator.getPort()); if (!existingHosts.contains(foundHost)) { log.info("Found a node we don't know about {} for TokenRange {}", foundHost, tokenRange); foundHosts.add(foundHost); } } } } break; } } } catch (Exception e) { log.error("Discovery Service failed attempt to connect CassandraHost", e); } return foundHosts; } NodeDiscovery(CassandraHostConfigurator cassandraHostConfigurator, HConnectionManager connectionManager); void doAddNodes(); Set<CassandraHost> discoverNodes();  }
@Test public void testNoneAdded() { List<TokenRange> tokens = createRange("localhost"); 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); Assert.assertEquals(0, q.discoverNodes().size()); }