Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Replace usage of StepVerifier.create with StepVerifier::create.

Original pull request: #672
See #671
  • Loading branch information
christophstrobl authored and mp911de committed Nov 2, 2023
1 parent f98c7b9 commit e66d317
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void setUp() {
new Person("Jesse", "Pinkman", 27))) //
.flatMap(template::insert);

StepVerifier.create(truncateAndInsert).expectNextCount(4).verifyComplete();
truncateAndInsert.as(StepVerifier::create) //
.expectNextCount(4) //
.verifyComplete();
}

/**
Expand All @@ -67,6 +69,8 @@ void shouldInsertAndCountData() {
.flatMap(v -> template.count(Person.class)) //
.doOnNext(System.out::println);

StepVerifier.create(saveAndCount).expectNext(6L).verifyComplete();
saveAndCount.as(StepVerifier::create) //
.expectNext(6L) //
.verifyComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ void setUp() {
new Person("Saul", "Goodman", 42), //
new Person("Jesse", "Pinkman", 27))));

StepVerifier.create(deleteAndInsert).expectNextCount(4).verifyComplete();
deleteAndInsert.as(StepVerifier::create) //
.expectNextCount(4) //
.verifyComplete();
}

/**
Expand All @@ -67,7 +69,9 @@ void shouldInsertAndCountData() {
.flatMap(v -> repository.count()) //
.doOnNext(System.out::println);

StepVerifier.create(saveAndCount).expectNext(6L).verifyComplete();
saveAndCount.as(StepVerifier::create) //
.expectNext(6L) //
.verifyComplete();
}

/**
Expand All @@ -77,7 +81,7 @@ void shouldInsertAndCountData() {
@Test
void shouldPerformConversionBeforeResultProcessing() {

StepVerifier.create(repository.findAll().doOnNext(System.out::println)) //
repository.findAll().doOnNext(System.out::println).as(StepVerifier::create) //
.expectNextCount(4) //
.verifyComplete();
}
Expand All @@ -87,31 +91,43 @@ void shouldPerformConversionBeforeResultProcessing() {
*/
@Test
void shouldQueryDataWithQueryDerivation() {
StepVerifier.create(repository.findByLastname("White")).expectNextCount(2).verifyComplete();

repository.findByLastname("White").as(StepVerifier::create) //
.expectNextCount(2) //
.verifyComplete();
}

/**
* Fetch data limiting result size.
*/
@Test
void limitResultSize() {
StepVerifier.create(repository.findByLastname("White", Limit.of(1))).expectNextCount(1).verifyComplete();

repository.findByLastname("White", Limit.of(1)).as(StepVerifier::create) //
.expectNextCount(1) //
.verifyComplete();
}

/**
* Fetch data using a string query.
*/
@Test
void shouldQueryDataWithStringQuery() {
StepVerifier.create(repository.findByFirstnameInAndLastname("Walter", "White")).expectNextCount(1).verifyComplete();

repository.findByFirstnameInAndLastname("Walter", "White").as(StepVerifier::create) //
.expectNextCount(1) //
.verifyComplete();
}

/**
* Fetch data using query derivation.
*/
@Test
void shouldQueryDataWithDeferredQueryDerivation() {
StepVerifier.create(repository.findByLastname(Mono.just("White"))).expectNextCount(2).verifyComplete();

repository.findByLastname(Mono.just("White")).as(StepVerifier::create) //
.expectNextCount(2) //
.verifyComplete();
}

