Search in sources :

Example 1 with SupplyingCallback

use of com.mongodb.client.syncadapter.SupplyingCallback 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());
}
Also used : SupplyingCallback(com.mongodb.client.syncadapter.SupplyingCallback) MongoServerUnavailableException(com.mongodb.MongoServerUnavailableException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MongoServerUnavailableException (com.mongodb.MongoServerUnavailableException)1 SupplyingCallback (com.mongodb.client.syncadapter.SupplyingCallback)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1