Package io.mats3.test

Class MatsTestLatch

java.lang.Object
io.mats3.test.MatsTestLatch

public class MatsTestLatch extends Object
Test-utility: Gives a latch-functionality facilitating communication back from typically a Mats Terminator to the main-thread that sent a message to some processor, and is now waiting for the Terminator to get the result.
  • Field Details

    • WAIT_MILLIS_FOR_NON_OCCURRENCE

      public static final int WAIT_MILLIS_FOR_NON_OCCURRENCE
      Some tests needs to assert that something does not happen, i.e. actually wait for the timeout to expire. This time should obviously be as short as possible, but due to extreme inconsistencies on the runners of some continuous integration systems, we've set it at 1 second (1000 millis). This constant works as a central place to define this, so that it is not spread out through lots of tests.
  • Constructor Details

    • MatsTestLatch

      public MatsTestLatch()
  • Method Details

    • waitForResult

      public <S, I> MatsTestLatch.Result<S,I> waitForResult()
      Convenience method of waitForResult(long) meant for waiting for something that is expected to happen: Waits for 30 seconds for the test-latch to be resolved. Since tests employing this method should resolve as fast as possible, it makes little sense to limit this waiting time to "a short time", as either the test works, and it resolves literally as fast as possible, or the test is broken, and then it doesn't really matter that you have to wait 30 seconds to find out. What we don't want is a test that fails due to e.g. garbage collection kicking in, or some other infrastructural matters that do not relate to the test.
      Returns:
      same as waitForResult(long).
    • waitForResult

      public <S, I> MatsTestLatch.Result<S,I> waitForResult(long timeout)
      Waits for the specified time for resolve(DetachedProcessContext, Object, Object) resolve(..)} to be invoked by some other thread, returning the result. If the result is already in, it immediately returns. If the result does not come within timeout, an AssertionError is raised.

      Notice: If you wait for something that should happen, you should rather use the non-arg method waitForResult().

      Parameters:
      timeout - the max time to wait.
      Returns:
      the MatsTestLatch.Result. Throws AssertionError if not gotten within timeout.
    • resolve

      public void resolve(Object sto, Object dto)
      When this method is invoked, the waiting threads will be released - this variant does not take the ProcessContext, use the other one!
      Parameters:
      sto - State object.
      dto - the incoming state object that the Mats processor initially received.
      See Also:
    • resolve

      public void resolve(MatsEndpoint.DetachedProcessContext context, Object sto, Object dto)
      When this method is invoked, the waiting threads will be released.
      Parameters:
      context - (Detached)ProcessContext
      sto - State object.
      dto - the incoming state object that the Mats processor initially received.