T
- The type of data in onNext(Object)
.public final class TestCollectingPublisherSubscriber<T> extends java.lang.Object implements PublisherSource.Subscriber<T>
PublisherSource.Subscriber
that enqueues onNext(Object)
and terminal signals while providing blocking methods
to consume these events. There are two approaches to using this class:
TestCollectingPublisherSubscriber<String> sub = new TestCollectingPublisherSubscriber<>(); // Approach 1 - verify individual items sequentially. String s = sub.takeOnNext(); // verify s sub.awaitOnComplete(); // this will verify that all onNext signals have been consumed // Approach 2 - wait for terminal, verify items in bulk. sub.awaitOnComplete(false); // wait for the terminal signal, ignore if there are unconsumed onNext signals. List<String> onNextSignals = sub.pollAllOnNext(); // verify all onNextSignals occurred in the expected order
Constructor and Description |
---|
TestCollectingPublisherSubscriber() |
Modifier and Type | Method and Description |
---|---|
void |
awaitOnComplete()
Block until a terminal signal is received, throws if
onError(Throwable) and returns normally if
onComplete() . |
void |
awaitOnComplete(boolean verifyOnNextConsumed)
Block until a terminal signal is received, throws if
onError(Throwable) and returns normally if
onComplete() . |
java.lang.Throwable |
awaitOnError()
Block until a terminal signal is received, throws if
onComplete() and returns normally if
onError(Throwable) . |
java.lang.Throwable |
awaitOnError(boolean verifyOnNextConsumed)
Block until a terminal signal is received, throws if
onComplete() and returns normally if
onError(Throwable) . |
PublisherSource.Subscription |
awaitSubscription()
Block until
#onSubscribe(Subscription) . |
void |
onComplete()
Callback to signal completion of the
PublisherSource for this Subscriber . |
void |
onError(java.lang.Throwable t)
Callback to receive an
error for this Subscriber . |
void |
onNext(T t)
Callback to receive a
data element for this Subscriber . |
void |
onSubscribe(PublisherSource.Subscription subscription)
Callback to receive a
PublisherSource.Subscription for this Subscriber . |
java.util.List<T> |
pollAllOnNext()
Consume all currently available
onNext(Object) signals. |
boolean |
pollTerminal(long timeout,
java.util.concurrent.TimeUnit unit)
Block for a terminal event.
|
T |
takeOnNext()
Blocks until the next
onNext(Object) method invocation. |
public void onSubscribe(PublisherSource.Subscription subscription)
PublisherSource.Subscriber
PublisherSource.Subscription
for this Subscriber
.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
onSubscribe
in interface PublisherSource.Subscriber<T>
subscription
- PublisherSource.Subscription
for this Subscriber
.public void onNext(@Nullable T t)
PublisherSource.Subscriber
data
element for this Subscriber
.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
onNext
in interface PublisherSource.Subscriber<T>
t
- A data
element.public void onError(java.lang.Throwable t)
PublisherSource.Subscriber
error
for this Subscriber
.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
onError
in interface PublisherSource.Subscriber<T>
t
- error
for this Subscriber
.public void onComplete()
PublisherSource.Subscriber
PublisherSource
for this Subscriber
.
See Reactive Streams specifications for the rules about how and when this method will be invoked.
onComplete
in interface PublisherSource.Subscriber<T>
public PublisherSource.Subscription awaitSubscription() throws java.lang.InterruptedException
#onSubscribe(Subscription)
.PublisherSource.Subscription
from #onSubscribe(Subscription)
.java.lang.InterruptedException
- if an interrupt occurs while blocking for waiting for
#onSubscribe(Subscription)
.@Nullable public T takeOnNext() throws java.lang.InterruptedException
onNext(Object)
method invocation.onNext(Object)
.java.lang.InterruptedException
- if an interrupt occurs while blocking for the next item.public java.util.List<T> pollAllOnNext()
onNext(Object)
signals.List
containing all currently available onNext(Object)
signals.public java.lang.Throwable awaitOnError() throws java.lang.InterruptedException
onComplete()
and returns normally if
onError(Throwable)
. This method will verify that all onNext(Object)
signals have been
consumed.onError(Throwable)
.java.lang.InterruptedException
- If an interrupt occurs while blocking for the terminal event.public java.lang.Throwable awaitOnError(boolean verifyOnNextConsumed) throws java.lang.InterruptedException
onComplete()
and returns normally if
onError(Throwable)
.verifyOnNextConsumed
- true
to verify that all onNext(Object)
signals have been consumed
and throw if not. false
to ignore if onNext(Object)
signals have been consumed or not.onError(Throwable)
.java.lang.InterruptedException
- If an interrupt occurs while blocking for the terminal event.public void awaitOnComplete() throws java.lang.InterruptedException
onError(Throwable)
and returns normally if
onComplete()
. This method will verify that all onNext(Object)
signals have been consumed.java.lang.InterruptedException
- If an interrupt occurs while blocking for the terminal event.public void awaitOnComplete(boolean verifyOnNextConsumed) throws java.lang.InterruptedException
onError(Throwable)
and returns normally if
onComplete()
.verifyOnNextConsumed
- true
to verify that all onNext(Object)
signals have been consumed
and throw if not. false
to ignore if onNext(Object)
signals have been consumed or not.java.lang.InterruptedException
- If an interrupt occurs while blocking for the terminal event.public boolean pollTerminal(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
timeout
- The duration of time to wait.unit
- The unit of time to apply to the duration.true
if a terminal event has been received before the timeout duration.java.lang.InterruptedException
- If an interrupt occurs while blocking for the terminal event.