Class BlockingTestUtils


  • public final class BlockingTestUtils
    extends java.lang.Object
    Utilities to await results of an asynchronous computation either by blocking the calling thread.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void await​(Completable source, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
      Awaits termination of the passed Completable by blocking the calling thread.
      static <T> java.util.List<T> await​(Publisher<T> source, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
      Awaits termination of the passed Publisher by blocking the calling thread.
      static <T> T await​(Single<T> source, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
      Awaits termination of the passed Single by blocking the calling thread.
      static void awaitIndefinitely​(Completable source)
      Awaits termination of the passed Completable by blocking the calling thread.
      static <T> java.util.List<T> awaitIndefinitely​(Publisher<T> source)
      Awaits termination of the passed Publisher by blocking the calling thread.
      static <T> T awaitIndefinitely​(Single<T> source)
      Awaits termination of the passed Single by blocking the calling thread.
      static <T> java.util.List<T> awaitIndefinitelyNonNull​(Publisher<T> source)
      Awaits termination of the passed Publisher by blocking the calling thread.
      static <T> T awaitIndefinitelyNonNull​(Single<T> source)
      Awaits termination of the passed Single by blocking the calling thread.
      static void awaitIndefinitelyUnchecked​(Completable source)
      Awaits termination of the passed Completable by blocking the calling thread.
      static <T> java.util.List<T> awaitNonNull​(Publisher<T> source, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
      Awaits termination of the passed Publisher by blocking the calling thread.
      static <T> T awaitNonNull​(Single<T> source, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
      Awaits termination of the passed Single by blocking the calling thread.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • awaitIndefinitely

        @Nullable
        public static <T> java.util.List<T> awaitIndefinitely​(Publisher<T> source)
                                                       throws java.util.concurrent.ExecutionException,
                                                              java.lang.InterruptedException
        Awaits termination of the passed Publisher by blocking the calling thread.
        Type Parameters:
        T - Type of items produced by the Publisher.
        Parameters:
        source - to await for.
        Returns:
        List of all elements emitted by the Publisher, iff it terminated successfully.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
      • awaitIndefinitelyNonNull

        public static <T> java.util.List<T> awaitIndefinitelyNonNull​(Publisher<T> source)
                                                              throws java.util.concurrent.ExecutionException,
                                                                     java.lang.InterruptedException
        Awaits termination of the passed Publisher by blocking the calling thread.
        Type Parameters:
        T - Type of items produced by the Publisher.
        Parameters:
        source - to await for.
        Returns:
        List of all elements emitted by the Publisher, iff it terminated successfully.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure, or if the result of awaitIndefinitely(Publisher) is null.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
        See Also:
        awaitIndefinitely(Publisher)
      • await

        @Nullable
        public static <T> java.util.List<T> await​(Publisher<T> source,
                                                  long timeout,
                                                  java.util.concurrent.TimeUnit timeoutUnit)
                                           throws java.util.concurrent.ExecutionException,
                                                  java.lang.InterruptedException,
                                                  java.util.concurrent.TimeoutException
        Awaits termination of the passed Publisher by blocking the calling thread.
        Type Parameters:
        T - Type of items produced by the Publisher.
        Parameters:
        source - to await for.
        timeout - maximum time to wait for termination.
        timeoutUnit - TimeUnit for timeout.
        Returns:
        List of all elements emitted by the Publisher, iff it terminated successfully.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
        java.util.concurrent.TimeoutException - If the Publisher isn't terminated after waiting for the passed timeout duration.
      • awaitNonNull

        public static <T> java.util.List<T> awaitNonNull​(Publisher<T> source,
                                                         long timeout,
                                                         java.util.concurrent.TimeUnit timeoutUnit)
                                                  throws java.util.concurrent.ExecutionException,
                                                         java.lang.InterruptedException,
                                                         java.util.concurrent.TimeoutException
        Awaits termination of the passed Publisher by blocking the calling thread.
        Type Parameters:
        T - Type of items produced by the Publisher.
        Parameters:
        source - to await for.
        timeout - maximum time to wait for termination.
        timeoutUnit - TimeUnit for timeout.
        Returns:
        List of all elements emitted by the Publisher, iff it terminated successfully.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure, or if the result of await(Publisher, long, TimeUnit) is null.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
        java.util.concurrent.TimeoutException - If the Publisher isn't terminated after waiting for the passed timeout duration.
        See Also:
        await(Publisher, long, TimeUnit)
      • awaitIndefinitely

        @Nullable
        public static <T> T awaitIndefinitely​(Single<T> source)
                                       throws java.util.concurrent.ExecutionException,
                                              java.lang.InterruptedException
        Awaits termination of the passed Single by blocking the calling thread.
        Type Parameters:
        T - Type of the result of Single.
        Parameters:
        source - to await for.
        Returns:
        Result of the Single. null if the source is of type Void.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
      • awaitIndefinitelyNonNull

        public static <T> T awaitIndefinitelyNonNull​(Single<T> source)
                                              throws java.util.concurrent.ExecutionException,
                                                     java.lang.InterruptedException
        Awaits termination of the passed Single by blocking the calling thread.
        Type Parameters:
        T - Type of the result of Single.
        Parameters:
        source - to await for.
        Returns:
        Result of the Single. null if the source is of type Void.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure, or if the result of awaitIndefinitely(Single) is null.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
        See Also:
        awaitIndefinitely(Single)
      • await

        @Nullable
        public static <T> T await​(Single<T> source,
                                  long timeout,
                                  java.util.concurrent.TimeUnit timeoutUnit)
                           throws java.util.concurrent.ExecutionException,
                                  java.lang.InterruptedException,
                                  java.util.concurrent.TimeoutException
        Awaits termination of the passed Single by blocking the calling thread.
        Type Parameters:
        T - Type of the result of Single.
        Parameters:
        source - to await for.
        timeout - maximum time to wait for termination.
        timeoutUnit - TimeUnit for timeout.
        Returns:
        Result of the Single. null if the source is of type Void.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
        java.util.concurrent.TimeoutException - If the result isn't available after waiting for the passed timeout duration.
      • awaitNonNull

        public static <T> T awaitNonNull​(Single<T> source,
                                         long timeout,
                                         java.util.concurrent.TimeUnit timeoutUnit)
                                  throws java.util.concurrent.ExecutionException,
                                         java.lang.InterruptedException,
                                         java.util.concurrent.TimeoutException
        Awaits termination of the passed Single by blocking the calling thread.
        Type Parameters:
        T - Type of the result of Single.
        Parameters:
        source - to await for.
        timeout - maximum time to wait for termination.
        timeoutUnit - TimeUnit for timeout.
        Returns:
        Result of the Single. null if the source is of type Void.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure, or if the result of await(Single, long, TimeUnit) is null.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
        java.util.concurrent.TimeoutException - If the result isn't available after waiting for the passed timeout duration.
        See Also:
        await(Single, long, TimeUnit)
      • awaitIndefinitely

        public static void awaitIndefinitely​(Completable source)
                                      throws java.util.concurrent.ExecutionException,
                                             java.lang.InterruptedException
        Awaits termination of the passed Completable by blocking the calling thread.
        Parameters:
        source - to await for.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
      • awaitIndefinitelyUnchecked

        public static void awaitIndefinitelyUnchecked​(Completable source)
        Awaits termination of the passed Completable by blocking the calling thread.

        This method will re-throw exceptions from awaitIndefinitely(Completable).

        Parameters:
        source - to await for.
      • await

        public static void await​(Completable source,
                                 long timeout,
                                 java.util.concurrent.TimeUnit timeoutUnit)
                          throws java.util.concurrent.ExecutionException,
                                 java.lang.InterruptedException,
                                 java.util.concurrent.TimeoutException
        Awaits termination of the passed Completable by blocking the calling thread.
        Parameters:
        source - to await for.
        timeout - maximum time to wait for termination.
        timeoutUnit - TimeUnit for timeout.
        Throws:
        java.util.concurrent.ExecutionException - if the passed Publisher terminates with a failure.
        java.lang.InterruptedException - if the thread was interrupted while waiting for termination.
        java.util.concurrent.TimeoutException - If the Completable isn't terminated after waiting for the passed timeout duration.