/** * Creates a trigger that continuously fires based on the given interval. * * @param interval The time interval at which to fire. * @param <W> The type of {@link Window Windows} on which this trigger can operate. */ public static <W extends Window> ContinuousEventTimeTrigger<W> of(Time interval) { return new ContinuousEventTimeTrigger<>(interval.toMilliseconds()); }
@Test public void testMergingWindows() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(ContinuousEventTimeTrigger.<TimeWindow>of(Time.hours(1)), new TimeWindow.Serializer()); assertTrue(ContinuousEventTimeTrigger.<TimeWindow>of(Time.hours(1)).canMerge());
/** * Verify that late elements trigger immediately and also that we don't set a timer * for those. */ @Test public void testLateElementTriggersImmediately() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(ContinuousEventTimeTrigger.<TimeWindow>of(Time.hours(1)), new TimeWindow.Serializer()); testHarness.advanceWatermark(2); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
/** * Verify that the trigger doesn't fail with an NPE if we insert a timer firing when there is * no trigger state. */ @Test public void testTriggerHandlesAllOnTimerCalls() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(ContinuousEventTimeTrigger.<TimeWindow>of(Time.milliseconds(5)), new TimeWindow.Serializer()); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); // this will make the elements we now process fall into late windows, i.e. no trigger state // will be created testHarness.advanceWatermark(10); // late fires immediately assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); // simulate a GC timer firing testHarness.invokeOnEventTime(20, new TimeWindow(0, 2)); }
/** * Creates a trigger that continuously fires based on the given interval. * * @param interval The time interval at which to fire. * @param <W> The type of {@link Window Windows} on which this trigger can operate. */ public static <W extends Window> ContinuousEventTimeTrigger<W> of(Time interval) { return new ContinuousEventTimeTrigger<>(interval.toMilliseconds()); }
stateDesc, new InternalIterableWindowFunction<>(new SessionWindowFunction()), ContinuousEventTimeTrigger.of(Time.seconds(2)), 0,
/** * Creates a trigger that continuously fires based on the given interval. * * @param interval The time interval at which to fire. * @param <W> The type of {@link Window Windows} on which this trigger can operate. */ public static <W extends Window> ContinuousEventTimeTrigger<W> of(Time interval) { return new ContinuousEventTimeTrigger<>(interval.toMilliseconds()); }
stateDesc, new InternalSingleValueWindowFunction<>(new PassThroughWindowFunction<String, GlobalWindow, Tuple2<String, Integer>>()), ContinuousEventTimeTrigger.of(Time.of(windowSize, TimeUnit.SECONDS)), 0,
/** * Creates a trigger that continuously fires based on the given interval. * * @param interval The time interval at which to fire. * @param <W> The type of {@link Window Windows} on which this trigger can operate. */ public static <W extends Window> ContinuousEventTimeTrigger<W> of(Time interval) { return new ContinuousEventTimeTrigger<>(interval.toMilliseconds()); }
/** * Verify that clear() does not leak across windows. */ @Test public void testClear() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(ContinuousEventTimeTrigger.<TimeWindow>of(Time.hours(1)), new TimeWindow.Serializer()); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); assertEquals(2, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(4, testHarness.numEventTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(2, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.clearTriggerState(new TimeWindow(2, 4)); assertEquals(1, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(3, testHarness.numEventTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.clearTriggerState(new TimeWindow(0, 2)); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); // doesn't clean up timers }
public void testWindowSeparationAndFiring() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(ContinuousEventTimeTrigger.<TimeWindow>of(Time.hours(1)), new TimeWindow.Serializer());