Class AssertionSinkBuilder<S,T>

java.lang.Object
com.hazelcast.jet.pipeline.test.AssertionSinkBuilder<S,T>
Type Parameters:
S - type of the state object
T - type of the items the sink will accept

public final class AssertionSinkBuilder<S,T> extends Object
Since:
Jet 3.2
  • Method Details

    • assertionSink

      @Nonnull public static <S> AssertionSinkBuilder<S,Void> assertionSink(@Nonnull String name, @Nonnull SupplierEx<? extends S> createFn)
      Returns a builder object that offers a step-by-step fluent API to build an assertion Sink for the Pipeline API. An assertion sink is typically used for testing of pipelines where you want to run an assertion either on each item as they arrive, or when all items have been received.

      These are the callback functions you can provide to implement the sink's behavior:

      • createFn creates the state which can be used to hold incoming items.
      • receiveFn gets notified of each item the sink receives and can either assert the item directly or add it to the state object.
      • timerFn is run periodically even when there are no items received. This can be used to assert that certain assertions have been reached within a specific time in streaming pipelines.
      • completeFn is run after all the items have been received. This only applies to batch jobs, in a streaming job this method will never be called.
      The returned sink will have a global parallelism of 1: all items will be sent to the same instance of the sink.

      The sink doesn't participate in the fault-tolerance protocol, which means you can't remember which items you already received across a job restart.

      Type Parameters:
      S - type of the state object
      Since:
      Jet 3.2
    • receiveFn

      @Nonnull public <T_NEW> AssertionSinkBuilder<S,T_NEW> receiveFn(@Nonnull BiConsumerEx<? super S,? super T_NEW> receiveFn)
      Sets the function Jet will call upon receiving every item. The function receives two arguments: the state object (as provided by the createFn) and the received item. It may assert the item directly or push it to the state object.
      Type Parameters:
      T_NEW - type of the items the sink will accept
      Parameters:
      receiveFn - the function to execute upon receiving an item
    • timerFn

      @Nonnull public AssertionSinkBuilder<S,T> timerFn(@Nonnull ConsumerEx<? super S> timerFn)
      Sets the function that will be called periodically. You can use this function to assert that a condition will eventually be reached. The function is guaranteed to be called even if there are no items coming into the sink.

      This function is optional.

      Parameters:
      timerFn - the optional "timer" function
    • completeFn

      @Nonnull public AssertionSinkBuilder<S,T> completeFn(@Nonnull ConsumerEx<? super S> completeFn)
      Sets the function that will be called after all the upstream stages have completed and all the items were received.

      This function is optional.

      Parameters:
      completeFn - the optional "complete" function
    • build

      @Nonnull public Sink<T> build()
      Creates and returns the Sink with the components you supplied to this builder.