public abstract class TestPublisher<T> extends Object implements Publisher<T>, PublisherProbe<T>
Publisher
that you can directly manipulate, triggering
onNext
, onComplete
and
onError
events, for testing purposes.
You can assert the state of the publisher using its assertXXX
methods,
usually inside a StepVerifier
's
then
callback.
The TestPublisher can also be made more lenient towards the RS spec
and allow "spec violations", as enumerated in TestPublisher.Violation
. Use the
createNoncompliant(Violation, Violation...)
factory method to create such
a misbehaving publisher.
TestPublisher are generally hot, directly propagating signals to currently subscribed downstreams and only replaying the first termination signal to subsequent subscribers. TestPublishers are also generally not safe to use from multiple parallel threads.
Modifier and Type | Class and Description |
---|---|
static class |
TestPublisher.Violation
Possible misbehavior for a
TestPublisher . |
PublisherProbe.DefaultPublisherProbe<T>
Constructor and Description |
---|
TestPublisher() |
Modifier and Type | Method and Description |
---|---|
abstract TestPublisher<T> |
assertCancelled()
Asserts that this publisher has had at least one subscriber that has been cancelled.
|
abstract TestPublisher<T> |
assertCancelled(int n)
Asserts that this publisher has had at least n subscribers that have been cancelled.
|
abstract TestPublisher<T> |
assertMinRequested(long n)
Assert that the current minimum request of all this publisher's subscribers
is >=
n . |
abstract TestPublisher<T> |
assertNoRequestOverflow()
Asserts that this publisher has had no subscriber with request overflow.
|
abstract TestPublisher<T> |
assertNoSubscribers()
Asserts that this publisher has no subscribers.
|
abstract TestPublisher<T> |
assertNotCancelled()
Asserts that this publisher has had no cancelled subscribers.
|
abstract TestPublisher<T> |
assertRequestOverflow()
Asserts that this publisher has had subscriber that saw request overflow,
that is received an onNext event despite having a requested amount of 0 at
the time.
|
abstract TestPublisher<T> |
assertSubscribers()
Asserts that this publisher has subscribers.
|
abstract TestPublisher<T> |
assertSubscribers(int n)
Asserts that this publisher has exactly n subscribers.
|
abstract TestPublisher<T> |
complete()
Triggers
completion of this publisher. |
static <T> TestPublisher<T> |
create()
Create a standard hot
TestPublisher . |
static <T> TestPublisher<T> |
createCold()
Create a cold
TestPublisher , which can be subscribed to by multiple
subscribers. |
static <T> TestPublisher<T> |
createNoncompliant(TestPublisher.Violation first,
TestPublisher.Violation... rest)
Create a
noncompliant hot TestPublisher
with a given set of reactive streams spec violations that will be overlooked. |
TestPublisher<T> |
emit(T... values)
Combine emitting items and completing this publisher.
|
abstract TestPublisher<T> |
error(Throwable t)
Triggers an
error signal to the subscribers. |
abstract Flux<T> |
flux()
Convenience method to wrap this
TestPublisher to a Flux . |
abstract Mono<T> |
mono()
Convenience method to wrap this
TestPublisher to a Mono . |
abstract TestPublisher<T> |
next(T value)
Send 1
onNext signal to the subscribers. |
TestPublisher<T> |
next(T first,
T... rest)
Send 1-n
onNext signals to the subscribers. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
assertWasCancelled, assertWasNotCancelled, assertWasNotRequested, assertWasNotSubscribed, assertWasRequested, assertWasSubscribed, empty, of, wasCancelled, wasRequested, wasSubscribed
public static <T> TestPublisher<T> create()
TestPublisher
.T
- the type of the publisherTestPublisher
public static <T> TestPublisher<T> createNoncompliant(TestPublisher.Violation first, TestPublisher.Violation... rest)
noncompliant
hot TestPublisher
with a given set of reactive streams spec violations that will be overlooked.T
- the type of the publisherfirst
- the first allowed TestPublisher.Violation
rest
- additional optional violationsTestPublisher
public static <T> TestPublisher<T> createCold()
TestPublisher
, which can be subscribed to by multiple
subscribers. It caches the next(Object)
events and replays them to
all subscribers upon subscription.
Note that this type of Publisher
isn't
T
- the type of the publisherTestPublisher
public abstract Flux<T> flux()
TestPublisher
to a Flux
.flux
in interface PublisherProbe<T>
Flux
version of the probe.public abstract Mono<T> mono()
TestPublisher
to a Mono
.mono
in interface PublisherProbe<T>
Mono
version of the probe.public abstract TestPublisher<T> assertMinRequested(long n)
n
.n
- the expected minimum requestTestPublisher
for chaining.public abstract TestPublisher<T> assertSubscribers()
TestPublisher
for chaining.public abstract TestPublisher<T> assertSubscribers(int n)
n
- the expected number of subscribersTestPublisher
for chaining.public abstract TestPublisher<T> assertNoSubscribers()
TestPublisher
for chaining.public abstract TestPublisher<T> assertCancelled()
TestPublisher
for chaining.public abstract TestPublisher<T> assertCancelled(int n)
n
- the expected number of subscribers to have been cancelled.TestPublisher
for chaining.public abstract TestPublisher<T> assertNotCancelled()
TestPublisher
for chaining.public abstract TestPublisher<T> assertRequestOverflow()
TestPublisher
for chaining.public abstract TestPublisher<T> assertNoRequestOverflow()
TestPublisher
for chaining.public abstract TestPublisher<T> next(@Nullable T value)
onNext
signal to the subscribers.value
- the item to emit (can be null if the relevant TestPublisher.Violation
is set)TestPublisher
for chaining.public abstract TestPublisher<T> error(Throwable t)
error
signal to the subscribers.t
- the Throwable
to triggerTestPublisher
for chaining.public abstract TestPublisher<T> complete()
completion
of this publisher.TestPublisher
for chaining.@SafeVarargs public final TestPublisher<T> next(@Nullable T first, T... rest)
onNext
signals to the subscribers.first
- the first item to emitrest
- the optional remaining items to emitTestPublisher
for chaining.next
@SafeVarargs public final TestPublisher<T> emit(T... values)
values
- the values to emit to subscribersTestPublisher
for chaining.next
,
complete