Class TestEnvironment

java.lang.Object
org.reactivestreams.tck.TestEnvironment

public class TestEnvironment extends Object
  • Field Details

    • TEST_BUFFER_SIZE

      public static final int TEST_BUFFER_SIZE
      See Also:
    • DEFAULT_TIMEOUT_MILLIS_ENV

      private static final String DEFAULT_TIMEOUT_MILLIS_ENV
      See Also:
    • DEFAULT_TIMEOUT_MILLIS

      private static final long DEFAULT_TIMEOUT_MILLIS
      See Also:
    • DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS_ENV

      private static final String DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS_ENV
      See Also:
    • DEFAULT_POLL_TIMEOUT_MILLIS_ENV

      private static final String DEFAULT_POLL_TIMEOUT_MILLIS_ENV
      See Also:
    • defaultTimeoutMillis

      private final long defaultTimeoutMillis
    • defaultPollTimeoutMillis

      private final long defaultPollTimeoutMillis
    • defaultNoSignalsTimeoutMillis

      private final long defaultNoSignalsTimeoutMillis
    • printlnDebug

      private final boolean printlnDebug
    • asyncErrors

      private CopyOnWriteArrayList<Throwable> asyncErrors
  • Constructor Details

    • TestEnvironment

      public TestEnvironment(long defaultTimeoutMillis, long defaultNoSignalsTimeoutMillis, long defaultPollTimeoutMillis, boolean printlnDebug)
      Tests must specify the timeout for expected outcome of asynchronous interactions. Longer timeout does not invalidate the correctness of the implementation, but can in some cases result in longer time to run the tests.
      Parameters:
      defaultTimeoutMillis - default timeout to be used in all expect* methods
      defaultNoSignalsTimeoutMillis - default timeout to be used when no further signals are expected anymore
      defaultPollTimeoutMillis - default amount of time to poll for events if defaultTimeoutMillis isn't preempted by an asynchronous event.
      printlnDebug - if true, signals such as OnNext / Request / OnComplete etc will be printed to standard output,
    • TestEnvironment

      public TestEnvironment(long defaultTimeoutMillis, long defaultNoSignalsTimeoutMillis, boolean printlnDebug)
      Tests must specify the timeout for expected outcome of asynchronous interactions. Longer timeout does not invalidate the correctness of the implementation, but can in some cases result in longer time to run the tests.
      Parameters:
      defaultTimeoutMillis - default timeout to be used in all expect* methods
      defaultNoSignalsTimeoutMillis - default timeout to be used when no further signals are expected anymore
      printlnDebug - if true, signals such as OnNext / Request / OnComplete etc will be printed to standard output,
    • TestEnvironment

      public TestEnvironment(long defaultTimeoutMillis, long defaultNoSignalsTimeoutMillis, long defaultPollTimeoutMillis)
      Tests must specify the timeout for expected outcome of asynchronous interactions. Longer timeout does not invalidate the correctness of the implementation, but can in some cases result in longer time to run the tests.
      Parameters:
      defaultTimeoutMillis - default timeout to be used in all expect* methods
      defaultNoSignalsTimeoutMillis - default timeout to be used when no further signals are expected anymore
      defaultPollTimeoutMillis - default amount of time to poll for events if defaultTimeoutMillis isn't preempted by an asynchronous event.
    • TestEnvironment

      public TestEnvironment(long defaultTimeoutMillis, long defaultNoSignalsTimeoutMillis)
      Tests must specify the timeout for expected outcome of asynchronous interactions. Longer timeout does not invalidate the correctness of the implementation, but can in some cases result in longer time to run the tests.
      Parameters:
      defaultTimeoutMillis - default timeout to be used in all expect* methods
      defaultNoSignalsTimeoutMillis - default timeout to be used when no further signals are expected anymore
    • TestEnvironment

      public TestEnvironment(long defaultTimeoutMillis)
      Tests must specify the timeout for expected outcome of asynchronous interactions. Longer timeout does not invalidate the correctness of the implementation, but can in some cases result in longer time to run the tests.
      Parameters:
      defaultTimeoutMillis - default timeout to be used in all expect* methods
    • TestEnvironment

      public TestEnvironment(boolean printlnDebug)
      Tests must specify the timeout for expected outcome of asynchronous interactions. Longer timeout does not invalidate the correctness of the implementation, but can in some cases result in longer time to run the tests. The default timeout for all expect* methods will be obtained by either the env variable DEFAULT_TIMEOUT_MILLIS or the default value (DEFAULT_TIMEOUT_MILLIS) will be used.
      Parameters:
      printlnDebug - if true, signals such as OnNext / Request / OnComplete etc will be printed to standard output, often helpful to pinpoint simple race conditions etc.
    • TestEnvironment

      public TestEnvironment()
      Tests must specify the timeout for expected outcome of asynchronous interactions. Longer timeout does not invalidate the correctness of the implementation, but can in some cases result in longer time to run the tests. The default timeout for all expect* methods will be obtained by either the env variable DEFAULT_TIMEOUT_MILLIS or the default value (DEFAULT_TIMEOUT_MILLIS) will be used.
  • Method Details

    • defaultTimeoutMillis

      public long defaultTimeoutMillis()
      This timeout is used when waiting for a signal to arrive.
    • defaultNoSignalsTimeoutMillis

      public long defaultNoSignalsTimeoutMillis()
      This timeout is used when asserting that no further signals are emitted. Note that this timeout default
    • defaultPollTimeoutMillis

      public long defaultPollTimeoutMillis()
      The default amount of time to poll for events if defaultTimeoutMillis isn't preempted by an asynchronous event.
    • envDefaultTimeoutMillis

      public static long envDefaultTimeoutMillis()
      Tries to parse the env variable DEFAULT_TIMEOUT_MILLIS as long and returns the value if present OR its default value.
      Throws:
      IllegalArgumentException - when unable to parse the env variable
    • envDefaultNoSignalsTimeoutMillis

      public static long envDefaultNoSignalsTimeoutMillis()
      Tries to parse the env variable DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS as long and returns the value if present OR its default value.
      Throws:
      IllegalArgumentException - when unable to parse the env variable
    • envDefaultPollTimeoutMillis

      public static long envDefaultPollTimeoutMillis()
      Tries to parse the env variable DEFAULT_POLL_TIMEOUT_MILLIS_ENV as long and returns the value if present OR its default value.
      Throws:
      IllegalArgumentException - when unable to parse the env variable
    • flop

      public void flop(String msg)
      To flop means to "fail asynchronously", either by onErroring or by failing some TCK check triggered asynchronously. This method does *NOT* fail the test - it's up to inspections of the error to fail the test if required. Use env.verifyNoAsyncErrorsNoDelay() at the end of your TCK tests to verify there no flops called during it's execution. To check investigate asyncErrors more closely you can use expectError methods or collect the error directly from the environment using env.dropAsyncError(). To clear asyncErrors you can call clearAsyncErrors()
    • flop

      public void flop(Throwable thr, String msg)
      To flop means to "fail asynchronously", either by onErroring or by failing some TCK check triggered asynchronously. This method does *NOT* fail the test - it's up to inspections of the error to fail the test if required. This overload keeps the passed in throwable as the asyncError, instead of creating an AssertionError for this. Use env.verifyNoAsyncErrorsNoDelay() at the end of your TCK tests to verify there no flops called during it's execution. To check investigate asyncErrors more closely you can use expectError methods or collect the error directly from the environment using env.dropAsyncError(). To clear asyncErrors you can call clearAsyncErrors()
    • flop

      public void flop(Throwable thr)
      To flop means to "fail asynchronously", either by onErroring or by failing some TCK check triggered asynchronously. This method does *NOT* fail the test - it's up to inspections of the error to fail the test if required. This overload keeps the passed in throwable as the asyncError, instead of creating an AssertionError for this. Use env.verifyNoAsyncErrorsNoDelay() at the end of your TCK tests to verify there no flops called during it's execution. To check investigate asyncErrors more closely you can use expectError methods or collect the error directly from the environment using env.dropAsyncError(). To clear asyncErrors you can call clearAsyncErrors()
    • flopAndFail

      public <T> T flopAndFail(String msg)
      To flop means to "fail asynchronously", either by onErroring or by failing some TCK check triggered asynchronously. This method DOES fail the test right away (it tries to, by throwing an AssertionException), in such it is different from flop(java.lang.String) which only records the error. Use env.verifyNoAsyncErrorsNoDelay() at the end of your TCK tests to verify there no flops called during it's execution. To check investigate asyncErrors more closely you can use expectError methods or collect the error directly from the environment using env.dropAsyncError(). To clear asyncErrors you can call clearAsyncErrors()
    • subscribe

      public <T> void subscribe(Publisher<T> pub, TestEnvironment.TestSubscriber<T> sub) throws InterruptedException
      Throws:
      InterruptedException
    • subscribe

      public <T> void subscribe(Publisher<T> pub, TestEnvironment.TestSubscriber<T> sub, long timeoutMillis) throws InterruptedException
      Throws:
      InterruptedException
    • newBlackholeSubscriber

      public <T> TestEnvironment.ManualSubscriber<T> newBlackholeSubscriber(Publisher<T> pub) throws InterruptedException
      Throws:
      InterruptedException
    • newManualSubscriber

      public <T> TestEnvironment.ManualSubscriber<T> newManualSubscriber(Publisher<T> pub) throws InterruptedException
      Throws:
      InterruptedException
    • newManualSubscriber

      public <T> TestEnvironment.ManualSubscriber<T> newManualSubscriber(Publisher<T> pub, long timeoutMillis) throws InterruptedException
      Throws:
      InterruptedException
    • clearAsyncErrors

      public void clearAsyncErrors()
    • dropAsyncError

      public Throwable dropAsyncError()
    • verifyNoAsyncErrors

      public void verifyNoAsyncErrors()
      Waits for defaultNoSignalsTimeoutMillis() and then verifies that no asynchronous errors were signalled pior to, or during that time (by calling flop()).
    • verifyNoAsyncErrors

      public void verifyNoAsyncErrors(long delay)
      This version of verifyNoAsyncErrors should be used when errors still could be signalled asynchronously during defaultTimeoutMillis() time.

      It will immediatly check if any async errors were signaled (using flop(String), and if no errors encountered wait for another default timeout as the errors may yet be signalled. The initial check is performed in order to fail-fast in case of an already failed test.
    • verifyNoAsyncErrorsNoDelay

      public void verifyNoAsyncErrorsNoDelay()
      Verifies that no asynchronous errors were signalled pior to calling this method (by calling flop()). This version of verifyNoAsyncError does not wait before checking for asynchronous errors, and is to be used for example in tight loops etc.
    • debug

      public void debug(String msg)
      If TestEnvironment#printlnDebug is true, print debug message to std out.
    • debugEnabled

      public final boolean debugEnabled()
    • findCallerMethodInStackTrace

      public Optional<StackTraceElement> findCallerMethodInStackTrace(String method)
      Looks for given method method in stack trace. Can be used to answer questions like "was this method called from onComplete?".
      Returns:
      the caller's StackTraceElement at which he the looked for method was found in the call stack, EMPTY otherwise