Search in sources :

Example 1 with ServerSessionPool

use of com.mongodb.internal.session.ServerSessionPool in project mongo-java-driver by mongodb.

the class MongoClientImplTest method testStartSession.

@Test
void testStartSession() {
    ServerDescription serverDescription = ServerDescription.builder().address(new ServerAddress()).state(ServerConnectionState.CONNECTED).maxWireVersion(8).build();
    MongoClientImpl mongoClient = createMongoClient();
    Cluster cluster = mongoClient.getCluster();
    when(cluster.getCurrentDescription()).thenReturn(new ClusterDescription(ClusterConnectionMode.SINGLE, ClusterType.STANDALONE, singletonList(serverDescription)));
    ServerSessionPool serverSessionPool = mock(ServerSessionPool.class);
    ClientSessionHelper clientSessionHelper = new ClientSessionHelper(mongoClient, serverSessionPool);
    assertAll("Start Session Tests", () -> assertAll("check validation", () -> assertThrows(IllegalArgumentException.class, () -> mongoClient.startSession(null))), () -> {
        Mono<ClientSession> expected = clientSessionHelper.createClientSessionMono(ClientSessionOptions.builder().build(), OPERATION_EXECUTOR);
        assertPublisherIsTheSameAs(expected, mongoClient.startSession(), "Default");
    }, () -> {
        ClientSessionOptions options = ClientSessionOptions.builder().causallyConsistent(true).defaultTransactionOptions(TransactionOptions.builder().readConcern(ReadConcern.LINEARIZABLE).build()).build();
        Mono<ClientSession> expected = clientSessionHelper.createClientSessionMono(options, OPERATION_EXECUTOR);
        assertPublisherIsTheSameAs(expected, mongoClient.startSession(options), "with options");
    });
}
Also used : ServerSessionPool(com.mongodb.internal.session.ServerSessionPool) ServerDescription(com.mongodb.connection.ServerDescription) ClientSession(com.mongodb.reactivestreams.client.ClientSession) ServerAddress(com.mongodb.ServerAddress) Cluster(com.mongodb.internal.connection.Cluster) ClusterDescription(com.mongodb.connection.ClusterDescription) ClientSessionOptions(com.mongodb.ClientSessionOptions) Test(org.junit.jupiter.api.Test)

Aggregations

ClientSessionOptions (com.mongodb.ClientSessionOptions)1 ServerAddress (com.mongodb.ServerAddress)1 ClusterDescription (com.mongodb.connection.ClusterDescription)1 ServerDescription (com.mongodb.connection.ServerDescription)1 Cluster (com.mongodb.internal.connection.Cluster)1 ServerSessionPool (com.mongodb.internal.session.ServerSessionPool)1 ClientSession (com.mongodb.reactivestreams.client.ClientSession)1 Test (org.junit.jupiter.api.Test)1