Search in sources :

Example 1 with LatencyMinimizingServerSelector

use of com.mongodb.internal.selector.LatencyMinimizingServerSelector in project mongo-java-driver by mongodb.

the class ServerSelectionSelectionTest method shouldPassAllOutcomes.

@Test
public void shouldPassAllOutcomes() {
    // skip this test because the driver prohibits maxStaleness or tagSets with mode of primary at a much lower level
    assumeTrue(!description.equals("max-staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.json"));
    ServerSelector serverSelector = null;
    List<ServerDescription> suitableServers = buildServerDescriptions(definition.getArray("suitable_servers", new BsonArray()));
    List<ServerDescription> selectedServers = null;
    try {
        serverSelector = getServerSelector();
        selectedServers = serverSelector.select(clusterDescription);
        if (error) {
            fail("Should have thrown exception");
        }
    } catch (MongoConfigurationException e) {
        if (!error) {
            fail("Should not have thrown exception: " + e);
        }
        return;
    }
    assertServers(selectedServers, suitableServers);
    ServerSelector latencyBasedServerSelector = new CompositeServerSelector(asList(serverSelector, new LatencyMinimizingServerSelector(15, TimeUnit.MILLISECONDS)));
    List<ServerDescription> inLatencyWindowServers = buildServerDescriptions(definition.getArray("in_latency_window"));
    List<ServerDescription> latencyBasedSelectedServers = latencyBasedServerSelector.select(clusterDescription);
    assertServers(latencyBasedSelectedServers, inLatencyWindowServers);
}
Also used : ServerSelector(com.mongodb.selector.ServerSelector) CompositeServerSelector(com.mongodb.selector.CompositeServerSelector) WritableServerSelector(com.mongodb.internal.selector.WritableServerSelector) LatencyMinimizingServerSelector(com.mongodb.internal.selector.LatencyMinimizingServerSelector) ReadPreferenceServerSelector(com.mongodb.internal.selector.ReadPreferenceServerSelector) MongoConfigurationException(com.mongodb.MongoConfigurationException) BsonArray(org.bson.BsonArray) LatencyMinimizingServerSelector(com.mongodb.internal.selector.LatencyMinimizingServerSelector) CompositeServerSelector(com.mongodb.selector.CompositeServerSelector) Test(org.junit.Test)

Example 2 with LatencyMinimizingServerSelector

use of com.mongodb.internal.selector.LatencyMinimizingServerSelector 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));
}
Also used : LatencyMinimizingServerSelector(com.mongodb.internal.selector.LatencyMinimizingServerSelector) ReadPreferenceServerSelector(com.mongodb.internal.selector.ReadPreferenceServerSelector) ClusterDescription(com.mongodb.connection.ClusterDescription) Test(org.junit.Test)

Aggregations

LatencyMinimizingServerSelector (com.mongodb.internal.selector.LatencyMinimizingServerSelector)2 ReadPreferenceServerSelector (com.mongodb.internal.selector.ReadPreferenceServerSelector)2 Test (org.junit.Test)2 MongoConfigurationException (com.mongodb.MongoConfigurationException)1 ClusterDescription (com.mongodb.connection.ClusterDescription)1 WritableServerSelector (com.mongodb.internal.selector.WritableServerSelector)1 CompositeServerSelector (com.mongodb.selector.CompositeServerSelector)1 ServerSelector (com.mongodb.selector.ServerSelector)1 BsonArray (org.bson.BsonArray)1