use of org.apache.apex.malhar.lib.window.impl.WatermarkImpl in project apex-malhar by apache.
the class WindowedOperatorTest method testWatermarkAndAllowedLateness.
@Test
public void testWatermarkAndAllowedLateness() {
WindowedOperatorImpl<Long, MutableLong, Long> windowedOperator = createDefaultWindowedOperator();
CollectorTestSink controlSink = new CollectorTestSink();
windowedOperator.controlOutput.setSink(controlSink);
windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.millis(1000)));
windowedOperator.setAllowedLateness(Duration.millis(1000));
windowedOperator.setup(testMeta.operatorContext);
windowedOperator.beginWindow(1);
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 100L, 2L));
Assert.assertEquals("There should be exactly one window in the storage", 1, plainDataStorage.size());
Assert.assertEquals("There should be exactly one window in the storage", 1, windowStateStorage.size());
Map.Entry<Window, WindowState> entry = windowStateStorage.entries().iterator().next();
Window window = entry.getKey();
WindowState windowState = entry.getValue();
Assert.assertEquals(-1, windowState.watermarkArrivalTime);
Assert.assertEquals(2L, plainDataStorage.get(window).longValue());
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 200L, 3L));
Assert.assertEquals(5L, plainDataStorage.get(window).longValue());
windowedOperator.processWatermark(new WatermarkImpl(BASE + 1200));
windowedOperator.endWindow();
Assert.assertTrue(windowState.watermarkArrivalTime >= 0);
Assert.assertEquals("We should get one watermark tuple", 1, controlSink.getCount(false));
windowedOperator.beginWindow(2);
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 900L, 4L));
Assert.assertEquals("Late but not too late", 9L, plainDataStorage.get(window).longValue());
windowedOperator.processWatermark(new WatermarkImpl(BASE + 3000));
windowedOperator.endWindow();
Assert.assertEquals("We should get two watermark tuples", 2, controlSink.getCount(false));
windowedOperator.beginWindow(3);
// this tuple should be dropped
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 120L, 5L));
Assert.assertEquals("The window should be dropped because it's too late", 0, plainDataStorage.size());
Assert.assertEquals("The window should be dropped because it's too late", 0, windowStateStorage.size());
windowedOperator.endWindow();
windowedOperator.teardown();
}
Aggregations