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 ServerAddressSelectorTest method testAll.
@Test
public void testAll() throws UnknownHostException {
ServerAddressSelector selector = new ServerAddressSelector(new ServerAddress("localhost:27018"));
assertTrue(selector.toString().startsWith("ServerAddressSelector"));
assertEquals(selector.getServerAddress(), selector.getServerAddress());
ServerDescription primary = ServerDescription.builder().state(CONNECTED).address(new ServerAddress()).ok(true).type(ServerType.REPLICA_SET_PRIMARY).build();
ServerDescription secondary = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27018")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).build();
assertEquals(Arrays.asList(secondary), selector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, Arrays.asList(primary, secondary))));
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class CompositeServerSelector method select.
@Override
public List<ServerDescription> select(final ClusterDescription clusterDescription) {
ClusterDescription curClusterDescription = clusterDescription;
List<ServerDescription> choices = null;
for (ServerSelector cur : serverSelectors) {
choices = cur.select(curClusterDescription);
curClusterDescription = new ClusterDescription(clusterDescription.getConnectionMode(), clusterDescription.getType(), choices, clusterDescription.getClusterSettings(), clusterDescription.getServerSettings());
}
return choices;
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class LoadBalancedCluster method init.
private void init(final ClusterId clusterId, final ClusterableServerFactory serverFactory, final ServerAddress host) {
clusterListener.clusterOpening(new ClusterOpeningEvent(clusterId));
ClusterDescription initialDescription = new ClusterDescription(settings.getMode(), ClusterType.LOAD_BALANCED, singletonList(ServerDescription.builder().address(settings.getHosts().get(0)).state(CONNECTING).build()), settings, serverFactory.getSettings());
clusterListener.clusterDescriptionChanged(new ClusterDescriptionChangedEvent(clusterId, initialDescription, description));
description = new ClusterDescription(ClusterConnectionMode.LOAD_BALANCED, ClusterType.LOAD_BALANCED, singletonList(ServerDescription.builder().ok(true).state(ServerConnectionState.CONNECTED).type(ServerType.LOAD_BALANCER).address(host).build()), settings, serverFactory.getSettings());
server = serverFactory.create(this, host);
clusterListener.clusterDescriptionChanged(new ClusterDescriptionChangedEvent(clusterId, description, initialDescription));
}
use of com.mongodb.connection.ClusterDescription in project mongo-java-driver by mongodb.
the class MongoClientDelegate method createClientSession.
@Nullable
public ClientSession createClientSession(final ClientSessionOptions options, final ReadConcern readConcern, final WriteConcern writeConcern, final ReadPreference readPreference) {
notNull("readConcern", readConcern);
notNull("writeConcern", writeConcern);
notNull("readPreference", readPreference);
ClusterDescription connectedClusterDescription = getConnectedClusterDescription();
if (connectedClusterDescription.getLogicalSessionTimeoutMinutes() == null && connectedClusterDescription.getConnectionMode() != ClusterConnectionMode.LOAD_BALANCED) {
return null;
} else {
ClientSessionOptions mergedOptions = ClientSessionOptions.builder(options).defaultTransactionOptions(TransactionOptions.merge(options.getDefaultTransactionOptions(), TransactionOptions.builder().readConcern(readConcern).writeConcern(writeConcern).readPreference(readPreference).build())).build();
return new ClientSessionImpl(serverSessionPool, originator, mergedOptions, this);
}
}
Aggregations