use of com.mongodb.session.ClientSession in project spring-data-mongodb by spring-projects.
the class ClientSessionTests method shouldApplyClientSession.
// DATAMONGO-1880
@Test
public void shouldApplyClientSession() {
ClientSession session = client.startSession(ClientSessionOptions.builder().causallyConsistent(true).build());
assertThat(session.getOperationTime()).isNull();
Document doc = template.withSession(() -> session).execute(action -> action.findOne(new Query(), Document.class, "test"));
assertThat(doc).isNotNull();
assertThat(session.getOperationTime()).isNotNull();
assertThat(session.getServerSession().isClosed()).isFalse();
session.close();
}
use of com.mongodb.session.ClientSession in project spring-data-mongodb by spring-projects.
the class SessionAwareMethodInterceptorUnitTests method proxyFactoryOnDatabaseWithSessionInArgumentListProceedsWithExecution.
// DATAMONGO-1880
@Test
public void proxyFactoryOnDatabaseWithSessionInArgumentListProceedsWithExecution() {
ClientSession yetAnotherSession = mock(ClientSession.class);
database.drop(yetAnotherSession);
verify(targetDatabase).drop(eq(yetAnotherSession));
}
use of com.mongodb.session.ClientSession in project spring-data-mongodb by spring-projects.
the class SessionAwareMethodInterceptorUnitTests method proxyFactoryOnCollectionWithSessionInArgumentListProceedsWithExecution.
// DATAMONGO-1880
@Test
public void proxyFactoryOnCollectionWithSessionInArgumentListProceedsWithExecution() {
ClientSession yetAnotherSession = mock(ClientSession.class);
collection.find(yetAnotherSession);
verify(targetCollection).find(eq(yetAnotherSession));
}
use of com.mongodb.session.ClientSession in project spring-data-mongodb by spring-projects.
the class SessionBoundMongoTemplateUnitTests method setUp.
@Before
public void setUp() {
when(client.getDatabase(anyString())).thenReturn(database);
when(codecRegistry.get(any(Class.class))).thenReturn(new BsonValueCodec());
when(database.getCodecRegistry()).thenReturn(codecRegistry);
when(database.getCollection(anyString(), any())).thenReturn(collection);
when(database.listCollectionNames(any(ClientSession.class))).thenReturn(mongoIterable);
when(collection.find(any(ClientSession.class), any(), any())).thenReturn(findIterable);
when(collection.aggregate(any(ClientSession.class), anyList(), any())).thenReturn(aggregateIterable);
when(collection.distinct(any(ClientSession.class), any(), any(), any())).thenReturn(distinctIterable);
when(collection.mapReduce(any(ClientSession.class), any(), any(), any())).thenReturn(mapReduceIterable);
when(findIterable.iterator()).thenReturn(cursor);
when(aggregateIterable.collation(any())).thenReturn(aggregateIterable);
when(aggregateIterable.allowDiskUse(anyBoolean())).thenReturn(aggregateIterable);
when(aggregateIterable.batchSize(anyInt())).thenReturn(aggregateIterable);
when(aggregateIterable.map(any())).thenReturn(aggregateIterable);
when(aggregateIterable.useCursor(anyBoolean())).thenReturn(aggregateIterable);
when(aggregateIterable.into(any())).thenReturn(Collections.emptyList());
when(mongoIterable.iterator()).thenReturn(cursor);
when(distinctIterable.map(any())).thenReturn(distinctIterable);
when(distinctIterable.into(any())).thenReturn(Collections.emptyList());
when(mapReduceIterable.sort(any())).thenReturn(mapReduceIterable);
when(mapReduceIterable.filter(any())).thenReturn(mapReduceIterable);
when(mapReduceIterable.map(any())).thenReturn(mapReduceIterable);
when(mapReduceIterable.iterator()).thenReturn(cursor);
when(cursor.hasNext()).thenReturn(false);
when(findIterable.projection(any())).thenReturn(findIterable);
factory = new SimpleMongoDbFactory(client, "foo");
this.mappingContext = new MongoMappingContext();
this.converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), mappingContext);
this.template = new SessionBoundMongoTemplate(clientSession, new MongoTemplate(factory, converter));
}
use of com.mongodb.session.ClientSession in project spring-data-mongodb by spring-projects.
the class ReactiveClientSessionTests method reusesClientSessionInSessionScopedCallback.
// DATAMONGO-1880
@Test
public void reusesClientSessionInSessionScopedCallback() {
ClientSession session = Mono.from(client.startSession(ClientSessionOptions.builder().causallyConsistent(true).build())).block();
CountingSessionSupplier sessionSupplier = new CountingSessionSupplier(session);
ReactiveSessionScoped sessionScoped = template.withSession(sessionSupplier);
sessionScoped.execute(action -> action.findOne(new Query(), Document.class, "test")).blockFirst();
assertThat(sessionSupplier.getInvocationCount()).isEqualTo(1);
sessionScoped.execute(action -> action.findOne(new Query(), Document.class, "test")).blockFirst();
assertThat(sessionSupplier.getInvocationCount()).isEqualTo(1);
}
Aggregations