use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project JavaForFun by gumartinm.
the class MongoConfiguration method reactiveMongoTemplate.
@Bean
@Override
public ReactiveMongoTemplate reactiveMongoTemplate() throws Exception {
ReactiveMongoTemplate reactiveMongoTemplate = new ReactiveMongoTemplate(reactiveMongoDbFactory(), super.mappingMongoConverter());
reactiveMongoTemplate.setWriteConcern(WriteConcern.ACKNOWLEDGED);
return reactiveMongoTemplate;
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-boot by spring-projects.
the class MongoReactiveHealthIndicatorTests method testMongoIsUp.
@Test
void testMongoIsUp() {
Document buildInfo = mock(Document.class);
given(buildInfo.getString("version")).willReturn("2.6.4");
ReactiveMongoTemplate reactiveMongoTemplate = mock(ReactiveMongoTemplate.class);
given(reactiveMongoTemplate.executeCommand("{ buildInfo: 1 }")).willReturn(Mono.just(buildInfo));
MongoReactiveHealthIndicator mongoReactiveHealthIndicator = new MongoReactiveHealthIndicator(reactiveMongoTemplate);
Mono<Health> health = mongoReactiveHealthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("version");
assertThat(h.getDetails().get("version")).isEqualTo("2.6.4");
}).verifyComplete();
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-boot by spring-projects.
the class MongoReactiveHealthIndicatorTests method testMongoIsDown.
@Test
void testMongoIsDown() {
ReactiveMongoTemplate reactiveMongoTemplate = mock(ReactiveMongoTemplate.class);
given(reactiveMongoTemplate.executeCommand("{ buildInfo: 1 }")).willThrow(new MongoException("Connection failed"));
MongoReactiveHealthIndicator mongoReactiveHealthIndicator = new MongoReactiveHealthIndicator(reactiveMongoTemplate);
Mono<Health> health = mongoReactiveHealthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
assertThat(h.getDetails()).containsOnlyKeys("error");
assertThat(h.getDetails().get("error")).isEqualTo(MongoException.class.getName() + ": Connection failed");
}).verifyComplete();
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTransactionManagerUnitTests method suspendTransactionWhilePropagationNotSupported.
// DATAMONGO-2265
@Test
void suspendTransactionWhilePropagationNotSupported() {
ReactiveMongoTransactionManager txManager = new ReactiveMongoTransactionManager(databaseFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(databaseFactory);
when(session.commitTransaction()).thenReturn(Mono.empty());
TransactionalOperator outer = TransactionalOperator.create(txManager, new DefaultTransactionDefinition());
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
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, never()).startTransaction();
verify(databaseFactory, times(1)).withSession(eq(session));
verify(databaseFactory, never()).withSession(eq(session2));
verify(db, times(2)).drop();
verify(session2, never()).close();
}
use of org.springframework.data.mongodb.core.ReactiveMongoTemplate in project spring-data-mongodb by spring-projects.
the class ReactiveAggregationUnitTests method setUp.
@BeforeEach
void setUp() {
factory = new SimpleReactiveMongoDatabaseFactory(mongoClient, "db");
template = new ReactiveMongoTemplate(factory);
when(mongoClient.getDatabase("db")).thenReturn(db);
when(db.getCollection(eq(INPUT_COLLECTION), any(Class.class))).thenReturn(collection);
when(collection.aggregate(anyList(), any(Class.class))).thenReturn(publisher);
when(publisher.allowDiskUse(any())).thenReturn(publisher);
when(publisher.collation(any())).thenReturn(publisher);
}
Aggregations