use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateUpdateTests method aggregationUpdateUpsertsCorrectly.
// DATAMONGO-2331
@Test
public void aggregationUpdateUpsertsCorrectly() {
AggregationUpdate update = AggregationUpdate.update().set("title").toValue("The Burning White");
template.update(Book.class).matching(Query.query(Criteria.where("id").is(1))).apply(update).upsert().then().as(StepVerifier::create).verifyComplete();
all(Book.class).collectList().as(StepVerifier::create).consumeNextWith(it -> {
assertThat(it).containsExactly(org.bson.Document.parse("{\"_id\" : 1, \"title\" : \"The Burning White\" }"));
}).verifyComplete();
}
use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.
the class ReactiveChangeStreamOperationSupportTests method changeStreamEventsShouldBeConvertedCorrectly.
// DATAMONGO-1803
@Test
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
public void changeStreamEventsShouldBeConvertedCorrectly() throws InterruptedException {
BlockingQueue<ChangeStreamEvent<Person>> documents = new LinkedBlockingQueue<>(100);
Disposable disposable = //
template.changeStream(Person.class).listen().doOnNext(documents::add).subscribe();
// just give it some time to link to the collection.
Thread.sleep(500);
Person person1 = new Person("Spring", 38);
Person person2 = new Person("Data", 39);
Person person3 = new Person("MongoDB", 37);
Flux.merge(template.insert(person1).delayElement(Duration.ofMillis(2)), template.insert(person2).delayElement(Duration.ofMillis(2)), //
template.insert(person3).delayElement(Duration.ofMillis(2))).as(//
StepVerifier::create).expectNextCount(//
3).verifyComplete();
// just give it some time to link receive all events
Thread.sleep(500);
try {
assertThat(documents.stream().map(ChangeStreamEvent::getBody).collect(Collectors.toList())).containsOnly(person1, person2, person3);
} finally {
disposable.dispose();
}
}
use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.
the class ReactiveClientSessionTests method useMonoInCallback.
// DATAMONGO-1880
@Test
public void useMonoInCallback() {
ClientSession session = Mono.from(client.startSession(ClientSessionOptions.builder().causallyConsistent(true).build())).block();
assertThat(session.getOperationTime()).isNull();
//
template.withSession(() -> session).execute(action -> action.findOne(new Query(), Document.class, COLLECTION_NAME)).as(//
StepVerifier::create).expectNextCount(//
1).verifyComplete();
assertThat(session.getOperationTime()).isNotNull();
assertThat(session.getServerSession().isClosed()).isFalse();
session.close();
}
use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplateAuditingTests method auditingSetsLastModifiedDateCorrectlyForImmutableVersionedKotlinEntityOnSave.
// DATAMONGO-2346
@Test
void auditingSetsLastModifiedDateCorrectlyForImmutableVersionedKotlinEntityOnSave() {
KAuditableVersionedEntity entity = new KAuditableVersionedEntity(null, "value", null, null);
//
template.save(entity).delayElement(Duration.ofMillis(500)).flatMap(inserted -> //
template.save(inserted.withValue("changed-value")).map(//
updated -> Tuples.of(inserted, updated))).flatMap(tuple2 -> template.findOne(Query.query(Criteria.where("id").is(tuple2.getT1().getId())), KAuditableVersionedEntity.class).map(//
fetched -> Tuples.of(tuple2.getT1(), tuple2.getT2(), fetched))).as(//
StepVerifier::create).consumeNextWith(tuple3 -> {
assertThat(tuple3.getT2().getModificationDate()).isAfter(tuple3.getT1().getModificationDate());
assertThat(tuple3.getT3().getModificationDate()).isAfter(tuple3.getT1().getModificationDate());
assertThat(tuple3.getT3().getModificationDate()).isEqualTo(tuple3.getT2().getModificationDate().truncatedTo(ChronoUnit.MILLIS));
}).verifyComplete();
}
use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.
the class ReactiveMapReduceTests method mapReduceWithInlineResult.
// DATAMONGO-1890
@Test
public void mapReduceWithInlineResult() {
createMapReduceData();
template.mapReduce(new Query(), Person.class, "jmr1", ValueObject.class, mapFunction, reduceFunction, MapReduceOptions.options()).buffer(4).as(//
StepVerifier::create).consumeNextWith(result -> {
assertThat(result).containsExactlyInAnyOrder(new ValueObject("a", 1), new ValueObject("b", 2), new ValueObject("c", 2), new ValueObject("d", 1));
}).verifyComplete();
}
Aggregations