use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class ReadPreferenceWithFallbackServerSelectorTest method shouldSelectCorrectServersWhenAllServersAreAtLeastMinimum.
@Test
public void shouldSelectCorrectServersWhenAllServersAreAtLeastMinimum() {
ReadPreferenceWithFallbackServerSelector selector = new ReadPreferenceWithFallbackServerSelector(ReadPreference.secondary(), FIVE_DOT_ZERO_WIRE_VERSION, ReadPreference.primary());
ClusterDescription clusterDescription = new ClusterDescription(ClusterConnectionMode.MULTIPLE, ClusterType.REPLICA_SET, asList(builder().ok(true).state(CONNECTED).type(REPLICA_SET_PRIMARY).address(new ServerAddress("localhost:27017")).maxWireVersion(FIVE_DOT_ZERO_WIRE_VERSION).build(), builder().ok(true).state(CONNECTED).type(REPLICA_SET_SECONDARY).address(new ServerAddress("localhost:27018")).maxWireVersion(FIVE_DOT_ZERO_WIRE_VERSION).build()));
assertEquals(clusterDescription.getServerDescriptions().stream().filter(serverDescription -> serverDescription.getType() == REPLICA_SET_SECONDARY).collect(toList()), selector.select(clusterDescription));
assertEquals(ReadPreference.secondary(), selector.getAppliedReadPreference());
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class ReadPreferenceWithFallbackServerSelectorTest method shouldSelectCorrectServersWhenAtLeastOneServerIsOlderThanMinimum.
@Test
public void shouldSelectCorrectServersWhenAtLeastOneServerIsOlderThanMinimum() {
ReadPreferenceWithFallbackServerSelector selector = new ReadPreferenceWithFallbackServerSelector(ReadPreference.secondary(), FIVE_DOT_ZERO_WIRE_VERSION, ReadPreference.primary());
ClusterDescription clusterDescription = new ClusterDescription(ClusterConnectionMode.MULTIPLE, ClusterType.REPLICA_SET, asList(builder().ok(true).state(CONNECTED).type(REPLICA_SET_PRIMARY).address(new ServerAddress("localhost:27017")).maxWireVersion(FOUR_DOT_FOUR_WIRE_VERSION).build(), builder().ok(true).state(CONNECTED).type(REPLICA_SET_SECONDARY).address(new ServerAddress("localhost:27018")).maxWireVersion(FIVE_DOT_ZERO_WIRE_VERSION).build()));
assertEquals(clusterDescription.getServerDescriptions().stream().filter(serverDescription -> serverDescription.getType() == REPLICA_SET_PRIMARY).collect(toList()), selector.select(clusterDescription));
assertEquals(ReadPreference.primary(), selector.getAppliedReadPreference());
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class CompositeServerSelectorTest method shouldPassOnClusterDescriptionWithCorrectServersAndSettings.
@Test
public void shouldPassOnClusterDescriptionWithCorrectServersAndSettings() {
TestServerSelector firstSelector = new TestServerSelector();
TestServerSelector secondSelector = new TestServerSelector();
CompositeServerSelector composedSelector = new CompositeServerSelector(asList(firstSelector, secondSelector));
composedSelector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, asList(first, second, third), ClusterSettings.builder().hosts(asList(new ServerAddress())).build(), ServerSettings.builder().build()));
assertTrue(secondSelector.clusterDescription.getServerDescriptions().isEmpty());
assertNotNull(secondSelector.clusterDescription.getClusterSettings());
assertNotNull(secondSelector.clusterDescription.getServerSettings());
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class ServerSelectionWithinLatencyWindowTest method shouldPassAllOutcomes.
@Test
public void shouldPassAllOutcomes() {
ServerSelector selector = new ReadPreferenceServerSelector(ReadPreference.nearest());
Map<ServerAddress, List<ServerTuple>> selectionResultsGroupedByServerAddress = IntStream.range(0, iterations).mapToObj(i -> BaseCluster.selectServer(selector, clusterDescription, address -> Assertions.assertNotNull(serverCatalog.get(address)))).collect(groupingBy(serverTuple -> serverTuple.getServerDescription().getAddress()));
Map<ServerAddress, BigDecimal> selectionFrequencies = selectionResultsGroupedByServerAddress.entrySet().stream().collect(toMap(Map.Entry::getKey, entry -> BigDecimal.valueOf(entry.getValue().size()).setScale(2, RoundingMode.UNNECESSARY).divide(BigDecimal.valueOf(iterations), RoundingMode.HALF_UP)));
outcome.assertMatches(selectionFrequencies);
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class LatencyMinimizingServerSelectorTest method testZeroLatencyDifferentialTolerance.
@Test
public void testZeroLatencyDifferentialTolerance() throws UnknownHostException {
LatencyMinimizingServerSelector selector = new LatencyMinimizingServerSelector(0, TimeUnit.NANOSECONDS);
ServerDescription primary = ServerDescription.builder().state(CONNECTED).address(new ServerAddress()).ok(true).type(ServerType.REPLICA_SET_PRIMARY).roundTripTime(10, TimeUnit.NANOSECONDS).build();
ServerDescription secondaryOne = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27018")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).roundTripTime(11, TimeUnit.NANOSECONDS).build();
assertEquals(Arrays.asList(primary), selector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, Arrays.asList(primary, secondaryOne))));
}
Aggregations