Search in sources :

Example 31 with ClusterDescription

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))));
}
Also used : ServerDescription(com.mongodb.connection.ServerDescription) ServerAddress(com.mongodb.ServerAddress) ClusterDescription(com.mongodb.connection.ClusterDescription) Test(org.junit.Test)

Aggregations

ClusterDescription (com.mongodb.connection.ClusterDescription)31 ServerAddress (com.mongodb.ServerAddress)15 ServerDescription (com.mongodb.connection.ServerDescription)12 Test (org.junit.Test)11 ServerSelector (com.mongodb.selector.ServerSelector)5 Test (org.junit.jupiter.api.Test)5 ReadPreferenceServerSelector (com.mongodb.internal.selector.ReadPreferenceServerSelector)3 List (java.util.List)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BsonDocument (org.bson.BsonDocument)3 ClientSessionOptions (com.mongodb.ClientSessionOptions)2 MongoException (com.mongodb.MongoException)2 MongoInterruptedException (com.mongodb.MongoInterruptedException)2 ClusterDescriptionChangedEvent (com.mongodb.event.ClusterDescriptionChangedEvent)2 ClusterOpeningEvent (com.mongodb.event.ClusterOpeningEvent)2 LatencyMinimizingServerSelector (com.mongodb.internal.selector.LatencyMinimizingServerSelector)2 BsonArray (org.bson.BsonArray)2 MongoClientException (com.mongodb.MongoClientException)1 MongoTimeoutException (com.mongodb.MongoTimeoutException)1 ReadPreference (com.mongodb.ReadPreference)1