Package reactor.test.subscriber
Class TestSubscriberBuilder
java.lang.Object
reactor.test.subscriber.TestSubscriberBuilder
A configuration builder used to create a fine-tuned
TestSubscriber, also
allowing for a Fuseable.ConditionalSubscriber variant.
Notably, it allows the created instance to enforce fusion compatibility
(by assuming a Fuseable source publisher and expecting a
Fuseable.QueueSubscription).
See TestSubscriber.builder() to obtain a new builder.
Note that all methods mutate the builder configuration, so reuse is discouraged.
- Author:
- Simon Baslé
-
Method Summary
Modifier and TypeMethodDescription<T> TestSubscriber<T>build()Create aTestSubscriberaccording to this builder.<T> ConditionalTestSubscriber<T>buildConditional(Predicate<? super T> tryOnNext) Create aFuseable.ConditionalSubscribervariant ofTestSubscriberaccording to this builder.contextPut(Object key, Object value) Enrich theContextwith a single entry.contextPutAll(ContextView toAdd) Enrich theContextby putting all entries of the givenContextViewin it.initialRequest(long initialRequest) Set the request to be made upon receiving theSubscriptioninSubscriber.onSubscribe(Subscription).Set the request to be made upon receiving theSubscriptioninSubscriber.onSubscribe(Subscription)to be an unbounded request, ie.requireFusion(int exactMode) Expect fusion to be possible with theTestSubscriber, withFuseable.NONE) being a special case.requireFusion(int requestedMode, int negotiatedMode) Expect fusion to be possible with theTestSubscriber, with both parameters set toFuseable.NONEbeing a special case.
-
Method Details
-
contextPut
Enrich theContextwith a single entry.- Parameters:
key- the key to put/set in theContextof the futureTestSubscribervalue- the value to associate with the key- Returns:
- this builder, mutated to have the key/value pair added to the
Context
-
contextPutAll
Enrich theContextby putting all entries of the givenContextViewin it.- Parameters:
toAdd- theContextViewto add to theContextof the futureTestSubscriber- Returns:
- this builder, mutated to have all
ContextView's key/value pairs added to theContext
-
initialRequest
Set the request to be made upon receiving theSubscriptioninSubscriber.onSubscribe(Subscription). Default isLong.MAX_VALUE.- Parameters:
initialRequest- the request to be made at subscription- Returns:
- this builder, mutated to reflect the new request to be made at subscription
-
initialRequestUnbounded
Set the request to be made upon receiving theSubscriptioninSubscriber.onSubscribe(Subscription)to be an unbounded request, ie.Long.MAX_VALUE.- Returns:
- this builder, mutated to reflect an unbounded request is to be made at subscription
-
requireFusion
Expect fusion to be possible with theTestSubscriber, withFuseable.NONE) being a special case. Fusion will be negotiated at subscription, enforcing the need for aFuseable.QueueSubscriptionto be passed. Furthermore, the fusion mode returned from the negotiation with theFuseable.QueueSubscriptionis expected to be the same as the provided mode.Use
requireFusion(Fuseable.NONE)to remove any previously fusion requirement, as well as removing type enforcement on the subscription (a vanillaSubscriptionbecomes acceptable). UserequireNotFuseable()to strictly enforce that theSubscriptionMUST NOT be aFuseable.QueueSubscription.- Parameters:
exactMode- the requested fusion mode, expected in return from the negotiation with theFuseable.QueueSubscription- Returns:
- this builder, mutated to require fusion with the given mode
-
requireFusion
Expect fusion to be possible with theTestSubscriber, with both parameters set toFuseable.NONEbeing a special case. Fusion will be negotiated at subscription, enforcing the need for aFuseable.QueueSubscriptionto be passed. Furthermore, thenegotiatedModeis expected to be negotiated by the subscription in response to requestingrequestedMode.Use
requireFusion(Fuseable.NONE, Fuseable.NONE)to remove any previously fusion requirement, as well as removing type enforcement on the subscription (a vanillaSubscriptionbecomes acceptable). UserequireNotFuseable()to strictly enforce that theSubscriptionMUST NOT be aFuseable.QueueSubscription.- Parameters:
requestedMode- the fusion mode requested to theFuseable.QueueSubscriptionnegotiatedMode- the fusion mode expected from the negotiation with theFuseable.QueueSubscription- Returns:
- this builder, mutated to require fusion with the given negotiated mode (in response to the given requested mode)
-
requireNotFuseable
Enforce that theSubscriptionpassed to theTestSubscriberisn't aFuseable.QueueSubscription. This is stricter thanrequireFusion(Fuseable.NONE, Fuseable.NONE), which merely disables fusion but still accepts the incoming subscription to be a QueueSubscription.- Returns:
- this builder, mutated to reject all
Fuseable.QueueSubscription
-
buildConditional
Create aFuseable.ConditionalSubscribervariant ofTestSubscriberaccording to this builder. The providedPredicatewill be used as the implementation ofFuseable.ConditionalSubscriber.tryOnNext(Object).- Type Parameters:
T- the type of elements received by theTestSubscriber, defined by the predicate- Parameters:
tryOnNext- thePredicateto use as thetryOnNextimplementation- Returns:
- a
ConditionalTestSubscriber
-
build
Create aTestSubscriberaccording to this builder.- Type Parameters:
T- the type of elements to be received by the subscriber- Returns:
- a new plain
TestSubscriber
-