Search in sources :

Example 1 with FixedDiffEventTimeWatermarkGen

use of org.apache.apex.malhar.lib.window.impl.FixedDiffEventTimeWatermarkGen in project apex-malhar by apache.

the class WindowedOperatorTest method testImplicitWatermarks.

@Test
public void testImplicitWatermarks() {
    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.setImplicitWatermarkGenerator(new FixedDiffEventTimeWatermarkGen(100));
    windowedOperator.setup(testMeta.operatorContext);
    windowedOperator.beginWindow(1);
    windowedOperator.endWindow();
    Assert.assertEquals("We should get no watermark tuple", 0, controlSink.getCount(false));
    windowedOperator.beginWindow(2);
    windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 100L, 2L));
    windowedOperator.endWindow();
    Assert.assertEquals("We should get one watermark tuple", 1, controlSink.getCount(false));
    Assert.assertEquals("Check Watermark value", ((ControlTuple.Watermark) controlSink.collectedTuples.get(0)).getTimestamp(), BASE);
    windowedOperator.beginWindow(3);
    windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 900L, 4L));
    windowedOperator.endWindow();
    Assert.assertEquals("We should get two watermark tuples", 2, controlSink.getCount(false));
    Assert.assertEquals("Check Watermark value", ((ControlTuple.Watermark) controlSink.collectedTuples.get(1)).getTimestamp(), BASE + 800);
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableLong(org.apache.commons.lang3.mutable.MutableLong) FixedDiffEventTimeWatermarkGen(org.apache.apex.malhar.lib.window.impl.FixedDiffEventTimeWatermarkGen) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Aggregations

CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)1 FixedDiffEventTimeWatermarkGen (org.apache.apex.malhar.lib.window.impl.FixedDiffEventTimeWatermarkGen)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 Test (org.junit.Test)1