use of org.joda.time.Instant in project beam by apache.
the class ReduceFnRunnerTest method testPaneInfoAllStatesAfterWatermarkAccumulating.
@Test
public void testPaneInfoAllStatesAfterWatermarkAccumulating() throws Exception {
ReduceFnTester<Integer, Iterable<Integer>, IntervalWindow> tester = ReduceFnTester.nonCombining(WindowingStrategy.of(FixedWindows.of(Duration.millis(10))).withTrigger(Repeatedly.forever(AfterFirst.of(AfterPane.elementCountAtLeast(2), AfterWatermark.pastEndOfWindow()))).withMode(AccumulationMode.ACCUMULATING_FIRED_PANES).withAllowedLateness(Duration.millis(100)).withTimestampCombiner(TimestampCombiner.EARLIEST).withClosingBehavior(ClosingBehavior.FIRE_ALWAYS));
tester.advanceInputWatermark(new Instant(0));
tester.injectElements(TimestampedValue.of(1, new Instant(1)), TimestampedValue.of(2, new Instant(2)));
List<WindowedValue<Iterable<Integer>>> output = tester.extractOutput();
assertThat(output, contains(WindowMatchers.valueWithPaneInfo(PaneInfo.createPane(true, false, Timing.EARLY, 0, -1))));
assertThat(output, contains(WindowMatchers.isSingleWindowedValue(containsInAnyOrder(1, 2), 1, 0, 10)));
tester.advanceInputWatermark(new Instant(50));
// We should get the ON_TIME pane even though it is empty,
// because we have an AfterWatermark.pastEndOfWindow() trigger.
output = tester.extractOutput();
assertThat(output, contains(WindowMatchers.valueWithPaneInfo(PaneInfo.createPane(false, false, Timing.ON_TIME, 1, 0))));
assertThat(output, contains(WindowMatchers.isSingleWindowedValue(containsInAnyOrder(1, 2), 9, 0, 10)));
// We should get the final pane even though it is empty.
tester.advanceInputWatermark(new Instant(150));
output = tester.extractOutput();
assertThat(output, contains(WindowMatchers.valueWithPaneInfo(PaneInfo.createPane(false, true, Timing.LATE, 2, 1))));
assertThat(output, contains(WindowMatchers.isSingleWindowedValue(containsInAnyOrder(1, 2), 9, 0, 10)));
}
use of org.joda.time.Instant in project beam by apache.
the class SimplePushbackSideInputDoFnRunnerTest method processElementSideInputNotReadySomeWindows.
@Test
public void processElementSideInputNotReadySomeWindows() {
when(reader.isReady(Mockito.eq(singletonView), Mockito.eq(GlobalWindow.INSTANCE))).thenReturn(false);
when(reader.isReady(Mockito.eq(singletonView), org.mockito.AdditionalMatchers.not(Mockito.eq(GlobalWindow.INSTANCE)))).thenReturn(true);
SimplePushbackSideInputDoFnRunner<Integer, Integer> runner = createRunner(ImmutableList.<PCollectionView<?>>of(singletonView));
IntervalWindow littleWindow = new IntervalWindow(new Instant(-500L), new Instant(0L));
IntervalWindow bigWindow = new IntervalWindow(BoundedWindow.TIMESTAMP_MIN_VALUE, new Instant(250L));
WindowedValue<Integer> multiWindow = WindowedValue.of(2, new Instant(-2), ImmutableList.of(littleWindow, bigWindow, GlobalWindow.INSTANCE), PaneInfo.NO_FIRING);
Iterable<WindowedValue<Integer>> multiWindowPushback = runner.processElementInReadyWindows(multiWindow);
assertThat(multiWindowPushback, containsInAnyOrder(WindowedValue.timestampedValueInGlobalWindow(2, new Instant(-2L))));
assertThat(underlying.inputElems, containsInAnyOrder(WindowedValue.of(2, new Instant(-2), ImmutableList.of(littleWindow), PaneInfo.NO_FIRING), WindowedValue.of(2, new Instant(-2), ImmutableList.of(bigWindow), PaneInfo.NO_FIRING)));
}
use of org.joda.time.Instant in project beam by apache.
the class SimplePushbackSideInputDoFnRunnerTest method processElementNoSideInputs.
@Test
public void processElementNoSideInputs() {
SimplePushbackSideInputDoFnRunner<Integer, Integer> runner = createRunner(ImmutableList.<PCollectionView<?>>of());
WindowedValue<Integer> multiWindow = WindowedValue.of(2, new Instant(-2), ImmutableList.of(new IntervalWindow(new Instant(-500L), new Instant(0L)), new IntervalWindow(BoundedWindow.TIMESTAMP_MIN_VALUE, new Instant(250L)), GlobalWindow.INSTANCE), PaneInfo.ON_TIME_AND_ONLY_FIRING);
Iterable<WindowedValue<Integer>> multiWindowPushback = runner.processElementInReadyWindows(multiWindow);
assertThat(multiWindowPushback, emptyIterable());
// Should preserve the compressed representation when there's no side inputs.
assertThat(underlying.inputElems, containsInAnyOrder(multiWindow));
}
use of org.joda.time.Instant in project beam by apache.
the class SimplePushbackSideInputDoFnRunnerTest method testOnTimerCalled.
/** Tests that a call to onTimer gets delegated. */
@Test
public void testOnTimerCalled() {
PushbackSideInputDoFnRunner<Integer, Integer> runner = createRunner(ImmutableList.<PCollectionView<?>>of());
String timerId = "fooTimer";
IntervalWindow window = new IntervalWindow(new Instant(4), new Instant(16));
Instant timestamp = new Instant(72);
// Mocking is not easily compatible with annotation analysis, so we manually record
// the method call.
runner.onTimer(timerId, window, new Instant(timestamp), TimeDomain.EVENT_TIME);
assertThat(underlying.firedTimers, contains(TimerData.of(timerId, StateNamespaces.window(IntervalWindow.getCoder(), window), timestamp, TimeDomain.EVENT_TIME)));
}
use of org.joda.time.Instant in project beam by apache.
the class SimplePushbackSideInputDoFnRunnerTest method processElementSideInputNotReady.
@Test
public void processElementSideInputNotReady() {
when(reader.isReady(Mockito.eq(singletonView), Mockito.any(BoundedWindow.class))).thenReturn(false);
SimplePushbackSideInputDoFnRunner<Integer, Integer> runner = createRunner(ImmutableList.<PCollectionView<?>>of(singletonView));
WindowedValue<Integer> oneWindow = WindowedValue.of(2, new Instant(-2), new IntervalWindow(new Instant(-500L), new Instant(0L)), PaneInfo.ON_TIME_AND_ONLY_FIRING);
Iterable<WindowedValue<Integer>> oneWindowPushback = runner.processElementInReadyWindows(oneWindow);
assertThat(oneWindowPushback, containsInAnyOrder(oneWindow));
assertThat(underlying.inputElems, Matchers.<WindowedValue<Integer>>emptyIterable());
}
Aggregations