use of org.springframework.data.mongodb.test.util.Template in project spring-data-mongodb by spring-projects.
the class DefaultReactiveIndexOperationsTests method shouldFavorExplicitMappingHintViaClass.
// DATAMONGO-1682, DATAMONGO-2198
@Test
public void shouldFavorExplicitMappingHintViaClass() {
IndexDefinition id = new Index().named("partial-with-inheritance").on("k3y", Direction.ASC).partial(of(where("age").gte(10)));
indexOps = new DefaultReactiveIndexOperations(template, this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class), new QueryMapper(template.getConverter()), MappingToSameCollection.class);
indexOps.ensureIndex(id).as(StepVerifier::create).expectNextCount(1).verifyComplete();
//
indexOps.getIndexInfo().filter(this.indexByName("partial-with-inheritance")).as(StepVerifier::create).consumeNextWith(indexInfo -> {
assertThat(Document.parse(indexInfo.getPartialFilterExpression())).isEqualTo(Document.parse("{ \"a_g_e\" : { \"$gte\" : 10 } }"));
}).verifyComplete();
}
use of org.springframework.data.mongodb.test.util.Template in project spring-data-mongodb by spring-projects.
the class DefaultMessageListenerContainerTests method shouldNotifyErrorHandlerOnErrorInListener.
// DATAMONGO-2322
@Test
@EnableIfReplicaSetAvailable
public void shouldNotifyErrorHandlerOnErrorInListener() throws InterruptedException {
ErrorHandler errorHandler = mock(ErrorHandler.class);
MessageListenerContainer container = new DefaultMessageListenerContainer(template);
AtomicBoolean thrownException = new AtomicBoolean();
Subscription subscription = container.register(new ChangeStreamRequest(message -> {
try {
if (thrownException.compareAndSet(false, true)) {
throw new IllegalStateException("Boom!");
}
} finally {
messageListener.onMessage(message);
}
}, options()), Person.class, errorHandler);
container.start();
awaitSubscription(subscription, TIMEOUT);
collection.insertOne(new Document("_id", "id-1").append("firstname", "foo"));
collection.insertOne(new Document("_id", "id-2").append("firstname", "bar"));
awaitMessages(messageListener, 2, TIMEOUT);
verify(errorHandler, atLeast(1)).handleError(any(IllegalStateException.class));
assertThat(messageListener.getTotalNumberMessagesReceived()).isEqualTo(2);
}
Aggregations