Search in sources :

Example 16 with ClusterId

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

the class NativeAuthenticatorUnitTest 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()));
    MongoCredential credential = MongoCredential.createCredential("\u53f0\u5317", "database", "Ta\u0301ibe\u030Ci".toCharArray());
    subject = new NativeAuthenticator(new MongoCredentialWithCache(credential), ClusterConnectionMode.MULTIPLE, getServerApi());
}
Also used : ConnectionDescription(com.mongodb.connection.ConnectionDescription) ServerId(com.mongodb.connection.ServerId) ClusterId(com.mongodb.connection.ClusterId) MongoCredential(com.mongodb.MongoCredential) ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Example 17 with ClusterId

use of com.mongodb.connection.ClusterId 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(new MongoCredentialWithCache(credential), ClusterConnectionMode.MULTIPLE, getServerApi());
}
Also used : ConnectionDescription(com.mongodb.connection.ConnectionDescription) ServerId(com.mongodb.connection.ServerId) ClusterId(com.mongodb.connection.ClusterId) ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Example 18 with ClusterId

use of com.mongodb.connection.ClusterId in project brave by openzipkin.

the class ITMongoDBTracing method getClusterId.

@Before
public void getClusterId() throws Exception {
    // TODO: Figure out an easier way to get this!
    Field clusterIdField = Class.forName("com.mongodb.internal.connection.BaseCluster").getDeclaredField("clusterId");
    clusterIdField.setAccessible(true);
    ClusterId clusterId = (ClusterId) clusterIdField.get(((MongoClientImpl) mongoClient).getCluster());
    this.clusterId = clusterId.getValue();
}
Also used : Field(java.lang.reflect.Field) MongoClientImpl(com.mongodb.client.internal.MongoClientImpl) ClusterId(com.mongodb.connection.ClusterId) Before(org.junit.Before)

Example 19 with ClusterId

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

the class PlainAuthenticatorTest method setUp.

@Before
public void setUp() {
    String host = System.getProperty("org.mongodb.test.host");
    userName = System.getProperty("org.mongodb.test.userName");
    source = System.getProperty("org.mongod.test.source");
    password = System.getProperty("org.mongodb.test.password");
    internalConnection = new InternalStreamConnectionFactory(ClusterConnectionMode.SINGLE, streamFactory, null, null, null, Collections.<MongoCompressor>emptyList(), null, getServerApi()).create(new ServerId(new ClusterId(), new ServerAddress(host)));
    connectionDescription = new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress()));
}
Also used : ConnectionDescription(com.mongodb.connection.ConnectionDescription) ServerId(com.mongodb.connection.ServerId) ClusterId(com.mongodb.connection.ClusterId) ServerAddress(com.mongodb.ServerAddress) Before(org.junit.Before)

Example 20 with ClusterId

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

the class LoadBalancedClusterTest method shouldFailSelectServerAsynchronouslyWhenThereIsSRVMisconfiguration.

@Test
public void shouldFailSelectServerAsynchronouslyWhenThereIsSRVMisconfiguration() {
    // given
    String srvHostName = "foo.bar.com";
    ClusterSettings clusterSettings = ClusterSettings.builder().mode(ClusterConnectionMode.LOAD_BALANCED).srvHost(srvHostName).build();
    ClusterableServerFactory serverFactory = mockServerFactory();
    DnsSrvRecordMonitorFactory dnsSrvRecordMonitorFactory = mock(DnsSrvRecordMonitorFactory.class);
    when(dnsSrvRecordMonitorFactory.create(eq(srvHostName), eq(clusterSettings.getSrvServiceName()), any())).thenAnswer(invocation -> new TestDnsSrvRecordMonitor(invocation.getArgument(2)).hosts(Arrays.asList(new ServerAddress("host1"), new ServerAddress("host2"))));
    cluster = new LoadBalancedCluster(new ClusterId(), clusterSettings, serverFactory, dnsSrvRecordMonitorFactory);
    FutureResultCallback<ServerTuple> callback = new FutureResultCallback<>();
    cluster.selectServerAsync(mock(ServerSelector.class), callback);
    MongoClientException exception = assertThrows(MongoClientException.class, callback::get);
    assertEquals("In load balancing mode, the host must resolve to a single SRV record, but instead it resolved to multiple hosts", exception.getMessage());
}
Also used : FutureResultCallback(com.mongodb.async.FutureResultCallback) ClusterSettings(com.mongodb.connection.ClusterSettings) MongoClientException(com.mongodb.MongoClientException) ClusterId(com.mongodb.connection.ClusterId) ServerAddress(com.mongodb.ServerAddress) ServerSelector(com.mongodb.selector.ServerSelector) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterId (com.mongodb.connection.ClusterId)24 ServerAddress (com.mongodb.ServerAddress)19 ClusterSettings (com.mongodb.connection.ClusterSettings)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)13 Test (org.junit.jupiter.api.Test)12 ServerId (com.mongodb.connection.ServerId)7 Before (org.junit.Before)7 FutureResultCallback (com.mongodb.async.FutureResultCallback)6 ServerSelector (com.mongodb.selector.ServerSelector)6 MongoTimeoutException (com.mongodb.MongoTimeoutException)5 ConnectionDescription (com.mongodb.connection.ConnectionDescription)5 ServerSettings (com.mongodb.connection.ServerSettings)3 MongoClientException (com.mongodb.MongoClientException)2 MongoConfigurationException (com.mongodb.MongoConfigurationException)2 ConnectionId (com.mongodb.connection.ConnectionId)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 BsonDocument (org.bson.BsonDocument)2