Search in sources :

Example 1 with LatencyMinimizingServerSelector

use of com.mongodb.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/server_selection/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 : ReadPreferenceServerSelector(com.mongodb.selector.ReadPreferenceServerSelector) WritableServerSelector(com.mongodb.selector.WritableServerSelector) ServerSelector(com.mongodb.selector.ServerSelector) CompositeServerSelector(com.mongodb.selector.CompositeServerSelector) LatencyMinimizingServerSelector(com.mongodb.selector.LatencyMinimizingServerSelector) MongoConfigurationException(com.mongodb.MongoConfigurationException) BsonArray(org.bson.BsonArray) LatencyMinimizingServerSelector(com.mongodb.selector.LatencyMinimizingServerSelector) CompositeServerSelector(com.mongodb.selector.CompositeServerSelector) Test(org.junit.Test)

Aggregations

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