Search in sources :

Example 6 with ServerAddress

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

the class ClusterDescriptionTest method testSortingOfAll.

@Test
@SuppressWarnings("deprecation")
public void testSortingOfAll() throws UnknownHostException {
    ClusterDescription description = new ClusterDescription(MULTIPLE, UNKNOWN, asList(builder().state(CONNECTING).address(new ServerAddress("loc:27019")).build(), builder().state(CONNECTING).address(new ServerAddress("loc:27018")).build(), builder().state(CONNECTING).address(new ServerAddress("loc:27017")).build()));
    Iterator<ServerDescription> iter = description.getAll().iterator();
    assertEquals(new ServerAddress("loc:27017"), iter.next().getAddress());
    assertEquals(new ServerAddress("loc:27018"), iter.next().getAddress());
    assertEquals(new ServerAddress("loc:27019"), iter.next().getAddress());
}
Also used : ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Example 7 with ServerAddress

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

the class ClusterDescriptionTest method setUp.

@Before
public void setUp() throws IOException {
    TagSet tags1 = new TagSet(asList(new Tag("foo", "1"), new Tag("bar", "2"), new Tag("baz", "1")));
    TagSet tags2 = new TagSet(asList(new Tag("foo", "1"), new Tag("bar", "2"), new Tag("baz", "2")));
    TagSet tags3 = new TagSet(asList(new Tag("foo", "1"), new Tag("bar", "3"), new Tag("baz", "3")));
    primary = builder().state(CONNECTED).address(new ServerAddress("localhost", 27017)).ok(true).type(REPLICA_SET_PRIMARY).tagSet(tags1).build();
    secondary = builder().state(CONNECTED).address(new ServerAddress("localhost", 27018)).ok(true).type(REPLICA_SET_SECONDARY).tagSet(tags2).build();
    otherSecondary = builder().state(CONNECTED).address(new ServerAddress("otherhost", 27019)).ok(true).type(REPLICA_SET_SECONDARY).tagSet(tags3).build();
    uninitiatedMember = builder().state(CONNECTED).address(new ServerAddress("localhost", 27020)).ok(true).type(REPLICA_SET_OTHER).build();
    notOkMember = builder().state(CONNECTED).address(new ServerAddress("localhost", 27021)).ok(false).build();
    List<ServerDescription> nodeList = asList(primary, secondary, otherSecondary, uninitiatedMember, notOkMember);
    cluster = new ClusterDescription(MULTIPLE, REPLICA_SET, nodeList);
}
Also used : TagSet(com.mongodb.TagSet) ServerAddress(com.mongodb.ServerAddress) Tag(com.mongodb.Tag) Before(org.junit.Before)

Example 8 with ServerAddress

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

the class X509AuthenticatorNoUserNameTest method before.

@Before
public void before() {
    connection = new TestInternalConnection(new ServerId(new ClusterId(), new ServerAddress("localhost", 27017)));
    connectionDescriptionThreeTwo = new ConnectionDescription(new ConnectionId(new ServerId(new ClusterId(), new ServerAddress())), new ServerVersion(3, 2), ServerType.STANDALONE, 1000, 16000, 48000);
    connectionDescriptionThreeFour = new ConnectionDescription(new ConnectionId(new ServerId(new ClusterId(), new ServerAddress())), new ServerVersion(3, 4), ServerType.STANDALONE, 1000, 16000, 48000);
    credential = MongoCredential.createMongoX509Credential("CN=client,OU=kerneluser,O=10Gen,L=New York City,ST=New York,C=US");
    subject = new X509Authenticator(this.credential);
}
Also used : ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Example 9 with ServerAddress

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

the class X509AuthenticatorUnitTest method before.

@Before
public void before() {
    connection = new TestInternalConnection(new ServerId(new ClusterId(), new ServerAddress("localhost", 27017)));
    connectionDescription = new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress()));
    credential = MongoCredential.createMongoX509Credential("CN=client,OU=kerneluser,O=10Gen,L=New York City,ST=New York,C=US");
    subject = new X509Authenticator(this.credential);
}
Also used : ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Example 10 with ServerAddress

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

the class LatencyMinimizingServerSelectorTest method testZeroLatencyDifferentialTolerance.

@Test
public void testZeroLatencyDifferentialTolerance() throws UnknownHostException {
    LatencyMinimizingServerSelector selector = new LatencyMinimizingServerSelector(0, TimeUnit.NANOSECONDS);
    ServerDescription primary = ServerDescription.builder().state(CONNECTED).address(new ServerAddress()).ok(true).type(ServerType.REPLICA_SET_PRIMARY).roundTripTime(10, TimeUnit.NANOSECONDS).build();
    ServerDescription secondaryOne = ServerDescription.builder().state(CONNECTED).address(new ServerAddress("localhost:27018")).ok(true).type(ServerType.REPLICA_SET_SECONDARY).roundTripTime(11, TimeUnit.NANOSECONDS).build();
    assertEquals(Arrays.asList(primary), selector.select(new ClusterDescription(MULTIPLE, REPLICA_SET, Arrays.asList(primary, secondaryOne))));
}
Also used : ServerDescription(com.mongodb.connection.ServerDescription) ServerAddress(com.mongodb.ServerAddress) ClusterDescription(com.mongodb.connection.ClusterDescription) Test(org.junit.Test)

Aggregations

ServerAddress (com.mongodb.ServerAddress)58 Test (org.junit.Test)22 MongoClient (com.mongodb.MongoClient)13 MongoCredential (com.mongodb.MongoCredential)9 ArrayList (java.util.ArrayList)9 Before (org.junit.Before)9 TagSet (com.mongodb.TagSet)4 ClusterDescription (com.mongodb.connection.ClusterDescription)4 ClusterSettings (com.mongodb.connection.ClusterSettings)4 MongoClient (com.mongodb.reactivestreams.client.MongoClient)4 Tag (com.mongodb.Tag)3 MongoDatabase (com.mongodb.client.MongoDatabase)3 ServerDescription (com.mongodb.connection.ServerDescription)3 UnknownHostException (java.net.UnknownHostException)3 Date (java.util.Date)3 ChunkInfo (org.apache.drill.exec.store.mongo.common.ChunkInfo)3 BsonDocument (org.bson.BsonDocument)3 DataXException (com.alibaba.datax.common.exception.DataXException)2 ConnectionString (com.mongodb.ConnectionString)2 MongoClientURI (com.mongodb.MongoClientURI)2