use of com.mongodb.connection.ServerId in project mongo-java-driver by mongodb.
the class DefaultTestClusterableServerFactory method create.
@Override
public ClusterableServer create(final Cluster cluster, final ServerAddress serverAddress) {
ServerId serverId = new ServerId(cluster.getClusterId(), serverAddress);
if (clusterConnectionMode == ClusterConnectionMode.LOAD_BALANCED) {
return new LoadBalancedServer(serverId, new TestConnectionPool(), new TestConnectionFactory(), serverListenerFactory.create(serverAddress), cluster.getClock());
} else {
SameObjectProvider<SdamServerDescriptionManager> sdamProvider = SameObjectProvider.uninitialized();
TestServerMonitor serverMonitor = new TestServerMonitor(sdamProvider);
serverAddressToServerMonitorMap.put(serverAddress, serverMonitor);
ConnectionPool connectionPool = new TestConnectionPool();
ServerListener serverListener = serverListenerFactory.create(serverAddress);
SdamServerDescriptionManager sdam = new DefaultSdamServerDescriptionManager(cluster, serverId, serverListener, serverMonitor, connectionPool, clusterConnectionMode);
sdamProvider.initialize(sdam);
serverMonitor.start();
return new DefaultServer(serverId, clusterConnectionMode, connectionPool, new TestConnectionFactory(), serverMonitor, sdam, serverListener, null, cluster.getClock(), true);
}
}
use of com.mongodb.connection.ServerId in project mongo-java-driver by mongodb.
the class PlainAuthenticatorUnitTest 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.createPlainCredential("user", "$external", "pencil".toCharArray());
subject = new PlainAuthenticator(new MongoCredentialWithCache(credential), ClusterConnectionMode.MULTIPLE, getServerApi());
}
use of com.mongodb.connection.ServerId 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.ServerId 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.ServerId in project mongo-java-driver by mongodb.
the class DefaultConnectionPoolTest method newControllableConnectionFactory.
private static ControllableConnectionFactory newControllableConnectionFactory(final ExecutorService asyncOpenExecutor) {
ControllableConnectionFactory.OpenDurationHandle openDurationHandle = new ControllableConnectionFactory.OpenDurationHandle();
InternalConnectionFactory connectionFactory = (serverId, connectionGenerationSupplier) -> {
InternalConnection connection = mock(InternalConnection.class, withSettings().stubOnly());
when(connection.getGeneration()).thenReturn(connectionGenerationSupplier.getGeneration());
when(connection.getDescription()).thenReturn(new ConnectionDescription(serverId));
AtomicBoolean open = new AtomicBoolean(false);
when(connection.opened()).thenAnswer(invocation -> open.get());
Runnable doOpen = () -> {
sleepMillis(openDurationHandle.getDurationAndCountDown().toMillis());
if (ThreadLocalRandom.current().nextFloat() < 0.2) {
// add a bit more randomness
sleepMillis(ThreadLocalRandom.current().nextInt(7, 15));
}
open.set(true);
};
doAnswer(invocation -> {
doOpen.run();
return null;
}).when(connection).open();
doAnswer(invocation -> {
SingleResultCallback<?> callback = invocation.getArgument(0, SingleResultCallback.class);
asyncOpenExecutor.execute(() -> {
doOpen.run();
callback.onResult(null, null);
});
return null;
}).when(connection).openAsync(any());
return connection;
};
return new ControllableConnectionFactory(connectionFactory, openDurationHandle);
}
Aggregations