Class TestPubsubSignal

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class TestPubsubSignal
    extends java.lang.Object
    implements org.junit.rules.TestRule
    Test rule which observes elements of the PCollection and checks whether they match the success criteria.

    Uses a random temporary Pubsub topic for synchronization.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)  
      static TestPubsubSignal create()
      Creates an instance of this rule.
      org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PBegin,​org.apache.beam.sdk.values.PDone> signalStart()
      Outputs a message that the pipeline has started.
      <T> org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<? extends T>,​org.apache.beam.sdk.values.POutput> signalSuccessWhen​(org.apache.beam.sdk.coders.Coder<T> coder, org.apache.beam.sdk.transforms.SerializableFunction<java.util.Set<T>,​java.lang.Boolean> successPredicate)
      Invocation of signalSuccessWhen(Coder, SerializableFunction, SerializableFunction) with Object.toString() as the formatter.
      <T> org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<? extends T>,​org.apache.beam.sdk.values.POutput> signalSuccessWhen​(org.apache.beam.sdk.coders.Coder<T> coder, org.apache.beam.sdk.transforms.SerializableFunction<T,​java.lang.String> formatter, org.apache.beam.sdk.transforms.SerializableFunction<java.util.Set<T>,​java.lang.Boolean> successPredicate)
      Outputs a success message when successPredicate is evaluated to true.
      org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Supplier<java.lang.Void> waitForStart​(org.joda.time.Duration duration)
      Future that waits for a start signal for duration.
      void waitForSuccess​(org.joda.time.Duration duration)
      Wait for a success signal for duration.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        public static TestPubsubSignal create()
        Creates an instance of this rule.

        Loads GCP configuration from TestPipelineOptions.

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • signalStart

        public org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PBegin,​org.apache.beam.sdk.values.PDone> signalStart()
        Outputs a message that the pipeline has started.
      • signalSuccessWhen

        public <T> org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<? extends T>,​org.apache.beam.sdk.values.POutput> signalSuccessWhen​(org.apache.beam.sdk.coders.Coder<T> coder,
                                                                                                                                                                             org.apache.beam.sdk.transforms.SerializableFunction<T,​java.lang.String> formatter,
                                                                                                                                                                             org.apache.beam.sdk.transforms.SerializableFunction<java.util.Set<T>,​java.lang.Boolean> successPredicate)
        Outputs a success message when successPredicate is evaluated to true.

        successPredicate is a SerializableFunction that accepts a set of currently captured events and returns true when the set satisfies the success criteria.

        If successPredicate is evaluated to false, then it will be re-evaluated when next event becomes available.

        If successPredicate is evaluated to true, then a success will be signaled and waitForSuccess(Duration) will unblock.

        If successPredicate throws, then failure will be signaled and waitForSuccess(Duration) will unblock.

      • signalSuccessWhen

        public <T> org.apache.beam.sdk.transforms.PTransform<org.apache.beam.sdk.values.PCollection<? extends T>,​org.apache.beam.sdk.values.POutput> signalSuccessWhen​(org.apache.beam.sdk.coders.Coder<T> coder,
                                                                                                                                                                             org.apache.beam.sdk.transforms.SerializableFunction<java.util.Set<T>,​java.lang.Boolean> successPredicate)
        Invocation of signalSuccessWhen(Coder, SerializableFunction, SerializableFunction) with Object.toString() as the formatter.
      • waitForStart

        public org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Supplier<java.lang.Void> waitForStart​(org.joda.time.Duration duration)
        Future that waits for a start signal for duration.

        This future must be created before running the pipeline. A subscription must exist prior to the start signal being published, which occurs immediately upon pipeline startup.

      • waitForSuccess

        public void waitForSuccess​(org.joda.time.Duration duration)
                            throws java.io.IOException
        Wait for a success signal for duration.
        Throws:
        java.io.IOException