use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method suspendTransactionWhilePropagationRequiresNew.
// DATAMONGO-2265
@Test
void suspendTransactionWhilePropagationRequiresNew() {
when(databaseFactory.withSession(session2)).thenReturn(databaseFactory2);
when(databaseFactory2.getMongoDatabase()).thenReturn(Mono.just(db2));
when(session2.getServerSession()).thenReturn(serverSession);
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.commitTransaction()).thenReturn(Mono.empty());
when(session2.commitTransaction()).thenReturn(Mono.empty());
TransactionalOperator outer = TransactionalOperator.create(txManager, new DefaultTransactionDefinition());
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionalOperator inner = TransactionalOperator.create(txManager, definition);
outer.execute(tx1 -> {
return template.execute(db -> {
db.drop();
return inner.execute(tx2 -> {
return template.execute(db2 -> {
db2.drop();
return Mono.empty();
});
});
});
}).as(StepVerifier::create).verifyComplete();
verify(session).startTransaction();
verify(session2).startTransaction();
verify(databaseFactory, times(1)).withSession(eq(session));
verify(databaseFactory).withSession(eq(session2));
verify(db).drop();
verify(db2).drop();
verify(session).close();
verify(session2).close();
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactivePerformanceTests method setUp.
@BeforeEach
public void setUp() throws Exception {
mongo = MongoClients.create();
SimpleReactiveMongoDatabaseFactory mongoDbFactory = new SimpleReactiveMongoDatabaseFactory(this.mongo, DATABASE_NAME);
MongoMappingContext context = new MongoMappingContext();
context.setInitialEntitySet(Collections.singleton(Person.class));
context.afterPropertiesSet();
converter = new MappingMongoConverter(new DbRefResolver() {
@Nullable
@Override
public Object resolveReference(MongoPersistentProperty property, Object source, ReferenceLookupDelegate referenceLookupDelegate, MongoEntityReader entityReader) {
return null;
}
@Override
public Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback, DbRefProxyHandler proxyHandler) {
return null;
}
@Override
public DBRef createDbRef(org.springframework.data.mongodb.core.mapping.DBRef annotation, MongoPersistentEntity<?> entity, Object id) {
return null;
}
@Override
public Document fetch(DBRef dbRef) {
return null;
}
@Override
public List<Document> bulkFetch(List<DBRef> dbRefs) {
return null;
}
}, context);
operations = new ReactiveMongoTemplate(mongoDbFactory, converter);
ReactiveMongoRepositoryFactory factory = new ReactiveMongoRepositoryFactory(operations);
repository = factory.getRepository(ReactivePersonRepository.class);
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveMongoPersistentEntityIndexCreatorUnitTests method setUp.
@BeforeEach
@SuppressWarnings("unchecked")
void setUp() {
when(factory.getExceptionTranslator()).thenReturn(new MongoExceptionTranslator());
when(factory.getMongoDatabase()).thenReturn(Mono.just(db));
when(db.getCollection(any(), any(Class.class))).thenReturn(collection);
indexOperations = new ReactiveMongoTemplate(factory).indexOps("foo");
keysCaptor = ArgumentCaptor.forClass(org.bson.Document.class);
optionsCaptor = ArgumentCaptor.forClass(IndexOptions.class);
collectionCaptor = ArgumentCaptor.forClass(String.class);
when(collection.createIndex(keysCaptor.capture(), optionsCaptor.capture())).thenReturn(Mono.just("OK"));
}
Aggregations