use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class LatencyMinimizingServerSelectorTest method testLatencyDifferentialMinimization.
@Test
public void testLatencyDifferentialMinimization() throws UnknownHostException {
LatencyMinimizingServerSelector selector = new LatencyMinimizingServerSelector(20, TimeUnit.MILLISECONDS);
ServerDescription primary = ServerDescription.builder().state(CONNECTED).address(new ServerAddress()).ok(true).type(ServerType.REPLICA_SET_PRIMARY).roundTripTime(10, TimeUnit.MILLISECONDS).build();
ServerDescription secondaryOne = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27018")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).roundTripTime(15, TimeUnit.MILLISECONDS).build();
ServerDescription secondaryTwo = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27019")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).roundTripTime(31, TimeUnit.MILLISECONDS).build();
ServerDescription secondaryThree = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27020")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).roundTripTime(30, TimeUnit.MILLISECONDS).build();
assertEquals(Arrays.asList(primary, secondaryOne, secondaryThree), selector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, Arrays.asList(primary, secondaryOne, secondaryTwo, secondaryThree))));
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class CompositeServerSelectorTest method shouldApplyServerSelectorsInOrder.
@Test
public void shouldApplyServerSelectorsInOrder() {
selector = new CompositeServerSelector(asList(new ReadPreferenceServerSelector(secondary()), new LatencyMinimizingServerSelector(15, MILLISECONDS)));
assertEquals(selector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, asList(first, second, third))), asList(second, third));
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class MongoClientDelegate method getConnectedClusterDescription.
private ClusterDescription getConnectedClusterDescription() {
ClusterDescription clusterDescription = cluster.getDescription();
if (getServerDescriptionListToConsiderForSessionSupport(clusterDescription).isEmpty()) {
cluster.selectServer(new ServerSelector() {
@Override
public List<ServerDescription> select(final ClusterDescription clusterDescription) {
return getServerDescriptionListToConsiderForSessionSupport(clusterDescription);
}
});
clusterDescription = cluster.getDescription();
}
return clusterDescription;
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class SingleServerCluster method publishDescription.
private void publishDescription(final ClusterType clusterType, final ServerDescription serverDescription) {
ClusterDescription currentDescription = getCurrentDescription();
ClusterDescription description = new ClusterDescription(ClusterConnectionMode.SINGLE, clusterType, serverDescription == null ? emptyList() : singletonList(serverDescription), getSettings(), getServerFactory().getSettings());
updateDescription(description);
fireChangeEvent(description, currentDescription);
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class MongoClientImplTest method testStartSession.
@Test
void testStartSession() {
ServerDescription serverDescription = ServerDescription.builder().address(new ServerAddress()).state(ServerConnectionState.CONNECTED).maxWireVersion(8).build();
MongoClientImpl mongoClient = createMongoClient();
Cluster cluster = mongoClient.getCluster();
when(cluster.getCurrentDescription()).thenReturn(new ClusterDescription(ClusterConnectionMode.SINGLE, ClusterType.STANDALONE, singletonList(serverDescription)));
ServerSessionPool serverSessionPool = mock(ServerSessionPool.class);
ClientSessionHelper clientSessionHelper = new ClientSessionHelper(mongoClient, serverSessionPool);
assertAll("Start Session Tests", () -> assertAll("check validation", () -> assertThrows(IllegalArgumentException.class, () -> mongoClient.startSession(null))), () -> {
Mono<ClientSession> expected = clientSessionHelper.createClientSessionMono(ClientSessionOptions.builder().build(), OPERATION_EXECUTOR);
assertPublisherIsTheSameAs(expected, mongoClient.startSession(), "Default");
}, () -> {
ClientSessionOptions options = ClientSessionOptions.builder().causallyConsistent(true).defaultTransactionOptions(TransactionOptions.builder().readConcern(ReadConcern.LINEARIZABLE).build()).build();
Mono<ClientSession> expected = clientSessionHelper.createClientSessionMono(options, OPERATION_EXECUTOR);
assertPublisherIsTheSameAs(expected, mongoClient.startSession(options), "with options");
});
}
Aggregations