Class TestSubscriber<T>

    • Field Detail

      • downstream

        private final org.reactivestreams.Subscriber<? super T> downstream
        The actual subscriber to forward events to.
      • cancelled

        private volatile boolean cancelled
        Makes sure the incoming Subscriptions get cancelled immediately.
      • upstream

        private final java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> upstream
        Holds the current subscription if any.
      • missedRequested

        private final java.util.concurrent.atomic.AtomicLong missedRequested
        Holds the requested amount until a subscription arrives.
    • Constructor Detail

      • TestSubscriber

        public TestSubscriber()
        Constructs a non-forwarding TestSubscriber with an initial request value of Long.MAX_VALUE.
      • TestSubscriber

        public TestSubscriber​(long initialRequest)
        Constructs a non-forwarding TestSubscriber with the specified initial request value.

        The TestSubscriber doesn't validate the initialRequest amount so one can test sources with invalid values as well.

        Parameters:
        initialRequest - the initial request amount
      • TestSubscriber

        public TestSubscriber​(@NonNull
                              @NonNull org.reactivestreams.Subscriber<? super T> downstream)
        Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped Subscriber.
        Parameters:
        downstream - the actual Subscriber to forward events to
      • TestSubscriber

        public TestSubscriber​(@NonNull
                              @NonNull org.reactivestreams.Subscriber<? super T> actual,
                              long initialRequest)
        Constructs a forwarding TestSubscriber with the specified initial request amount and an actual Subscriber to forward events to.

        The TestSubscriber doesn't validate the initialRequest value so one can test sources with invalid values as well.

        Parameters:
        actual - the actual Subscriber to forward events to
        initialRequest - the initial request amount
    • Method Detail

      • create

        @NonNull
        public static <T> @NonNull TestSubscriber<T> create()
        Creates a TestSubscriber with Long.MAX_VALUE initial request amount.
        Type Parameters:
        T - the value type
        Returns:
        the new TestSubscriber instance.
        See Also:
        create(long)
      • create

        @NonNull
        public static <T> @NonNull TestSubscriber<T> create​(long initialRequested)
        Creates a TestSubscriber with the given initial request amount.
        Type Parameters:
        T - the value type
        Parameters:
        initialRequested - the initial requested amount
        Returns:
        the new TestSubscriber instance.
      • create

        public static <T> TestSubscriber<T> create​(@NonNull
                                                   @NonNull org.reactivestreams.Subscriber<? super T> delegate)
        Constructs a forwarding TestSubscriber.
        Type Parameters:
        T - the value type received
        Parameters:
        delegate - the actual Subscriber to forward events to
        Returns:
        the new TestObserver instance
      • onSubscribe

        public void onSubscribe​(@NonNull
                                @NonNull org.reactivestreams.Subscription s)
        Description copied from interface: FlowableSubscriber
        Implementors of this method should make sure everything that needs to be visible in Subscriber.onNext(Object) is established before calling Subscription.request(long). In practice this means no initialization should happen after the request() call and additional behavior is thread safe in respect to onNext.
        Specified by:
        onSubscribe in interface FlowableSubscriber<T>
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<T>
      • onStart

        protected void onStart()
        Called after the onSubscribe is called and handled.
      • onNext

        public void onNext​(@NonNull
                           T t)
        Specified by:
        onNext in interface org.reactivestreams.Subscriber<T>
      • onError

        public void onError​(@NonNull
                            @NonNull java.lang.Throwable t)
        Specified by:
        onError in interface org.reactivestreams.Subscriber<T>
      • onComplete

        public void onComplete()
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<T>
      • request

        public final void request​(long n)
        Specified by:
        request in interface org.reactivestreams.Subscription
      • cancel

        public final void cancel()
        Specified by:
        cancel in interface org.reactivestreams.Subscription
      • isCancelled

        public final boolean isCancelled()
        Returns true if this TestSubscriber has been cancelled.
        Returns:
        true if this TestSubscriber has been cancelled
      • isDisposed

        protected final boolean isDisposed()
        Description copied from class: BaseTestConsumer
        Returns true if this test consumer was cancelled/disposed.
        Specified by:
        isDisposed in class BaseTestConsumer<T,​TestSubscriber<T>>
        Returns:
        true if this test consumer was cancelled/disposed.
      • requestMore

        public final TestSubscriber<T> requestMore​(long n)
        Calls request(long) and returns this.

        History: 2.0.1 - experimental

        Parameters:
        n - the request amount
        Returns:
        this
        Since:
        2.1