Search in sources :

Example 86 with StepVerifier

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Version(org.springframework.data.annotation.Version) ReplaceWithOperation(org.springframework.data.mongodb.core.aggregation.ReplaceWithOperation) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) ArrayList(java.util.ArrayList) Document(org.springframework.data.mongodb.core.mapping.Document) MongoClient(com.mongodb.reactivestreams.client.MongoClient) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions(org.assertj.core.api.Assertions) MongoTestUtils(org.springframework.data.mongodb.test.util.MongoTestUtils) Collection(java.util.Collection) EqualsAndHashCode(lombok.EqualsAndHashCode) Client(org.springframework.data.mongodb.test.util.Client) SetOperation(org.springframework.data.mongodb.core.aggregation.SetOperation) Field(org.springframework.data.mongodb.core.mapping.Field) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) ArithmeticOperators(org.springframework.data.mongodb.core.aggregation.ArithmeticOperators) Id(org.springframework.data.annotation.Id) AggregationUpdate(org.springframework.data.mongodb.core.aggregation.AggregationUpdate) EnableIfMongoServerVersion(org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion) MongoClientExtension(org.springframework.data.mongodb.test.util.MongoClientExtension) AggregationUpdate(org.springframework.data.mongodb.core.aggregation.AggregationUpdate) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 87 with StepVerifier

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();
    }
}
Also used : Disposable(reactor.core.Disposable) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) StepVerifier(reactor.test.StepVerifier) EnableIfMongoServerVersion(org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion) Test(org.junit.jupiter.api.Test)

Example 88 with StepVerifier

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();
}
Also used : Document(org.bson.Document) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) MongoTestUtils(org.springframework.data.mongodb.test.util.MongoTestUtils) Mono(reactor.core.publisher.Mono) ClientSession(com.mongodb.reactivestreams.client.ClientSession) Supplier(java.util.function.Supplier) Client(org.springframework.data.mongodb.test.util.Client) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) MongoClient(com.mongodb.reactivestreams.client.MongoClient) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ClientSessionOptions(com.mongodb.ClientSessionOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertions(org.assertj.core.api.Assertions) EnableIfMongoServerVersion(org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion) MongoClientExtension(org.springframework.data.mongodb.test.util.MongoClientExtension) EnableIfReplicaSetAvailable(org.springframework.data.mongodb.test.util.EnableIfReplicaSetAvailable) Query(org.springframework.data.mongodb.core.query.Query) ClientSession(com.mongodb.reactivestreams.client.ClientSession) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 89 with StepVerifier

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) AbstractReactiveMongoConfiguration(org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration) Tuples(reactor.util.function.Tuples) Version(org.springframework.data.annotation.Version) Autowired(org.springframework.beans.factory.annotation.Autowired) Document(org.springframework.data.mongodb.core.mapping.Document) MongoClient(com.mongodb.reactivestreams.client.MongoClient) ReactiveAuditorAware(org.springframework.data.domain.ReactiveAuditorAware) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) EnableReactiveMongoAuditing(org.springframework.data.mongodb.config.EnableReactiveMongoAuditing) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) KAuditableVersionedEntity(org.springframework.data.mongodb.core.KAuditableVersionedEntity) MongoTestUtils(org.springframework.data.mongodb.test.util.MongoTestUtils) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Set(java.util.Set) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) Client(org.springframework.data.mongodb.test.util.Client) LastModifiedDate(org.springframework.data.annotation.LastModifiedDate) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) LastModifiedBy(org.springframework.data.annotation.LastModifiedBy) ChronoUnit(java.time.temporal.ChronoUnit) ReactiveMongoTemplate(org.springframework.data.mongodb.core.ReactiveMongoTemplate) Bean(org.springframework.context.annotation.Bean) Id(org.springframework.data.annotation.Id) Collections(java.util.Collections) MongoClientExtension(org.springframework.data.mongodb.test.util.MongoClientExtension) KAuditableVersionedEntity(org.springframework.data.mongodb.core.KAuditableVersionedEntity) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 90 with StepVerifier

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();
}
Also used : Document(org.bson.Document) SimpleReactiveMongoDatabaseFactory(org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) Person(org.springframework.data.mongodb.core.Person) Mono(reactor.core.publisher.Mono) Test(org.junit.Test) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) Field(org.springframework.data.mongodb.core.mapping.Field) Flux(reactor.core.publisher.Flux) MongoDatabase(com.mongodb.reactivestreams.client.MongoDatabase) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Data(lombok.Data) Assertions(org.assertj.core.api.Assertions) ReactiveMongoTemplate(org.springframework.data.mongodb.core.ReactiveMongoTemplate) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Before(org.junit.Before) Query(org.springframework.data.mongodb.core.query.Query) StepVerifier(reactor.test.StepVerifier) Test(org.junit.Test)

Aggregations

StepVerifier (reactor.test.StepVerifier)234 Test (org.junit.jupiter.api.Test)176 Mono (reactor.core.publisher.Mono)111 Flux (reactor.core.publisher.Flux)92 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)77 Duration (java.time.Duration)76 BeforeEach (org.junit.jupiter.api.BeforeEach)60 Test (org.junit.Test)55 Query (org.springframework.data.mongodb.core.query.Query)54 Assertions (org.assertj.core.api.Assertions)53 Document (org.bson.Document)49 Arrays (java.util.Arrays)46 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)44 Criteria (org.springframework.data.mongodb.core.query.Criteria)44 TimeUnit (java.util.concurrent.TimeUnit)42 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)42 Disposable (reactor.core.Disposable)39 List (java.util.List)38 ClassPathResource (org.springframework.core.io.ClassPathResource)38 AtomicReference (java.util.concurrent.atomic.AtomicReference)37