Class AssertionSinks
- java.lang.Object
-
- com.hazelcast.jet.pipeline.test.AssertionSinks
-
public final class AssertionSinks extends java.lang.Object
Various assertions which can be used to assert items on the output of a pipeline.In this class there are variants that can be used as sinks in the pipeline. Variants that can be used in-line in a pipeline are in
Assertions
.- Since:
- Jet 3.2
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Sink<T>
assertAnyOrder(java.lang.String message, java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted the expected items in any order, but nothing else.static <T> Sink<T>
assertAnyOrder(java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted the expected items in any order, but nothing else.static <T> Sink<T>
assertCollected(ConsumerEx<? super java.util.List<T>> assertFn)
Collects all the received items in a list and once the upstream stage is completed it executes the assertion supplied byassertFn
.static <T> Sink<T>
assertCollectedEventually(int timeoutSeconds, ConsumerEx<? super java.util.List<T>> assertFn)
Collects all the received items into a list and runs theassertFn
every time a new item is received.static <T> Sink<T>
assertContains(java.lang.String message, java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted all of the given items in any order.static <T> Sink<T>
assertOrdered(java.lang.String message, java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted the exact sequence of expected items and nothing else.static <T> Sink<T>
assertOrdered(java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted the exact sequence of expected items and nothing else.
-
-
-
Method Detail
-
assertOrdered
@Nonnull public static <T> Sink<T> assertOrdered(@Nullable java.lang.String message, @Nonnull java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted the exact sequence of expected items and nothing else. If the assertion fails, the job will fail with anAssertionError
with the given message.Since Jet jobs are distributed, input from multiple upstream processors is merged in a non-deterministic way. Therefore this assertion is usable only for testing of non-distributed sources.
-
assertOrdered
@Nonnull public static <T> Sink<T> assertOrdered(@Nonnull java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted the exact sequence of expected items and nothing else. If the assertion fails, the job will fail with anAssertionError
.Since Jet jobs are distributed, input from multiple upstream processors is merged in a non-deterministic way. Therefore this assertion is usable only for testing of non-distributed sources.
-
assertAnyOrder
@Nonnull public static <T> Sink<T> assertAnyOrder(@Nullable java.lang.String message, @Nonnull java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted the expected items in any order, but nothing else. If the assertion fails, the job will fail with anAssertionError
with the given message.
-
assertAnyOrder
@Nonnull public static <T> Sink<T> assertAnyOrder(@Nonnull java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted the expected items in any order, but nothing else. If the assertion fails, the job will fail with anAssertionError
.
-
assertContains
@Nonnull public static <T> Sink<T> assertContains(@Nullable java.lang.String message, @Nonnull java.util.Collection<? extends T> expected)
Asserts that the previous stage emitted all of the given items in any order. If the assertion fails, the job will fail with aAssertionError
with the given message.
-
assertCollected
@Nonnull public static <T> Sink<T> assertCollected(@Nonnull ConsumerEx<? super java.util.List<T>> assertFn)
Collects all the received items in a list and once the upstream stage is completed it executes the assertion supplied byassertFn
. If no items were collected, it will be called with empty list.Not usable in streaming jobs - use
assertCollectedEventually(int, com.hazelcast.function.ConsumerEx<? super java.util.List<T>>)
.- Parameters:
assertFn
- assertion to execute once all items are received
-
assertCollectedEventually
@Nonnull public static <T> Sink<T> assertCollectedEventually(int timeoutSeconds, @Nonnull ConsumerEx<? super java.util.List<T>> assertFn)
Collects all the received items into a list and runs theassertFn
every time a new item is received. AnAssertionError
thrown from theassertFn
will be ignored untiltimeoutSeconds
have passed, after which the lastAssertionError
will be rethrown. IfassertFn
throws any other exception, it will be rethrown immediately.When
assertFn
completes without any error, the sink will throw anAssertionCompletedException
to indicate success. Exception is used to terminate the job so that you canjoin()
it. This also requires that there are no other assertions in the job as this one can complete the job before the other ones succeeded.The assertion can be validated as follows:
{@code try { jetInstance.newJob(p).join(); Assert.fail("Job should have completed with an AssertionCompletedException, " + "but completed normally"); } catch (CompletionException e) { String errorMsg = e.getCause().getMessage(); Assert.assertTrue( "Job was expected to complete with AssertionCompletedException, but completed with: " + e.getCause(), errorMsg.contains(AssertionCompletedException.class.getName()) ); }
- Parameters:
timeoutSeconds
- timeout in seconds, after which any assertion error will be propagatedassertFn
- assertion to execute periodically
-
-