Package io.mats3.test
Class MatsTestLatch
java.lang.Object
io.mats3.test.MatsTestLatch
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Some tests needs to assert that something does not happen, i.e. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
resolve
(MatsEndpoint.DetachedProcessContext context, Object sto, Object dto) When this method is invoked, the waiting threads will be released.void
When this method is invoked, the waiting threads will be released - this variant does not take the ProcessContext, usethe other one
!<S,
I> MatsTestLatch.Result<S, I> Convenience method ofwaitForResult(long)
meant for waiting for something that is expected to happen: Waits for 30 seconds for the test-latch to beresolved
.<S,
I> MatsTestLatch.Result<S, I> waitForResult
(long timeout) Waits for the specified time forresolve(DetachedProcessContext, Object, Object)
resolve(..)} to be invoked by some other thread, returning the result.
-
Field Details
-
WAIT_MILLIS_FOR_NON_OCCURRENCE
public static final int WAIT_MILLIS_FOR_NON_OCCURRENCESome 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
Convenience method ofwaitForResult(long)
meant for waiting for something that is expected to happen: Waits for 30 seconds for the test-latch to beresolved
. 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
Waits for the specified time forresolve(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, anAssertionError
is raised. Notice: If you wait for something that should happen, you should rather use the non-arg methodwaitForResult()
.- Parameters:
timeout
- the max time to wait.- Returns:
- the
MatsTestLatch.Result
. ThrowsAssertionError
if not gotten within timeout.
-
resolve
When this method is invoked, the waiting threads will be released - this variant does not take the ProcessContext, usethe other one
!- Parameters:
sto
- State object.dto
- the incoming state object that the Mats processor initially received.- See Also:
-
resolve
When this method is invoked, the waiting threads will be released.- Parameters:
context
- (Detached)ProcessContextsto
- State object.dto
- the incoming state object that the Mats processor initially received.
-