/**
Expand All @@ -120,7 +136,7 @@ void shouldQueryDataWithDeferredQueryDerivation() {
@Test
void shouldQueryDataWithMixedDeferredQueryDerivation() {

StepVerifier.create(repository.findByFirstnameAndLastname(Mono.just("Walter"), "White")) //
repository.findByFirstnameAndLastname(Mono.just("Walter"), "White").as(StepVerifier::create) //
.expectNextCount(1) //
.verifyComplete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,28 +200,31 @@ public void reactiveChangeEvents() {
ChangeStreamOptions.builder().filter(newAggregation(match(where("operationType").is("insert")))).build(),
Person.class);

StepVerifier.create(changeStream) //
changeStream.as(StepVerifier::create) //
.expectSubscription() //
.expectNoEvent(Duration.ofMillis(200)) // wait till change streams becomes active

// Save documents and await their change events
.then(() -> {
StepVerifier.create(reactiveTemplate.save(gabriel)).expectNextCount(1).verifyComplete();
StepVerifier.create(reactiveTemplate.save(ash)).expectNextCount(1).verifyComplete();
reactiveTemplate.save(gabriel).as(StepVerifier::create).expectNextCount(1).verifyComplete();
reactiveTemplate.save(ash).as(StepVerifier::create).expectNextCount(1).verifyComplete();
}).expectNextCount(2) //

// Update a document
.then(() -> {

StepVerifier.create(reactiveTemplate.update(Person.class) //
reactiveTemplate.update(Person.class) //
.matching(query(where("id").is(ash.id()))) //
.apply(update("age", 40)) //
.first()).expectNextCount(1).verifyComplete();
.first() //
.as(StepVerifier::create) //
.expectNextCount(1) //
.verifyComplete();
}).expectNoEvent(Duration.ofMillis(200)) // updates are skipped

// Save another document and await its change event
.then(() -> {
StepVerifier.create(reactiveTemplate.save(michael)).expectNextCount(1).verifyComplete();
reactiveTemplate.save(michael).as(StepVerifier::create).expectNextCount(1).verifyComplete();
}).expectNextCount(1) // there we go, all events received.

.thenCancel() // change streams are infinite streams, at some point we need to unsubscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static void setProperties(DynamicPropertyRegistry registry) {
@BeforeEach
void setUp() {

StepVerifier.create(template.dropCollection(Person.class)).verifyComplete();
template.dropCollection(Person.class).as(StepVerifier::create) //
.verifyComplete();

var insertAll = template
.insertAll(Flux.just(new Person("Walter", "White", 50), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void iterateOverKeysMatchingPrefixUsingKeysCommand() {
.count() //
.doOnSuccess(count -> System.out.println(String.format("Total No. found: %s", count)));

StepVerifier.create(keyCount).expectNext(50L).verifyComplete();
keyCount.as(StepVerifier::create).expectNext(50L).verifyComplete();
}

/**
Expand All @@ -98,7 +98,7 @@ void storeToListAndPop() {
.flatMap(result -> llen) //
.doOnNext(count -> System.out.println(String.format("Total items in list left: %s", count)));//

StepVerifier.create(popAndLlen).expectNext(0L).verifyComplete();
popAndLlen.as(StepVerifier::create).expectNext(0L).verifyComplete();
}

private void generateRandomKeys(int nrKeys) {
Expand All @@ -109,7 +109,9 @@ private void generateRandomKeys(int nrKeys) {
.map(key -> SetCommand.set(key) //
.value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes())));

StepVerifier.create(connection.stringCommands().set(generator)).expectNextCount(nrKeys).verifyComplete();
connection.stringCommands().set(generator).as(StepVerifier::create) //
.expectNextCount(nrKeys) //
.verifyComplete();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class JacksonJsonTests {
@Test
void shouldWriteAndReadPerson() {

StepVerifier.create(typedOperations.opsForValue().set("homer", new Person("Homer", "Simpson"))) //
typedOperations.opsForValue().set("homer", new Person("Homer", "Simpson")).as(StepVerifier::create) //
.expectNext(true) //
.verifyComplete();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class ListOperationsTests {

@BeforeEach
void before() {
StepVerifier.create(operations.execute(it -> it.serverCommands().flushDb())).expectNext("OK").verifyComplete();

operations.execute(it -> it.serverCommands().flushDb()).as(StepVerifier::create) //
.expectNext("OK") //
.verifyComplete();
}

/**
Expand All @@ -63,7 +66,7 @@ void shouldPollAndPopulateQueue() {
.log("example.springdata.redis", Level.INFO);

log.info("Blocking pop...waiting for message");
StepVerifier.create(blpop) //
blpop.as(StepVerifier::create) //
.then(() -> {

Mono.delay(Duration.ofSeconds(10)).doOnSuccess(it -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class ValueOperationsTests {

@BeforeEach
void before() {
StepVerifier.create(operations.execute(it -> it.serverCommands().flushDb())).expectNext("OK").verifyComplete();

operations.execute(it -> it.serverCommands().flushDb()).as(StepVerifier::create) //
.expectNext("OK") //
.verifyComplete();
}

/**
Expand All @@ -67,14 +70,14 @@ void shouldCacheValue() {

log.info("Initial access (takes a while...)");

StepVerifier.create(cachedMono).expectSubscription() //
cachedMono.as(StepVerifier::create).expectSubscription() //
.expectNoEvent(Duration.ofSeconds(9)) //
.expectNext("Hello, World!") //
.verifyComplete();

log.info("Subsequent access (use cached value)");

var duration = StepVerifier.create(cachedMono) //
var duration = cachedMono.as(StepVerifier::create) //
.expectNext("Hello, World!") //
.verifyComplete();

Expand Down

0 comments on commit e66d317

Please sign in to comment.