Search in sources :

Example 16 with StateNamespaceForTest

use of org.apache.beam.runners.core.StateNamespaceForTest in project beam by apache.

the class StreamingModeExecutionContextTest method testTimerInternalsSetTimer.

@Test
public void testTimerInternalsSetTimer() {
    Windmill.WorkItemCommitRequest.Builder outputBuilder = Windmill.WorkItemCommitRequest.newBuilder();
    NameContext nameContext = NameContextsForTests.nameContextForTest();
    DataflowOperationContext operationContext = executionContext.createOperationContext(nameContext);
    StreamingModeExecutionContext.StepContext stepContext = executionContext.getStepContext(operationContext);
    executionContext.start("key", Windmill.WorkItem.newBuilder().setKey(ByteString.EMPTY).setWorkToken(17L).build(), // input watermark
    new Instant(1000), // output watermark
    null, // synchronized processing time
    null, stateReader, stateFetcher, outputBuilder);
    TimerInternals timerInternals = stepContext.timerInternals();
    timerInternals.setTimer(TimerData.of(new StateNamespaceForTest("key"), new Instant(5000), new Instant(5000), TimeDomain.EVENT_TIME));
    executionContext.flushState();
    Windmill.Timer timer = outputBuilder.buildPartial().getOutputTimers(0);
    assertThat(timer.getTag().toStringUtf8(), equalTo("/skey+0:5000"));
    assertThat(timer.getTimestamp(), equalTo(TimeUnit.MILLISECONDS.toMicros(5000)));
    assertThat(timer.getType(), equalTo(Windmill.Timer.Type.WATERMARK));
}
Also used : TimerInternals(org.apache.beam.runners.core.TimerInternals) Instant(org.joda.time.Instant) NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Windmill(org.apache.beam.runners.dataflow.worker.windmill.Windmill) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Aggregations

StateNamespaceForTest (org.apache.beam.runners.core.StateNamespaceForTest)16 Test (org.junit.Test)16 StateNamespace (org.apache.beam.runners.core.StateNamespace)15 BagState (org.apache.beam.sdk.state.BagState)10 Instant (org.joda.time.Instant)2 TimerInternals (org.apache.beam.runners.core.TimerInternals)1 NameContext (org.apache.beam.runners.dataflow.worker.counters.NameContext)1 Windmill (org.apache.beam.runners.dataflow.worker.windmill.Windmill)1 CoderRegistry (org.apache.beam.sdk.coders.CoderRegistry)1 CombiningState (org.apache.beam.sdk.state.CombiningState)1 MapState (org.apache.beam.sdk.state.MapState)1 SetState (org.apache.beam.sdk.state.SetState)1 ValueState (org.apache.beam.sdk.state.ValueState)1 WatermarkHoldState (org.apache.beam.sdk.state.WatermarkHoldState)1 TimestampCombiner (org.apache.beam.sdk.transforms.windowing.TimestampCombiner)1