Search in sources :

Example 6 with Receiver

use of org.apache.beam.runners.dataflow.worker.util.common.worker.Receiver in project beam by apache.

the class UserParDoFnFactoryTest method testFactorySimultaneousUse.

@Test
public void testFactorySimultaneousUse() throws Exception {
    PipelineOptions options = PipelineOptionsFactory.create();
    CounterSet counters = new CounterSet();
    TestDoFn initialFn = new TestDoFn(Collections.<TupleTag<String>>emptyList());
    CloudObject cloudObject = getCloudObject(initialFn);
    ParDoFn parDoFn = factory.create(options, cloudObject, null, MAIN_OUTPUT, ImmutableMap.<TupleTag<?>, Integer>of(MAIN_OUTPUT, 0), BatchModeExecutionContext.forTesting(options, "testStage"), TestOperationContext.create(counters));
    // The fn should not be reused while the first ParDoFn is not finished
    ParDoFn secondParDoFn = factory.create(options, cloudObject, null, MAIN_OUTPUT, ImmutableMap.<TupleTag<?>, Integer>of(MAIN_OUTPUT, 0), BatchModeExecutionContext.forTesting(options, "testStage"), TestOperationContext.create(counters));
    Receiver rcvr = new OutputReceiver();
    parDoFn.startBundle(rcvr);
    parDoFn.processElement(WindowedValue.valueInGlobalWindow("foo"));
    // Must be after the first call to process element for reallyStartBundle to have been called
    TestDoFn firstDoFn = (TestDoFn) ((SimpleParDoFn) parDoFn).getDoFnInfo().getDoFn();
    secondParDoFn.startBundle(rcvr);
    secondParDoFn.processElement(WindowedValue.valueInGlobalWindow("spam"));
    // Must be after the first call to process element for reallyStartBundle to have been called
    TestDoFn secondDoFn = (TestDoFn) ((SimpleParDoFn) secondParDoFn).getDoFnInfo().getDoFn();
    parDoFn.finishBundle();
    secondParDoFn.finishBundle();
    assertThat(firstDoFn, not(theInstance(secondDoFn)));
    assertThat(firstDoFn.state, equalTo(TestDoFn.State.FINISHED));
    assertThat(secondDoFn.state, equalTo(TestDoFn.State.FINISHED));
}
Also used : CounterSet(org.apache.beam.runners.dataflow.worker.counters.CounterSet) CloudObject(org.apache.beam.runners.dataflow.util.CloudObject) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) Receiver(org.apache.beam.runners.dataflow.worker.util.common.worker.Receiver) OutputReceiver(org.apache.beam.runners.dataflow.worker.util.common.worker.OutputReceiver) OutputReceiver(org.apache.beam.runners.dataflow.worker.util.common.worker.OutputReceiver) ParDoFn(org.apache.beam.runners.dataflow.worker.util.common.worker.ParDoFn) Test(org.junit.Test)

Aggregations

OutputReceiver (org.apache.beam.runners.dataflow.worker.util.common.worker.OutputReceiver)6 Receiver (org.apache.beam.runners.dataflow.worker.util.common.worker.Receiver)6 CloudObject (org.apache.beam.runners.dataflow.util.CloudObject)5 CounterSet (org.apache.beam.runners.dataflow.worker.counters.CounterSet)5 ParDoFn (org.apache.beam.runners.dataflow.worker.util.common.worker.ParDoFn)5 PipelineOptions (org.apache.beam.sdk.options.PipelineOptions)5 Test (org.junit.Test)5 DataflowStepContext (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext)2 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)2 Instant (org.joda.time.Instant)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OutputManager (org.apache.beam.runners.core.DoFnRunners.OutputManager)1 InMemoryStateInternals (org.apache.beam.runners.core.InMemoryStateInternals)1 StateInternals (org.apache.beam.runners.core.StateInternals)1 StateNamespace (org.apache.beam.runners.core.StateNamespace)1 TimerInternals (org.apache.beam.runners.core.TimerInternals)1 ElementCounter (org.apache.beam.runners.dataflow.worker.util.common.worker.ElementCounter)1 Coder (org.apache.beam.sdk.coders.Coder)1 StringUtf8Coder (org.apache.beam.sdk.coders.StringUtf8Coder)1