@Test public void shouldReturnAddressForSingleHostInPool() throws UnknownHostException { CassandraService cassandra = clientPoolWithServers(ImmutableSet.of(HOST_1)); InetSocketAddress resolvedHost = cassandra.getAddressForHost(HOSTNAME_1); assertThat(resolvedHost).isEqualTo(HOST_1); }
@VisibleForTesting InetSocketAddress getAddressForHost(String host) throws UnknownHostException { if (config.addressTranslation().containsKey(host)) { return config.addressTranslation().get(host); } InetAddress resolvedHost = InetAddress.getByName(host); Set<InetSocketAddress> allKnownHosts = Sets.union(currentPools.keySet(), config.servers().accept(new ThriftHostsExtractingVisitor())); for (InetSocketAddress address : allKnownHosts) { if (Objects.equals(address.getAddress(), resolvedHost)) { return address; } } Set<Integer> allKnownPorts = allKnownHosts.stream() .map(InetSocketAddress::getPort) .collect(Collectors.toSet()); if (allKnownPorts.size() == 1) { return new InetSocketAddress(resolvedHost, Iterables.getOnlyElement(allKnownPorts)); } else { throw new UnknownHostException("Couldn't find the provided host in server list or current servers"); } }
CassandraService implements AutoCloseable { @VisibleForTesting InetSocketAddress getAddressForHost(String host) throws UnknownHostException { if (config.addressTranslation().containsKey(host)) { return config.addressTranslation().get(host); } InetAddress resolvedHost = InetAddress.getByName(host); Set<InetSocketAddress> allKnownHosts = Sets.union(currentPools.keySet(), config.servers().accept(new ThriftHostsExtractingVisitor())); for (InetSocketAddress address : allKnownHosts) { if (Objects.equals(address.getAddress(), resolvedHost)) { return address; } } Set<Integer> allKnownPorts = allKnownHosts.stream() .map(InetSocketAddress::getPort) .collect(Collectors.toSet()); if (allKnownPorts.size() == 1) { return new InetSocketAddress(resolvedHost, Iterables.getOnlyElement(allKnownPorts)); } else { throw new UnknownHostException("Couldn't find the provided host in server list or current servers"); } } }
CassandraService implements AutoCloseable { @VisibleForTesting InetSocketAddress getAddressForHost(String host) throws UnknownHostException { if (config.addressTranslation().containsKey(host)) { return config.addressTranslation().get(host); } InetAddress resolvedHost = InetAddress.getByName(host); Set<InetSocketAddress> allKnownHosts = Sets.union(currentPools.keySet(), config.servers().accept(new ThriftHostsExtractingVisitor())); for (InetSocketAddress address : allKnownHosts) { if (Objects.equals(address.getAddress(), resolvedHost)) { return address; } } Set<Integer> allKnownPorts = allKnownHosts.stream() .map(InetSocketAddress::getPort) .collect(Collectors.toSet()); if (allKnownPorts.size() == 1) { return new InetSocketAddress(resolvedHost, Iterables.getOnlyElement(allKnownPorts)); } else { throw new UnknownHostException("Couldn't find the provided host in server list or current servers"); } } CassandraService(
            MetricsManager metricsManager,
            CassandraKeyValueServiceConfig config,
            Blacklist blacklist,
            CassandraClientPoolMetrics poolMetrics); }
CassandraService implements AutoCloseable { @VisibleForTesting InetSocketAddress getAddressForHost(String host) throws UnknownHostException { if (config.addressTranslation().containsKey(host)) { return config.addressTranslation().get(host); } InetAddress resolvedHost = InetAddress.getByName(host); Set<InetSocketAddress> allKnownHosts = Sets.union(currentPools.keySet(), config.servers().accept(new ThriftHostsExtractingVisitor())); for (InetSocketAddress address : allKnownHosts) { if (Objects.equals(address.getAddress(), resolvedHost)) { return address; } } Set<Integer> allKnownPorts = allKnownHosts.stream() .map(InetSocketAddress::getPort) .collect(Collectors.toSet()); if (allKnownPorts.size() == 1) { return new InetSocketAddress(resolvedHost, Iterables.getOnlyElement(allKnownPorts)); } else { throw new UnknownHostException("Couldn't find the provided host in server list or current servers"); } } CassandraService(
            MetricsManager metricsManager,
            CassandraKeyValueServiceConfig config,
            Blacklist blacklist,
            CassandraClientPoolMetrics poolMetrics); @Override void close(); Set<InetSocketAddress> refreshTokenRangesAndGetServers(); Set<InetSocketAddress> getLocalHosts(); Optional<CassandraClientPoolingContainer> getRandomGoodHostForPredicate(
            Predicate<InetSocketAddress> predicate); CassandraClientPoolingContainer getRandomGoodHost(); RangeMap<LightweightOppToken, List<InetSocketAddress>> getTokenMap(); Map<InetSocketAddress, CassandraClientPoolingContainer> getPools(); void debugLogStateOfPool(); InetSocketAddress getRandomHostForKey(byte[] key); void addPool(InetSocketAddress server); void removePool(InetSocketAddress removedServerAddress); void cacheInitialCassandraHosts(); void clearInitialCassandraHosts(); }
CassandraService implements AutoCloseable { @VisibleForTesting InetSocketAddress getAddressForHost(String host) throws UnknownHostException { if (config.addressTranslation().containsKey(host)) { return config.addressTranslation().get(host); } InetAddress resolvedHost = InetAddress.getByName(host); Set<InetSocketAddress> allKnownHosts = Sets.union(currentPools.keySet(), config.servers().accept(new ThriftHostsExtractingVisitor())); for (InetSocketAddress address : allKnownHosts) { if (Objects.equals(address.getAddress(), resolvedHost)) { return address; } } Set<Integer> allKnownPorts = allKnownHosts.stream() .map(InetSocketAddress::getPort) .collect(Collectors.toSet()); if (allKnownPorts.size() == 1) { return new InetSocketAddress(resolvedHost, Iterables.getOnlyElement(allKnownPorts)); } else { throw new UnknownHostException("Couldn't find the provided host in server list or current servers"); } } CassandraService(
            MetricsManager metricsManager,
            CassandraKeyValueServiceConfig config,
            Blacklist blacklist,
            CassandraClientPoolMetrics poolMetrics); @Override void close(); Set<InetSocketAddress> refreshTokenRangesAndGetServers(); Set<InetSocketAddress> getLocalHosts(); Optional<CassandraClientPoolingContainer> getRandomGoodHostForPredicate(
            Predicate<InetSocketAddress> predicate); CassandraClientPoolingContainer getRandomGoodHost(); RangeMap<LightweightOppToken, List<InetSocketAddress>> getTokenMap(); Map<InetSocketAddress, CassandraClientPoolingContainer> getPools(); void debugLogStateOfPool(); InetSocketAddress getRandomHostForKey(byte[] key); void addPool(InetSocketAddress server); void removePool(InetSocketAddress removedServerAddress); void cacheInitialCassandraHosts(); void clearInitialCassandraHosts();  }