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());
}
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());
}
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();
}
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()));
}
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());
}
Aggregations