use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class AfterProcessingTimeStateMachineTest method testAfterProcessingTimeWithMergingWindow.
@Test
public void testAfterProcessingTimeWithMergingWindow() throws Exception {
SimpleTriggerStateMachineTester<IntervalWindow> tester = TriggerStateMachineTester.forTrigger(AfterProcessingTimeStateMachine.pastFirstElementInPane().plusDelayOf(Duration.millis(5)), Sessions.withGapDuration(Duration.millis(10)));
tester.advanceProcessingTime(new Instant(10));
// in [1, 11), timer for 15
tester.injectElements(1);
IntervalWindow firstWindow = new IntervalWindow(new Instant(1), new Instant(11));
assertFalse(tester.shouldFire(firstWindow));
tester.advanceProcessingTime(new Instant(12));
// in [3, 13), timer for 17
tester.injectElements(3);
IntervalWindow secondWindow = new IntervalWindow(new Instant(3), new Instant(13));
assertFalse(tester.shouldFire(secondWindow));
tester.mergeWindows();
IntervalWindow mergedWindow = new IntervalWindow(new Instant(1), new Instant(13));
tester.advanceProcessingTime(new Instant(16));
assertTrue(tester.shouldFire(mergedWindow));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class AfterWatermarkStateMachineTest method testEarlyAndLateOnMergeAlreadyFinished.
/**
* Tests that if the EOW is finished in both as well as the merged window, then it is finished in
* the merged result.
*
* <p>Because windows are discarded when a trigger finishes, we need to embed this in a sequence
* in order to check that it is re-activated. So this test is potentially sensitive to other
* triggers' correctness.
*/
@Test
public void testEarlyAndLateOnMergeAlreadyFinished() throws Exception {
tester = TriggerStateMachineTester.forTrigger(AfterWatermarkStateMachine.pastEndOfWindow().withEarlyFirings(AfterPaneStateMachine.elementCountAtLeast(100)).withLateFirings(AfterPaneStateMachine.elementCountAtLeast(1)), Sessions.withGapDuration(Duration.millis(10)));
tester.injectElements(1);
tester.injectElements(5);
IntervalWindow firstWindow = new IntervalWindow(new Instant(1), new Instant(11));
IntervalWindow secondWindow = new IntervalWindow(new Instant(5), new Instant(15));
IntervalWindow mergedWindow = new IntervalWindow(new Instant(1), new Instant(15));
// Finish the AfterWatermark.pastEndOfWindow() bit of the trigger in both windows
tester.advanceInputWatermark(new Instant(15));
assertTrue(tester.shouldFire(firstWindow));
assertTrue(tester.shouldFire(secondWindow));
tester.fireIfShouldFire(firstWindow);
tester.fireIfShouldFire(secondWindow);
// Confirm that we are on the late trigger by probing
assertFalse(tester.shouldFire(firstWindow));
assertFalse(tester.shouldFire(secondWindow));
tester.injectElements(1);
tester.injectElements(5);
assertTrue(tester.shouldFire(firstWindow));
assertTrue(tester.shouldFire(secondWindow));
tester.fireIfShouldFire(firstWindow);
tester.fireIfShouldFire(secondWindow);
// Merging should leave it on the late trigger
tester.mergeWindows();
// Confirm that we are on the late trigger by probing
assertFalse(tester.shouldFire(mergedWindow));
tester.injectElements(1);
assertTrue(tester.shouldFire(mergedWindow));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class AfterWatermarkStateMachineTest method testTimerForEndOfWindowCompound.
@Test
public void testTimerForEndOfWindowCompound() throws Exception {
tester = TriggerStateMachineTester.forTrigger(AfterWatermarkStateMachine.pastEndOfWindow().withEarlyFirings(NeverStateMachine.ever()), FixedWindows.of(Duration.millis(100)));
assertThat(tester.getNextTimer(TimeDomain.EVENT_TIME), nullValue());
injectElements(1);
IntervalWindow window = new IntervalWindow(new Instant(0), new Instant(100));
assertThat(tester.getNextTimer(TimeDomain.EVENT_TIME), equalTo(window.maxTimestamp()));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class AfterWatermarkStateMachineTest method testEarlyAndAtWatermark.
@Test
public void testEarlyAndAtWatermark() throws Exception {
tester = TriggerStateMachineTester.forTrigger(AfterWatermarkStateMachine.pastEndOfWindow().withEarlyFirings(mockEarly), FixedWindows.of(Duration.millis(100)));
injectElements(1);
IntervalWindow window = new IntervalWindow(new Instant(0), new Instant(100));
testRunningAsTrigger(mockEarly, window);
// Fire due to watermark
when(mockEarly.shouldFire(anyTriggerContext())).thenReturn(false);
tester.advanceInputWatermark(new Instant(100));
assertTrue(tester.shouldFire(window));
tester.fireIfShouldFire(window);
assertTrue(tester.isMarkedFinished(window));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class OrFinallyStateMachineTest method testActualFiresButUntilFinishes.
/**
* Tests that for {@code OrFinally(actual, until)} when {@code actual} fires but does not finish,
* then {@code until} fires and finishes, the whole thing fires and finished.
*/
@Test
public void testActualFiresButUntilFinishes() throws Exception {
tester = TriggerStateMachineTester.forTrigger(new OrFinallyStateMachine(RepeatedlyStateMachine.forever(AfterPaneStateMachine.elementCountAtLeast(2)), AfterPaneStateMachine.elementCountAtLeast(3)), FixedWindows.of(Duration.millis(10)));
IntervalWindow window = new IntervalWindow(new Instant(0), new Instant(10));
// Before any firing
tester.injectElements(1);
assertFalse(tester.shouldFire(window));
assertFalse(tester.isMarkedFinished(window));
// The actual fires but doesn't finish
tester.injectElements(2);
assertTrue(tester.shouldFire(window));
tester.fireIfShouldFire(window);
assertFalse(tester.isMarkedFinished(window));
// The until fires and finishes; the trigger is finished
tester.injectElements(3);
assertTrue(tester.shouldFire(window));
tester.fireIfShouldFire(window);
assertTrue(tester.isMarkedFinished(window));
}
Aggregations