@Test public void testSortingOfAll() throws UnknownHostException { ClusterDescription description = new ClusterDescription( Multiple, Unknown, Arrays.asList( ServerDescription.builder() .state(Connecting) .address(new ServerAddress("loc:27019")) .build(), ServerDescription.builder() .state(Connecting) .address(new ServerAddress("loc:27018")) .build(), ServerDescription.builder() .state(Connecting) .address(new ServerAddress("loc:27017")) .build())); Iterator<ServerDescription> iter = description.getAll().iterator(); assertEquals(new ServerAddress("loc:27017"), iter.next().getAddress()); assertEquals(new ServerAddress("loc:27018"), iter.next().getAddress()); assertEquals(new ServerAddress("loc:27019"), iter.next().getAddress()); }
@Override public List<ServerDescription> choose(final ClusterDescription clusterDescription) { return getServersWithAcceptableLatencyDifference( clusterDescription.getAll(), getBestPingTimeNanos(clusterDescription.getAll())); }
@Test public void testEmptySet() { ClusterDescription description = new ClusterDescription(Multiple, Unknown, Collections.<ServerDescription>emptyList()); assertTrue(description.getAll().isEmpty()); }