Search in sources :

Example 46 with ServerAddress

use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.

the class TestClusterableServerFactory method getBuilder.

private ServerDescription.Builder getBuilder(final ServerAddress serverAddress, final ServerType serverType, final List<ServerAddress> hosts, final List<ServerAddress> passives, final boolean ok, final String setName, final ObjectId electionId, final ServerAddress trueAddress) {
    Set<String> hostsSet = new HashSet<String>();
    for (ServerAddress cur : hosts) {
        hostsSet.add(cur.toString());
    }
    Set<String> passivesSet = new HashSet<String>();
    for (ServerAddress cur : passives) {
        passivesSet.add(cur.toString());
    }
    return ServerDescription.builder().address(serverAddress).type(serverType).ok(ok).state(CONNECTED).canonicalAddress(trueAddress == null ? serverAddress.toString() : trueAddress.toString()).hosts(hostsSet).passives(passivesSet).setName(setName).electionId(electionId).setVersion(1);
}
Also used : ServerAddress(com.mongodb.ServerAddress) HashSet(java.util.HashSet)

Example 47 with ServerAddress

use of com.mongodb.ServerAddress in project mongo-java-driver by mongodb.

the class CompositeServerSelectorTest method shouldPassOnClusterDescriptionWithCorrectServersAndSettings.

@Test
public void shouldPassOnClusterDescriptionWithCorrectServersAndSettings() {
    TestServerSelector firstSelector = new TestServerSelector();
    TestServerSelector secondSelector = new TestServerSelector();
    CompositeServerSelector composedSelector = new CompositeServerSelector(asList(firstSelector, secondSelector));
    composedSelector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, asList(first, second, third), ClusterSettings.builder().hosts(asList(new ServerAddress())).build(), ServerSettings.builder().build()));
    assertTrue(secondSelector.clusterDescription.getServerDescriptions().isEmpty());
    assertNotNull(secondSelector.clusterDescription.getClusterSettings());
    assertNotNull(secondSelector.clusterDescription.getServerSettings());
}
Also used : ServerAddress(com.mongodb.ServerAddress) ClusterDescription(com.mongodb.connection.ClusterDescription) Test(org.junit.Test)

Example 48 with ServerAddress

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

Example 49 with ServerAddress

use of com.mongodb.ServerAddress 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)

Example 50 with ServerAddress

use of com.mongodb.ServerAddress in project spring-boot by spring-projects.

the class MongoClientFactoryTests method portCanBeCustomized.

@Test
public void portCanBeCustomized() {
    MongoProperties properties = new MongoProperties();
    properties.setPort(12345);
    MongoClient client = createMongoClient(properties);
    List<ServerAddress> allAddresses = extractServerAddresses(client);
    assertThat(allAddresses).hasSize(1);
    assertServerAddress(allAddresses.get(0), "localhost", 12345);
}
Also used : MongoClient(com.mongodb.MongoClient) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Aggregations

ServerAddress (com.mongodb.ServerAddress)72 Test (org.junit.Test)27 MongoClient (com.mongodb.MongoClient)21 ArrayList (java.util.ArrayList)13 MongoCredential (com.mongodb.MongoCredential)10 Before (org.junit.Before)9 Document (org.bson.Document)5 TagSet (com.mongodb.TagSet)4 ClusterDescription (com.mongodb.connection.ClusterDescription)4 ClusterSettings (com.mongodb.connection.ClusterSettings)4 MongoClient (com.mongodb.reactivestreams.client.MongoClient)4 UnknownHostException (java.net.UnknownHostException)4 List (java.util.List)4 Tag (com.mongodb.Tag)3 MongoDatabase (com.mongodb.client.MongoDatabase)3 ServerDescription (com.mongodb.connection.ServerDescription)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ChunkInfo (org.apache.drill.exec.store.mongo.common.ChunkInfo)3 BsonDocument (org.bson.BsonDocument)3