use of com.mongodb.MongoServerUnavailableException in project mongo-java-driver by mongodb.
the class DefaultConnectionPoolTest method shouldThrowOnPoolClosed.
@Test
public void shouldThrowOnPoolClosed() {
provider = new DefaultConnectionPool(SERVER_ID, connectionFactory, ConnectionPoolSettings.builder().maxSize(1).maxWaitTime(50, MILLISECONDS).build(), mockSdamProvider());
provider.close();
String expectedExceptionMessage = "The server at 127.0.0.1:27017 is no longer available";
MongoServerUnavailableException exception;
exception = assertThrows(MongoServerUnavailableException.class, () -> provider.get());
assertEquals(expectedExceptionMessage, exception.getMessage());
SupplyingCallback<InternalConnection> supplyingCallback = new SupplyingCallback<>();
provider.getAsync(supplyingCallback);
exception = assertThrows(MongoServerUnavailableException.class, supplyingCallback::get);
assertEquals(expectedExceptionMessage, exception.getMessage());
}
use of com.mongodb.MongoServerUnavailableException in project mongo-java-driver by mongodb.
the class DefaultServer method getConnectionAsync.
@Override
public void getConnectionAsync(final SingleResultCallback<AsyncConnection> callback) {
if (isClosed) {
callback.onResult(null, new MongoServerUnavailableException(String.format("The server at %s is no longer available", serverId.getAddress())));
return;
}
SdamIssue.Context exceptionContext = sdam.context();
operationBegin();
connectionPool.getAsync(new SingleResultCallback<InternalConnection>() {
@Override
public void onResult(final InternalConnection result, final Throwable t) {
if (t != null) {
try {
operationEnd();
sdam.handleExceptionBeforeHandshake(SdamIssue.specific(t, exceptionContext));
} finally {
callback.onResult(null, t);
}
} else {
callback.onResult(AsyncOperationCountTrackingConnection.decorate(DefaultServer.this, connectionFactory.createAsync(result, new DefaultServerProtocolExecutor(), clusterConnectionMode)), null);
}
}
});
}
Aggregations