use of com.mongodb.internal.selector.ServerAddressSelector in project mongo-java-driver by mongodb.
the class ServerHelper method waitForLastRelease.
public static void waitForLastRelease(final ServerAddress address, final Cluster cluster) {
ConcurrentPool<UsageTrackingInternalConnection> pool = connectionPool(cluster.selectServer(new ServerAddressSelector(address)).getServer());
long startTime = System.currentTimeMillis();
while (pool.getInUseCount() > 0) {
try {
sleep(10);
if (System.currentTimeMillis() > startTime + ClusterFixture.TIMEOUT * 1000) {
throw new MongoTimeoutException("Timed out waiting for pool in use count to drop to 0. Now at: " + pool.getInUseCount());
}
} catch (InterruptedException e) {
throw new MongoInterruptedException("Interrupted", e);
}
}
}
use of com.mongodb.internal.selector.ServerAddressSelector in project mongo-java-driver by mongodb.
the class SingleServerClusterTest method shouldSuccessfullyQueryASecondaryWithPrimaryReadPreference.
@Test
public void shouldSuccessfullyQueryASecondaryWithPrimaryReadPreference() {
// given
ServerAddress secondary = getSecondary();
setUpCluster(secondary);
String collectionName = getClass().getName();
Connection connection = cluster.selectServer(new ServerAddressSelector(secondary)).getServer().getConnection();
// when
BsonDocument result = connection.command(getDefaultDatabaseName(), new BsonDocument("count", new BsonString(collectionName)), new NoOpFieldNameValidator(), ReadPreference.primary(), new BsonDocumentCodec(), NoOpSessionContext.INSTANCE, getServerApi(), IgnorableRequestContext.INSTANCE);
// then
assertEquals(new BsonDouble(1.0).intValue(), result.getNumber("ok").intValue());
}
Aggregations