DoFnTester (Google Cloud Dataflow SDK 1.9.1 API)

Google Cloud Dataflow SDK for Java, version 1.9.1

Class DoFnTester<InputT,OutputT>

  • java.lang.Object
  • Type Parameters:
    InputT - the type of the DoFn's (main) input elements
    OutputT - the type of the DoFn's (main) output elements

    public class DoFnTester<InputT,OutputT>
    extends Object
    A harness for unit-testing a DoFn.

    For example:

     DoFn<InputT, OutputT> fn = ...;
     DoFnTester<InputT, OutputT> fnTester = DoFnTester.of(fn);
     // Set arguments shared across all batches:
     fnTester.setSideInputs(...);      // If fn takes side inputs.
     fnTester.setSideOutputTags(...);  // If fn writes to side outputs.
     // Process a batch containing a single input element:
     Input testInput = ...;
     List<OutputT> testOutputs = fnTester.processBatch(testInput);
     Assert.assertThat(testOutputs, Matchers.hasItems(...));
     // Process a bigger batch:
     Assert.assertThat(fnTester.processBatch(i1, i2, ...), Matchers.hasItems(...));