public interface StepVerifier
StepVerifier provides a declarative way of creating a verifiable script for
an async Publisher sequence, by expressing expectations about the events that
will happen upon subscription. The verification must be triggered after the terminal
expectations (completion, error, cancellation) have been declared, by calling one of
the verify() methods.
StepVerifier around a Publisher using
create(Publisher) or
withVirtualTime(Supplier<Publisher>)
(in which case you should lazily create the publisher inside the provided
lambda).expectNext,
expectNextMatches(Predicate),
assertNext(Consumer),
expectNextCount(long) or
expectNextSequence(Iterable).thenRequest(long) or thenCancel(). expectComplete(),
expectError(),
expectError(Class),
expectErrorMatches(Predicate), or
thenCancel().StepVerifier on its Publisher
using either verify() or verify(Duration). (note some of the terminal
expectations above have a "verify" prefixed alternative that both declare the
expectation and trigger the verification).AssertionError will be thrown indicating the
failures.For example:
StepVerifier.create(Flux.just("foo", "bar"))
.expectNext("foo")
.expectNext("bar")
.expectComplete()
.verify();
| Modifier and Type | Interface and Description |
|---|---|
static interface |
StepVerifier.Assertions
Exposes post-verification state assertions.
|
static interface |
StepVerifier.FirstStep<T>
Define a builder for explicitly expecting an initializing
Subscription as
first signal. |
static interface |
StepVerifier.LastStep
Define a builder for terminal states.
|
static interface |
StepVerifier.Step<T>
Define a builder for expecting main sequence individual signals.
|
| Modifier and Type | Field and Description |
|---|---|
static Duration |
DEFAULT_VERIFY_TIMEOUT
Default verification timeout (see
verify()) is "no timeout". |
| Modifier and Type | Method and Description |
|---|---|
static <T> StepVerifier.FirstStep<T> |
create(Publisher<? extends T> publisher)
Prepare a new
StepVerifier in an uncontrolled environment:
StepVerifier.Step.thenAwait() will block in real time. |
static <T> StepVerifier.FirstStep<T> |
create(Publisher<? extends T> publisher,
long n)
Prepare a new
StepVerifier in an uncontrolled environment:
StepVerifier.Step.thenAwait() will block in real time. |
static <T> StepVerifier.FirstStep<T> |
create(Publisher<? extends T> publisher,
StepVerifierOptions options)
Prepare a new
StepVerifier in an uncontrolled environment:
StepVerifier.Step.thenAwait() will block in real time. |
StepVerifier |
log()
Activate debug logging of a description of the test scenario, as well as
some details about certain verification steps.
|
static void |
resetDefaultTimeout()
Reset the
verify() timeout to the "unlimited" default. |
static void |
setDefaultTimeout(Duration timeout)
Set the
verify() timeout for all StepVerifier created through the
factory methods (create(Publisher), withVirtualTime(Supplier), etc.). |
Duration |
verify()
Verify the signals received by this subscriber.
|
Duration |
verify(Duration duration)
Verify the signals received by this subscriber.
|
StepVerifier.Assertions |
verifyThenAssertThat()
Verifies the signals received by this subscriber, then exposes
various assertion methods on the final state. |
static <T> StepVerifier.FirstStep<T> |
withVirtualTime(Supplier<? extends Publisher<? extends T>> scenarioSupplier)
Prepare a new
StepVerifier in a controlled environment using
VirtualTimeScheduler to manipulate a virtual clock via
StepVerifier.Step.thenAwait(). |
static <T> StepVerifier.FirstStep<T> |
withVirtualTime(Supplier<? extends Publisher<? extends T>> scenarioSupplier,
long n)
Prepare a new
StepVerifier in a controlled environment using
VirtualTimeScheduler to manipulate a virtual clock via
StepVerifier.Step.thenAwait(). |
static <T> StepVerifier.FirstStep<T> |
withVirtualTime(Supplier<? extends Publisher<? extends T>> scenarioSupplier,
StepVerifierOptions options)
Prepare a new
StepVerifier in a controlled environment using
a user-provided VirtualTimeScheduler to manipulate a virtual clock via
StepVerifier.Step.thenAwait(). |
static <T> StepVerifier.FirstStep<T> |
withVirtualTime(Supplier<? extends Publisher<? extends T>> scenarioSupplier,
Supplier<? extends VirtualTimeScheduler> vtsLookup,
long n)
Prepare a new
StepVerifier in a controlled environment using
a user-provided VirtualTimeScheduler to manipulate a virtual clock via
StepVerifier.Step.thenAwait(). |
static final Duration DEFAULT_VERIFY_TIMEOUT
verify()) is "no timeout".setDefaultTimeout(Duration),
resetDefaultTimeout()static void setDefaultTimeout(@Nullable Duration timeout)
verify() timeout for all StepVerifier created through the
factory methods (create(Publisher), withVirtualTime(Supplier), etc.).
This affects ALL such verifiers created after this call, until a call to either
this method or resetDefaultTimeout().
timeout - the timeout to use for verify() calls on all StepVerifier
created through the factory methods after this call. null is interpreted
as a call to resetDefaultTimeout().static void resetDefaultTimeout()
verify() timeout to the "unlimited" default.
This affects ALL such verifiers created after this call, until a call to
setDefaultTimeout(Duration).
static <T> StepVerifier.FirstStep<T> create(Publisher<? extends T> publisher)
StepVerifier in an uncontrolled environment:
StepVerifier.Step.thenAwait() will block in real time.
Each verify() will fully (re)play the scenario.publisher - the publisher to subscribe to and verifystatic <T> StepVerifier.FirstStep<T> create(Publisher<? extends T> publisher, long n)
StepVerifier in an uncontrolled environment:
StepVerifier.Step.thenAwait() will block in real time.
Each verify() will fully (re)play the scenario.
The verification will request a specified amount of values.publisher - the publisher to subscribe to and verifyn - the amount of items to requeststatic <T> StepVerifier.FirstStep<T> create(Publisher<? extends T> publisher, StepVerifierOptions options)
StepVerifier in an uncontrolled environment:
StepVerifier.Step.thenAwait() will block in real time.
Each verify() will fully (re)play the scenario.
The verification will request a specified amount of values according to
the options passed.publisher - the publisher to subscribe tooptions - the options for the verificationstatic <T> StepVerifier.FirstStep<T> withVirtualTime(Supplier<? extends Publisher<? extends T>> scenarioSupplier)
StepVerifier in a controlled environment using
VirtualTimeScheduler to manipulate a virtual clock via
StepVerifier.Step.thenAwait(). The scheduler is injected into all Schedulers factories,
which means that any operator created within the lambda without a specific scheduler
will use virtual time.
Each verify() will fully (re)play the scenario.
The verification will request an unbounded amount of values.T - the type of the subscriberscenarioSupplier - a mandatory supplier of the Publisher to subscribe
to and verify. In order for operators to use virtual time, they must be invoked
from within the lambda.static <T> StepVerifier.FirstStep<T> withVirtualTime(Supplier<? extends Publisher<? extends T>> scenarioSupplier, long n)
StepVerifier in a controlled environment using
VirtualTimeScheduler to manipulate a virtual clock via
StepVerifier.Step.thenAwait(). The scheduler is injected into all Schedulers factories,
which means that any operator created within the lambda without a specific scheduler
will use virtual time.
Each verify() will fully (re)play the scenario.
The verification will request a specified amount of values.T - the type of the subscriberscenarioSupplier - a mandatory supplier of the Publisher to subscribe
to and verify. In order for operators to use virtual time, they must be invoked
from within the lambda.n - the amount of items to request (must be >= 0)static <T> StepVerifier.FirstStep<T> withVirtualTime(Supplier<? extends Publisher<? extends T>> scenarioSupplier, Supplier<? extends VirtualTimeScheduler> vtsLookup, long n)
StepVerifier in a controlled environment using
a user-provided VirtualTimeScheduler to manipulate a virtual clock via
StepVerifier.Step.thenAwait(). The scheduler is injected into all Schedulers factories,
which means that any operator created within the lambda without a specific scheduler
will use virtual time.
Each verify() will fully (re)play the scenario.
The verification will request a specified amount of values.T - the type of the subscriberscenarioSupplier - a mandatory supplier of the Publisher to subscribe
to and verify. In order for operators to use virtual time, they must be invoked
from within the lambda.vtsLookup - the supplier of the VirtualTimeScheduler to inject and
manipulate during verification.n - the amount of items to request (must be >= 0)static <T> StepVerifier.FirstStep<T> withVirtualTime(Supplier<? extends Publisher<? extends T>> scenarioSupplier, StepVerifierOptions options)
StepVerifier in a controlled environment using
a user-provided VirtualTimeScheduler to manipulate a virtual clock via
StepVerifier.Step.thenAwait(). The scheduler is injected into all Schedulers factories,
which means that any operator created within the lambda without a specific scheduler
will use virtual time.
Each verify() will fully (re)play the scenario.
The verification will request a specified amount of values according to
the provided options.T - the type of the subscriberscenarioSupplier - a mandatory supplier of the Publisher to subscribe
to and verify. In order for operators to use virtual time, they must be invoked
from within the lambda.options - the verification options, including the supplier of the
VirtualTimeScheduler to inject and manipulate during verification.StepVerifier log()
verify() callDuration verify() throws AssertionError
StepVerifier via setDefaultTimeout(Duration),
this method will block until the stream has been terminated
(either through Subscriber.onComplete(), Subscriber.onError(Throwable) or
Subscription.cancel()). Depending on the declared expectations and actions,
notably in case of undersized manual requests, such a verification could also block
indefinitely.Duration the verification took.AssertionError - in case of expectation failuresverify(Duration),
setDefaultTimeout(Duration)Duration verify(Duration duration) throws AssertionError
Subscriber.onComplete(),
Subscriber.onError(Throwable) or Subscription.cancel()). Use
Duration.ZERO for an unlimited wait for termination.duration - the maximum duration to wait for the sequence to terminate, or
Duration.ZERO for unlimited wait.Duration the verification took.AssertionError - in case of expectation failures, or when the verification
times outStepVerifier.Assertions verifyThenAssertThat()
Verifies the signals received by this subscriber, then exposes
various assertion methods on the final state.
Note that like verify(), this method will block until
the stream has been terminated (either through Subscriber.onComplete(),
Subscriber.onError(Throwable) or Subscription.cancel()).
Depending on the declared expectations and actions, notably in case of undersized
manual requests, such a verification could also block indefinitely. Use
setDefaultTimeout(Duration) to globally add a timeout on verify()-derived
methods.
Duration the verification took.AssertionError - in case of expectation failures