- Type Parameters:
T- the type of the items
- All Implemented Interfaces:
ContextSupport,MultiSubscriber<T>,Flow.Subscriber<T>
Multi Flow.Subscriber for testing purposes that comes with useful assertion helpers.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newAssertSubscriberwith 0 requested items and no upfront cancellation.AssertSubscriber(long requested) Creates a newAssertSubscriberwith no upfront cancellation.AssertSubscriber(long requested, boolean cancelled) Creates a newAssertSubscriber.AssertSubscriber(Context context, long requested, boolean cancelled) Creates a newAssertSubscriber. -
Method Summary
Modifier and TypeMethodDescriptionAssert that the multi has completed.assertFailedWith(Class<? extends Throwable> expectedTypeOfFailure) Assert that the multi has failed.assertFailedWith(Class<? extends Throwable> expectedTypeOfFailure, String expectedFailureMessage) Assert that the multi has failed.Assert that no item has been received yet.final AssertSubscriber<T> assertItems(T... expected) Assert that a sequence of items has been received (in whole and in exact order).assertLastItem(T expected) Asserts that the last received item is equal toexpected.Assert that the multi has not been subscribed.Assert that the multi has not been terminated, i.e. did not received a failure or a completion event.Assert that the multi has been subscribed.Assert that the multi has been terminated, i.e. received a failure or a completion event.Awaits for a completion event.awaitCompletion(Duration duration) Awaits for a completion event at mostduration.Awaits for a failure event.awaitFailure(Duration duration) Awaits for a failure event.awaitFailure(Consumer<Throwable> assertion) Awaits for a failure event and validate it.awaitFailure(Consumer<Throwable> assertion, Duration duration) Awaits for a failure event and validate it.awaitItems(int number) Awaits for the subscriber to receivenumberitems in total (including the ones received after calling this method).awaitItems(int number, Duration duration) Awaits for the subscriber to receivenumberitems in total (including the ones received after calling this method).Awaits for the next item.awaitNextItem(Duration duration) Awaits for the next item.awaitNextItems(int number) Awaits for the nextnumberitems.awaitNextItems(int number, int request) Awaits for the nextnumberitems.awaitNextItems(int number, int request, Duration duration) Awaits for the nextnumberitems.awaitNextItems(int number, Duration duration) Awaits for the nextnumberitems.Awaits for a subscription event (the subscriber receives aFlow.Subscriptionfrom the upstream.awaitSubscription(Duration duration) Awaits for a subscription event (the subscriber receives aFlow.Subscriptionfrom the upstream.cancel()Cancel the subscription.context()Provide a context.static <T> AssertSubscriber<T> create()Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation.static <T> AssertSubscriber<T> create(long requested) Creates a newAssertSubscriberwith no upfront cancellation.static <T> AssertSubscriber<T> Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation.static <T> AssertSubscriber<T> Creates a newAssertSubscriberwith no upfront cancellation.The reported failure, if any.getItems()The list of items that have been received.booleanCheck whether the multi has completed.booleanCheck whether the subscription has been cancelled or not.voidMethod called when the upstream emits acompletionterminal event.voidMethod called when the upstream emits afailureterminal event.voidMethod called when the upstream emits anitemevent, in response to to requests toFlow.Subscription.request(long).voidrequest(long req) Request items.Run an action.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.smallrye.mutiny.subscription.MultiSubscriber
onComplete, onError, onNext
-
Field Details
-
DEFAULT_TIMEOUT
The default timeout used byawaitmethod.This static field is mutable, the authors assume that you know what you are doing if you ever feel like changing its value.
-
DEFAULT_MUTINY_AWAIT_TIMEOUT
Name of the environment variable for setting the default await methods timeout (in seconds).- See Also:
-
-
Constructor Details
-
AssertSubscriber
Creates a newAssertSubscriber.- Parameters:
context- the contextrequested- the number of initially requested itemscancelled-trueif the subscription is immediately cancelled,falseotherwise
-
AssertSubscriber
public AssertSubscriber(long requested, boolean cancelled) Creates a newAssertSubscriber.- Parameters:
requested- the number of initially requested itemscancelled-trueif the subscription is immediately cancelled,falseotherwise
-
AssertSubscriber
public AssertSubscriber()Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation. -
AssertSubscriber
public AssertSubscriber(long requested) Creates a newAssertSubscriberwith no upfront cancellation.- Parameters:
requested- the number of initially requested items
-
-
Method Details
-
create
Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation.- Type Parameters:
T- the items type- Returns:
- a new subscriber
-
create
Creates a newAssertSubscriberwith no upfront cancellation.- Type Parameters:
T- the items type- Parameters:
requested- the number of initially requested items- Returns:
- a new subscriber
-
create
Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation.- Type Parameters:
T- the items type- Parameters:
context- the context- Returns:
- a new subscriber
-
create
Creates a newAssertSubscriberwith no upfront cancellation.- Type Parameters:
T- the items type- Parameters:
context- the contextrequested- the number of initially requested items- Returns:
- a new subscriber
-
context
Description copied from interface:ContextSupportProvide a context.Since calls to this method shall only be triggered when a Mutiny pipeline uses a
withContextoperator, there is no need in general for caching the context value in a field of the implementing class. Exceptions include operators that have cross-subscriber semantics such as memoizers or broadcasters.This method is expected to be called once per
withContextoperator.- Specified by:
contextin interfaceContextSupport- Returns:
- the context, must not be
null.
-
assertCompleted
Assert that the multi has completed.- Returns:
- this
AssertSubscriber
-
assertFailedWith
public AssertSubscriber<T> assertFailedWith(Class<? extends Throwable> expectedTypeOfFailure, String expectedFailureMessage) Assert that the multi has failed.- Parameters:
expectedTypeOfFailure- the expected failure typeexpectedFailureMessage- a message to be contained in the failure message, ornullwhen any message is fine- Returns:
- this
AssertSubscriber
-
assertFailedWith
Assert that the multi has failed.- Parameters:
expectedTypeOfFailure- the expected failure type- Returns:
- this
AssertSubscriber
-
assertHasNotReceivedAnyItem
Assert that no item has been received yet.- Returns:
- this
AssertSubscriber
-
assertSubscribed
Assert that the multi has been subscribed.- Returns:
- this
AssertSubscriber
-
assertNotSubscribed
Assert that the multi has not been subscribed.- Returns:
- this
AssertSubscriber
-
assertTerminated
Assert that the multi has been terminated, i.e. received a failure or a completion event.- Returns:
- this
AssertSubscriber
-
assertNotTerminated
Assert that the multi has not been terminated, i.e. did not received a failure or a completion event.- Returns:
- this
AssertSubscriber
-
assertItems
Assert that a sequence of items has been received (in whole and in exact order).- Parameters:
expected- a sequence of items- Returns:
- this
AssertSubscriber
-
getLastItem
- Returns:
- get the last received item, potentially
nullif no items have been received.
-
assertLastItem
Asserts that the last received item is equal toexpected. The assertion fails if no items have been received.- Parameters:
expected- the expected item, must not benull- Returns:
- this
AssertSubscriber
-
awaitNextItem
Awaits for the next item. If no item have been received before the default timeout, anAssertionErroris thrown.Note that it requests one item from the upstream.
- Returns:
- this
AssertSubscriber - See Also:
-
awaitNextItem
Awaits for the next item. If no item have been received before the given timeout, anAssertionErroris thrown.Note that it requests one item from the upstream.
- Parameters:
duration- the timeout, must not benull- Returns:
- this
AssertSubscriber - See Also:
-
awaitNextItems
Awaits for the nextnumberitems. If not enough items have been received before the default timeout, anAssertionErroris thrown.This method requests
numberitems the upstream.- Parameters:
number- the number of items to expect, must be neither 0 nor negative.- Returns:
- this
AssertSubscriber - See Also:
-
awaitNextItems
Awaits for the nextnumberitems. If not enough items have been received before the default timeout, anAssertionErroris thrown.- Parameters:
number- the number of items to expect, must neither be 0 nor negative.request- if not 0, the number of items to request upstream.- Returns:
- this
AssertSubscriber
-
awaitNextItems
Awaits for the nextnumberitems. If not enough items have been received before the given timeout, anAssertionErroris thrown.This method requests
numberitems upstream.- Parameters:
number- the number of items to expect, must be neither 0 nor negative.duration- the timeout, must not benull- Returns:
- this
AssertSubscriber
-
awaitNextItems
Awaits for the nextnumberitems. If not enough items have been received before the given timeout, anAssertionErroris thrown.- Parameters:
number- the number of items to expect, must be neither 0 nor negative.request- if not 0, the number of items to request upstream.duration- the timeout, must not benull- Returns:
- this
AssertSubscriber
-
awaitItems
Awaits for the subscriber to receivenumberitems in total (including the ones received after calling this method). If not enough items have been received before the default timeout, anAssertionErroris thrown.Unlike
awaitNextItems(int, int), this method does not request items from the upstream.- Parameters:
number- the number of items to expect, must be neither 0 nor negative.- Returns:
- this
AssertSubscriber
-
awaitItems
Awaits for the subscriber to receivenumberitems in total (including the ones received after calling this method). If not enough items have been received before the given timeout, anAssertionErroris thrown.Unlike
awaitNextItems(int, int), this method does not requests items from the upstream.- Parameters:
number- the number of items to expect, must be neither 0 nor negative.duration- the timeout, must not benull- Returns:
- this
AssertSubscriber
-
awaitCompletion
Awaits for a completion event. It waits at mostDEFAULT_TIMEOUT.If the timeout expired, or if a failure event is received instead of the expected completion, the check fails.
- Returns:
- this
AssertSubscriber
-
awaitCompletion
Awaits for a completion event at mostduration.If the timeout expired, or if a failure event is received instead of the expected completion, the check fails.
- Parameters:
duration- the duration, must not benull- Returns:
- this
AssertSubscriber
-
awaitFailure
Awaits for a failure event. It waits at mostDEFAULT_TIMEOUT.If the timeout expired, or if a completion event is received instead of the expected failure, the check fails.
- Returns:
- this
AssertSubscriber
-
awaitFailure
Awaits for a failure event and validate it. It waits at mostDEFAULT_TIMEOUT.If the timeout expired, or if a completion event is received instead of the expected failure, the check fails. The received failure is validated using the
assertionconsumer. The code of the consumer is expected to throw anAssertionErrorto indicate that the failure didn't pass the validation. The consumer is not called if no failures are received.- Parameters:
assertion- a check validating the received failure (if any). Must not benull- Returns:
- this
AssertSubscriber
-
awaitFailure
Awaits for a failure event. It waits at mostduration.If the timeout expired, or if a completion event is received instead of the expected failure, the check fails.
- Parameters:
duration- the max duration to wait, must not benull- Returns:
- this
AssertSubscriber
-
awaitFailure
Awaits for a failure event and validate it. It waits at mostduration.If the timeout expired, or if a completion event is received instead of the expected failure, the check fails. The received failure is validated using the
assertionconsumer. The code of the consumer is expected to throw anAssertionErrorto indicate that the failure didn't pass the validation. The consumer is not called if no failures are received.- Parameters:
assertion- a check validating the received failure (if any). Must not benullduration- the max duration to wait, must not benull- Returns:
- this
AssertSubscriber
-
awaitSubscription
Awaits for a subscription event (the subscriber receives aFlow.Subscriptionfrom the upstream. It waits at mostDEFAULT_TIMEOUT.If the timeout expired, the check fails.
- Returns:
- this
AssertSubscriber
-
awaitSubscription
Awaits for a subscription event (the subscriber receives aFlow.Subscriptionfrom the upstream. It waits at mostduration.If the timeout expired, the check fails.
- Parameters:
duration- the duration, must not benull- Returns:
- this
AssertSubscriber
-
cancel
Cancel the subscription.- Returns:
- this
AssertSubscriber
-
request
Request items.- Parameters:
req- the number of items to request.- Returns:
- this
AssertSubscriber
-
onSubscribe
- Specified by:
onSubscribein interfaceFlow.Subscriber<T>
-
onItem
Description copied from interface:MultiSubscriberMethod called when the upstream emits anitemevent, in response to to requests toFlow.Subscription.request(long).- Specified by:
onItemin interfaceMultiSubscriber<T>- Parameters:
t- the item, must not benull.
-
onFailure
Description copied from interface:MultiSubscriberMethod called when the upstream emits afailureterminal event.No further events will be sent even if
Flow.Subscription.request(long)is invoked again.- Specified by:
onFailurein interfaceMultiSubscriber<T>- Parameters:
t- the failure, must not benull.
-
onCompletion
public void onCompletion()Description copied from interface:MultiSubscriberMethod called when the upstream emits acompletionterminal event.No further events will be sent even if
Flow.Subscription.request(long)is invoked again.- Specified by:
onCompletionin interfaceMultiSubscriber<T>
-
getItems
The list of items that have been received.- Returns:
- the list
-
getFailure
The reported failure, if any.- Returns:
- the failure or
null
-
run
Run an action.- Parameters:
action- the action- Returns:
- this
AssertSubscriber
-
isCancelled
public boolean isCancelled()Check whether the subscription has been cancelled or not.- Returns:
- a boolean
-
hasCompleted
public boolean hasCompleted()Check whether the multi has completed.- Returns:
- a boolean
-