use of org.springframework.data.mongodb.test.util.EnableIfReplicaSetAvailable in project spring-data-mongodb by spring-projects.
the class DefaultMessageListenerContainerTests method shouldReceiveMessagesWhenAddingRequestToAlreadyStartedContainer.
// DATAMONGO-1803
@Test
@EnableIfReplicaSetAvailable
public void shouldReceiveMessagesWhenAddingRequestToAlreadyStartedContainer() throws InterruptedException {
MessageListenerContainer container = new DefaultMessageListenerContainer(template);
container.start();
Document unexpected = new Document("_id", "id-1").append("value", "foo");
collection.insertOne(unexpected);
Subscription subscription = container.register(new ChangeStreamRequest(messageListener, options()), Document.class);
awaitSubscription(subscription, TIMEOUT);
Document expected = new Document("_id", "id-2").append("value", "bar");
collection.insertOne(expected);
awaitMessages(messageListener, 1, TIMEOUT);
container.stop();
assertThat(messageListener.getMessages().stream().map(Message::getBody).collect(Collectors.toList())).containsExactly(expected);
}
use of org.springframework.data.mongodb.test.util.EnableIfReplicaSetAvailable in project spring-data-mongodb by spring-projects.
the class SimpleMongoRepositoryTests method existsShouldBePossibleInTransaction.
// DATAMONGO-2130
@Test
@EnableIfReplicaSetAvailable
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
void existsShouldBePossibleInTransaction() {
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
TransactionTemplate tt = new TransactionTemplate(txmgr);
tt.afterPropertiesSet();
boolean exists = tt.execute(status -> {
Person sample = new Person();
sample.setLastname("Matthews");
repository.save(sample);
return repository.existsById(sample.getId());
});
assertThat(exists).isTrue();
}
use of org.springframework.data.mongodb.test.util.EnableIfReplicaSetAvailable in project spring-data-mongodb by spring-projects.
the class SimpleMongoRepositoryTests method countShouldBePossibleInTransaction.
// DATAMONGO-2130
@Test
@EnableIfReplicaSetAvailable
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
void countShouldBePossibleInTransaction() {
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
TransactionTemplate tt = new TransactionTemplate(txmgr);
tt.afterPropertiesSet();
long countPreTx = repository.count();
long count = tt.execute(status -> {
Person sample = new Person();
sample.setLastname("Matthews");
repository.save(sample);
return repository.count();
});
assertThat(count).isEqualTo(countPreTx + 1);
}
Aggregations