-
-
Notifications
You must be signed in to change notification settings - Fork 881
Open
Description
In the solution:
@Test
public void one_to_catch_them_all() {
AtomicInteger hooksTriggeredCounter = new AtomicInteger(0);
Flux<Integer> temperatureFlux = room_temperature_service()
.doFinally(signalType -> hooksTriggeredCounter.incrementAndGet());
StepVerifier.create(temperatureFlux.take(0))
.expectNextCount(0)
.verifyComplete();
StepVerifier.create(temperatureFlux.skip(20))
.expectNextCount(0)
.verifyComplete();
StepVerifier.create(temperatureFlux.skip(20)
.concatWith(Flux.error(new RuntimeException("oops"))))
.expectError()
.verify();
Assertions.assertEquals(hooksTriggeredCounter.get(), 3);
}
Last assert is failing because hooksTriggeredCounter.get() is equal to 2. This is happening because take(0) on first StepVerifier not working.
On Flux.take documentation says:
Take only the first N values from this Flux, if available. If n is zero, the source isn't even subscribed to and the operator completes immediately upon subscription.
As documentations says, on taking 0 the subscriber dosen't trigger.
To solve this we can:
StepVerifier.create(temperatureFlux.take(1))
.expectNextCount(1)
.verifyComplete();
or
Assertions.assertEquals(hooksTriggeredCounter.get(), 2);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels