Class UniAssertSubscriber<T>

    • Constructor Detail

      • UniAssertSubscriber

        public UniAssertSubscriber​(Context context,
                                   boolean cancelled)
        Create a new UniAssertSubscriber.
        Parameters:
        context - the subscription context, cannot be null
        cancelled - true when the subscription shall be cancelled upfront, false otherwise
      • UniAssertSubscriber

        public UniAssertSubscriber​(boolean cancelled)
        Create a new UniAssertSubscriber with an upfront cancellation configuration and an empty Context.
      • UniAssertSubscriber

        public UniAssertSubscriber()
        Create a new UniAssertSubscriber with no upfront cancellation and an empty Context.
    • Method Detail

      • create

        public static <T> UniAssertSubscriber<T> create​(Context context)
        Create a new UniAssertSubscriber with no upfront cancellation and a Context.
        Type Parameters:
        T - the type of the item
        Parameters:
        context - the context, cannot be null
        Returns:
        a new subscriber
      • context

        public Context context()
        Description copied from interface: ContextSupport
        Provide a context.

        Since calls to this method shall only be triggered when a Mutiny pipeline uses a withContext operator, 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 withContext operator.

        Specified by:
        context in interface ContextSupport
        Returns:
        the context, must not be null.
      • onItem

        public void onItem​(T item)
        Description copied from interface: UniSubscriber
        Event handler called once the item has been computed by the subscribed Uni. IMPORTANT: this method will be only called once per subscription. If UniSubscriber.onFailure(Throwable) is called, this method won't be called.
        Specified by:
        onItem in interface UniSubscriber<T>
        Parameters:
        item - the item, may be null.
      • onFailure

        public void onFailure​(java.lang.Throwable failure)
        Description copied from interface: UniSubscriber
        Called if the computation of the item by the subscriber Uni failed. IMPORTANT: this method will be only called once per subscription. If UniSubscriber.onItem(Object) is called, this method won't be called.
        Specified by:
        onFailure in interface UniSubscriber<T>
        Parameters:
        failure - the failure, cannot be null.
      • awaitItem

        public UniAssertSubscriber<T> awaitItem​(java.time.Duration duration)
        Awaits for a item event at most duration.

        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 be null
        Returns:
        this UniAssertSubscriber
      • awaitFailure

        public UniAssertSubscriber<T> awaitFailure​(java.util.function.Consumer<java.lang.Throwable> assertion)
        Awaits for a failure event and validate it. It waits at most AssertSubscriber.DEFAULT_TIMEOUT.

        If the timeout expired, or if an item event is received instead of the expected failure, the check fails. The received failure is validated using the assertion consumer. The code of the consumer is expected to throw an AssertionError to 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 be null
        Returns:
        this UniAssertSubscriber
      • awaitFailure

        public UniAssertSubscriber<T> awaitFailure​(java.time.Duration duration)
        Awaits for a failure event. It waits at most duration.

        If the timeout expired, or if an item event is received instead of the expected failure, the check fails.

        Parameters:
        duration - the max duration to wait, must not be null
        Returns:
        this UniAssertSubscriber
      • awaitFailure

        public UniAssertSubscriber<T> awaitFailure​(java.util.function.Consumer<java.lang.Throwable> assertion,
                                                   java.time.Duration duration)
        Awaits for a failure event and validate it. It waits at most duration.

        If the timeout expired, or if an item event is received instead of the expected failure, the check fails. The received failure is validated using the assertion consumer. The code of the consumer is expected to throw an AssertionError to 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 be null
        duration - the max duration to wait, must not be null
        Returns:
        this UniAssertSubscriber
      • awaitSubscription

        public UniAssertSubscriber<T> awaitSubscription​(java.time.Duration duration)
        Awaits for a subscription event (the subscriber receives a UniSubscription from the upstream. It waits at most duration.

        If the timeout expired, the check fails.

        Parameters:
        duration - the UniAssertSubscriber, must not be null
        Returns:
        this AssertSubscriber
      • getItem

        public T getItem()
        Get the Uni item, if any.
        Returns:
        the item or null
      • getFailure

        public java.lang.Throwable getFailure()
        Get the Uni failure, if any.
        Returns:
        the failure or null
      • assertFailedWith

        public UniAssertSubscriber<T> assertFailedWith​(java.lang.Class<? extends java.lang.Throwable> expectedTypeOfFailure,
                                                       java.lang.String expectedMessage)
        Assert that the Uni has failed.
        Parameters:
        expectedTypeOfFailure - the expected failure type
        expectedMessage - a message that is expected to be contained in the failure message
        Returns:
        this UniAssertSubscriber
      • assertFailedWith

        public UniAssertSubscriber<T> assertFailedWith​(java.lang.Class<? extends java.lang.Throwable> expectedTypeOfFailure)
        Assert that the Uni has failed.
        Parameters:
        expectedTypeOfFailure - the expected failure type
        Returns:
        this UniAssertSubscriber
      • getOnItemThreadName

        public java.lang.String getOnItemThreadName()
        Get the name of the thread that called onItem(Object), if any.
        Returns:
        the thread name
      • getOnFailureThreadName

        public java.lang.String getOnFailureThreadName()
        Get the name of the thread that called onFailure(Throwable), if any.
        Returns:
        the thread name
      • getOnSubscribeThreadName

        public java.lang.String getOnSubscribeThreadName()
        Get the name of the thread that called onSubscribe(UniSubscription), if any.
        Returns:
        the thread name
      • cancel

        public void cancel()
        Cancel the subscription.
      • getSignals

        public java.util.List<UniSignal> getSignals()
        Get the UniSignal audit trail for this subscriber.
        Returns:
        the signals in receive order
      • assertSignalsReceivedInOrder

        public UniAssertSubscriber<T> assertSignalsReceivedInOrder()
        Assert that signals have been received in correct order.

        An example of an legal sequence would be receiving onSubscribe -> onItem. An example of an illegal sequence would be receiving onItem -> onSubscribe.

        Returns:
        this UniAssertSubscriber