org.apache.flink.streaming.api.windowing.triggers.TriggerResult Java Examples
The following examples show how to use
org.apache.flink.streaming.api.windowing.triggers.TriggerResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TriggerTestHarness.java From flink with Apache License 2.0 | 6 votes |
/** * Advanced the watermark and checks whether we have exactly one firing for the given * window. The result of {@link Trigger#onEventTime(long, Window, Trigger.TriggerContext)} * is returned for that firing. */ public TriggerResult advanceWatermark(long time, W window) throws Exception { Collection<Tuple2<W, TriggerResult>> firings = advanceWatermark(time); if (firings.size() != 1) { throw new IllegalStateException("Must have exactly one timer firing. Fired timers: " + firings); } Tuple2<W, TriggerResult> firing = firings.iterator().next(); if (!firing.f0.equals(window)) { throw new IllegalStateException("Trigger fired for another window."); } return firing.f1; }
Example #2
Source File: TriggerTestHarness.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Advanced the watermark and checks whether we have exactly one firing for the given * window. The result of {@link Trigger#onEventTime(long, Window, Trigger.TriggerContext)} * is returned for that firing. */ public TriggerResult advanceWatermark(long time, W window) throws Exception { Collection<Tuple2<W, TriggerResult>> firings = advanceWatermark(time); if (firings.size() != 1) { throw new IllegalStateException("Must have exactly one timer firing. Fired timers: " + firings); } Tuple2<W, TriggerResult> firing = firings.iterator().next(); if (!firing.f0.equals(window)) { throw new IllegalStateException("Trigger fired for another window."); } return firing.f1; }
Example #3
Source File: CustomTrigger.java From flink-learning with Apache License 2.0 | 6 votes |
@Override public TriggerResult onElement(WordEvent element, long timestamp, TimeWindow window, TriggerContext ctx) throws Exception { log.info("======onElement====window start = {}, window end = {}", window.getStart(), window.getEnd()); return TriggerResult.CONTINUE; // ReducingState<Long> fireTimestamp = ctx.getPartitionedState(stateDesc); // // timestamp = ctx.getCurrentProcessingTime(); // // if (fireTimestamp.get() == null) { // long start = timestamp - (timestamp % interval); // long nextFireTimestamp = start + interval; // // ctx.registerProcessingTimeTimer(nextFireTimestamp); // // fireTimestamp.add(nextFireTimestamp); // return TriggerResult.CONTINUE; // } // return TriggerResult.CONTINUE; }
Example #4
Source File: TriggerTestHarness.java From flink with Apache License 2.0 | 5 votes |
/** * Manually invoke {@link Trigger#onEventTime(long, Window, Trigger.TriggerContext)} with * the given parameters. */ public TriggerResult invokeOnEventTime(long timestamp, W window) throws Exception { TestInternalTimerService.Timer<Integer, W> timer = new TestInternalTimerService.Timer<>(timestamp, KEY, window); return invokeOnEventTime(timer); }
Example #5
Source File: WindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
static <T> void shouldRegisterEventTimeTimerOnElement(Trigger<T, TimeWindow> mockTrigger, final long timestamp) throws Exception { doAnswer(new Answer<TriggerResult>() { @Override public TriggerResult answer(InvocationOnMock invocation) throws Exception { @SuppressWarnings("unchecked") Trigger.TriggerContext context = (Trigger.TriggerContext) invocation.getArguments()[3]; context.registerEventTimeTimer(timestamp); return TriggerResult.CONTINUE; } }) .when(mockTrigger).onElement(Matchers.<T>anyObject(), anyLong(), anyTimeWindow(), anyTriggerContext()); }
Example #6
Source File: CountTriggerTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testMergingWindows() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(CountTrigger.<TimeWindow>of(3), 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(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(4, 6))); // shouldn't have any timers assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(3, testHarness.numStateEntries()); assertEquals(1, testHarness.numStateEntries(new TimeWindow(0, 2))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(4, 6))); testHarness.mergeWindows(new TimeWindow(0, 4), Lists.newArrayList(new TimeWindow(0, 2), new TimeWindow(2, 4))); assertEquals(2, testHarness.numStateEntries()); assertEquals(0, testHarness.numStateEntries(new TimeWindow(0, 2))); assertEquals(0, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(0, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(4, 6))); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 4))); assertEquals(1, testHarness.numStateEntries()); assertEquals(0, testHarness.numStateEntries(new TimeWindow(0, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(4, 6))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(4, 6))); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(4, 6))); assertEquals(0, testHarness.numStateEntries()); }
Example #7
Source File: TriggerTestHarness.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private TriggerResult invokeOnEventTime(TestInternalTimerService.Timer<Integer, W> timer) throws Exception { TestTriggerContext<Integer, W> triggerContext = new TestTriggerContext<>( KEY, timer.getNamespace(), internalTimerService, stateBackend, windowSerializer); return trigger.onEventTime(timer.getTimestamp(), timer.getNamespace(), triggerContext); }
Example #8
Source File: TriggerTestHarness.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Manually invoke {@link Trigger#onEventTime(long, Window, Trigger.TriggerContext)} with * the given parameters. */ public TriggerResult invokeOnEventTime(long timestamp, W window) throws Exception { TestInternalTimerService.Timer<Integer, W> timer = new TestInternalTimerService.Timer<>(timestamp, KEY, window); return invokeOnEventTime(timer); }
Example #9
Source File: EventTimeTriggerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Merging a late window should not register a timer, otherwise we would get two firings: * one from onElement() on the merged window and one from the timer. */ @Test public void testMergingLateWindows() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); assertTrue(EventTimeTrigger.create().canMerge()); 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(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.advanceWatermark(10); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.mergeWindows(new TimeWindow(0, 4), Lists.newArrayList(new TimeWindow(0, 2), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 4))); }
Example #10
Source File: WindowOperatorContractTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static <T> void shouldRegisterProcessingTimeTimerOnElement(Trigger<T, TimeWindow> mockTrigger, final long timestamp) throws Exception { doAnswer(new Answer<TriggerResult>() { @Override public TriggerResult answer(InvocationOnMock invocation) throws Exception { @SuppressWarnings("unchecked") Trigger.TriggerContext context = (Trigger.TriggerContext) invocation.getArguments()[3]; context.registerProcessingTimeTimer(timestamp); return TriggerResult.CONTINUE; } }) .when(mockTrigger).onElement(Matchers.<T>anyObject(), anyLong(), anyTimeWindow(), anyTriggerContext()); }
Example #11
Source File: WindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
static <T> void shouldRegisterEventTimeTimerOnElement(Trigger<T, TimeWindow> mockTrigger, final long timestamp) throws Exception { doAnswer(new Answer<TriggerResult>() { @Override public TriggerResult answer(InvocationOnMock invocation) throws Exception { @SuppressWarnings("unchecked") Trigger.TriggerContext context = (Trigger.TriggerContext) invocation.getArguments()[3]; context.registerEventTimeTimer(timestamp); return TriggerResult.CONTINUE; } }) .when(mockTrigger).onElement(Matchers.<T>anyObject(), anyLong(), anyTimeWindow(), anyTriggerContext()); }
Example #12
Source File: CountTriggerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testMergeSubsumingWindow() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(CountTrigger.<TimeWindow>of(3), new TimeWindow.Serializer()); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(4, 6))); // shouldn't have any timers assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(2, testHarness.numStateEntries()); assertEquals(1, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(4, 6))); testHarness.mergeWindows(new TimeWindow(0, 8), Lists.newArrayList(new TimeWindow(2, 4), new TimeWindow(4, 6))); assertEquals(1, testHarness.numStateEntries()); assertEquals(0, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries(new TimeWindow(4, 6))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(0, 8))); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 8))); assertEquals(0, testHarness.numStateEntries()); }
Example #13
Source File: TriggerTestHarness.java From flink with Apache License 2.0 | 5 votes |
/** * Injects one element into the trigger for the given window and returns the result of * {@link Trigger#onElement(Object, long, Window, Trigger.TriggerContext)}. */ public TriggerResult processElement(StreamRecord<T> element, W window) throws Exception { TestTriggerContext<Integer, W> triggerContext = new TestTriggerContext<>( KEY, window, internalTimerService, stateBackend, windowSerializer); return trigger.onElement(element.getValue(), element.getTimestamp(), window, triggerContext); }
Example #14
Source File: CountTriggerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testMergingWindows() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(CountTrigger.<TimeWindow>of(3), 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(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(4, 6))); // shouldn't have any timers assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(3, testHarness.numStateEntries()); assertEquals(1, testHarness.numStateEntries(new TimeWindow(0, 2))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(4, 6))); testHarness.mergeWindows(new TimeWindow(0, 4), Lists.newArrayList(new TimeWindow(0, 2), new TimeWindow(2, 4))); assertEquals(2, testHarness.numStateEntries()); assertEquals(0, testHarness.numStateEntries(new TimeWindow(0, 2))); assertEquals(0, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(0, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(4, 6))); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 4))); assertEquals(1, testHarness.numStateEntries()); assertEquals(0, testHarness.numStateEntries(new TimeWindow(0, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(4, 6))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(4, 6))); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(4, 6))); assertEquals(0, testHarness.numStateEntries()); }
Example #15
Source File: EventTimeTriggerTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testMergingWindows() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); assertTrue(EventTimeTrigger.create().canMerge()); 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(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.mergeWindows(new TimeWindow(0, 4), Lists.newArrayList(new TimeWindow(0, 2), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(4, new TimeWindow(0, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
Example #16
Source File: EventTimeTriggerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Merging a late window should not register a timer, otherwise we would get two firings: * one from onElement() on the merged window and one from the timer. */ @Test public void testMergingLateWindows() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); assertTrue(EventTimeTrigger.create().canMerge()); 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(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.advanceWatermark(10); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.mergeWindows(new TimeWindow(0, 4), Lists.newArrayList(new TimeWindow(0, 2), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 4))); }
Example #17
Source File: DrivingSegments.java From flink-training-exercises with Apache License 2.0 | 5 votes |
@Override public TriggerResult onElement(ConnectedCarEvent event, long timestamp, GlobalWindow window, TriggerContext context) throws Exception { // if this is a stop event, set a timer if (event.speed == 0.0) { context.registerEventTimeTimer(event.timestamp); } return TriggerResult.CONTINUE; }
Example #18
Source File: TriggerTestHarness.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Injects one element into the trigger for the given window and returns the result of * {@link Trigger#onElement(Object, long, Window, Trigger.TriggerContext)}. */ public TriggerResult processElement(StreamRecord<T> element, W window) throws Exception { TestTriggerContext<Integer, W> triggerContext = new TestTriggerContext<>( KEY, window, internalTimerService, stateBackend, windowSerializer); return trigger.onElement(element.getValue(), element.getTimestamp(), window, triggerContext); }
Example #19
Source File: WindowOperatorContractTest.java From flink with Apache License 2.0 | 5 votes |
private static <T> void shouldDeleteProcessingTimeTimerOnElement(Trigger<T, TimeWindow> mockTrigger, final long timestamp) throws Exception { doAnswer(new Answer<TriggerResult>() { @Override public TriggerResult answer(InvocationOnMock invocation) throws Exception { @SuppressWarnings("unchecked") Trigger.TriggerContext context = (Trigger.TriggerContext) invocation.getArguments()[3]; context.deleteProcessingTimeTimer(timestamp); return TriggerResult.CONTINUE; } }) .when(mockTrigger).onElement(Matchers.<T>anyObject(), anyLong(), anyTimeWindow(), anyTriggerContext()); }
Example #20
Source File: EventTimeTriggerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testMergingWindows() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); assertTrue(EventTimeTrigger.create().canMerge()); 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(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.mergeWindows(new TimeWindow(0, 4), Lists.newArrayList(new TimeWindow(0, 2), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(4, new TimeWindow(0, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
Example #21
Source File: EventTimeTriggerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verify that clear() does not leak across windows. */ @Test public void testClear() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), 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(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.clearTriggerState(new TimeWindow(2, 4)); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.clearTriggerState(new TimeWindow(0, 2)); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
Example #22
Source File: EventTimeTriggerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Verify that state of separate windows does not leak into other windows. */ @Test public void testWindowSeparationAndFiring() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); // inject several elements assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); 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(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(2, new TimeWindow(0, 2))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(4, new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
Example #23
Source File: EventTimeTriggerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verify that state of separate windows does not leak into other windows. */ @Test public void testWindowSeparationAndFiring() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); // inject several elements assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); 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(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(2, new TimeWindow(0, 2))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(4, new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
Example #24
Source File: WindowOperatorContractTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testOnElementPurgeDoesNotCleanupMergingSet() throws Exception { MergingWindowAssigner<Integer, TimeWindow> mockAssigner = mockMergingAssigner(); Trigger<Integer, TimeWindow> mockTrigger = mockTrigger(); InternalWindowFunction<Iterable<Integer>, Void, Integer, TimeWindow> mockWindowFunction = mockWindowFunction(); KeyedOneInputStreamOperatorTestHarness<Integer, Integer, Void> testHarness = createWindowOperator(mockAssigner, mockTrigger, 0L, mockWindowFunction); testHarness.open(); when(mockAssigner.assignWindows(anyInt(), anyLong(), anyAssignerContext())) .thenReturn(Arrays.asList(new TimeWindow(0, 2))); assertEquals(0, testHarness.getOutput().size()); assertEquals(0, testHarness.numKeyedStateEntries()); doAnswer(new Answer<TriggerResult>() { @Override public TriggerResult answer(InvocationOnMock invocation) throws Exception { return TriggerResult.PURGE; } }).when(mockTrigger).onElement(Matchers.<Integer>anyObject(), anyLong(), anyTimeWindow(), anyTriggerContext()); testHarness.processElement(new StreamRecord<>(0, 0L)); assertEquals(1, testHarness.numKeyedStateEntries()); // the merging window set assertEquals(1, testHarness.numEventTimeTimers()); // one cleanup timer assertEquals(0, testHarness.getOutput().size()); }
Example #25
Source File: EventTimeTriggerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verify that state of separate windows does not leak into other windows. */ @Test public void testWindowSeparationAndFiring() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); // inject several elements assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); 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(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(2, new TimeWindow(0, 2))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(4, new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
Example #26
Source File: CountTriggerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verify that state of separate windows does not leak into other windows. */ @Test public void testWindowSeparationAndFiring() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(CountTrigger.<TimeWindow>of(3), 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))); // shouldn't have any timers assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(2, testHarness.numStateEntries()); assertEquals(1, testHarness.numStateEntries(new TimeWindow(0, 2))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); // right now, CountTrigger will clear it's state in onElement when firing // ideally, this should be moved to onFire() assertEquals(1, testHarness.numStateEntries()); assertEquals(0, testHarness.numStateEntries(new TimeWindow(0, 2))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); // now all state should be gone assertEquals(0, testHarness.numStateEntries()); }
Example #27
Source File: EventTimeTriggerTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testMergingWindows() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); assertTrue(EventTimeTrigger.create().canMerge()); 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(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(2, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); testHarness.mergeWindows(new TimeWindow(0, 4), Lists.newArrayList(new TimeWindow(0, 2), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(1, testHarness.numEventTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(4, new TimeWindow(0, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
Example #28
Source File: WindowOperatorTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public TriggerResult onElement(Object element, long timestamp, TimeWindow window, TriggerContext ctx) throws Exception { if (window.maxTimestamp() <= ctx.getCurrentWatermark()) { // if the watermark is already past the window fire immediately return TriggerResult.FIRE; } else { ctx.registerEventTimeTimer(window.maxTimestamp()); return TriggerResult.CONTINUE; } }
Example #29
Source File: ProcessingTimeTriggerTest.java From flink with Apache License 2.0 | 5 votes |
/** * Verify that state of separate windows does not leak into other windows. */ @Test public void testWindowSeparationAndFiring() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(ProcessingTimeTrigger.create(), new TimeWindow.Serializer()); // inject several elements assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 2))); 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(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(2, testHarness.numProcessingTimeTimers()); assertEquals(1, testHarness.numProcessingTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numProcessingTimeTimers(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceProcessingTime(2, new TimeWindow(0, 2))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(1, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numProcessingTimeTimers(new TimeWindow(0, 2))); assertEquals(1, testHarness.numProcessingTimeTimers(new TimeWindow(2, 4))); assertEquals(TriggerResult.FIRE, testHarness.advanceProcessingTime(4, new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries()); assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); }
Example #30
Source File: CountTriggerTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testMergeSubsumingWindow() throws Exception { TriggerTestHarness<Object, TimeWindow> testHarness = new TriggerTestHarness<>(CountTrigger.<TimeWindow>of(3), new TimeWindow.Serializer()); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(2, 4))); assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(4, 6))); // shouldn't have any timers assertEquals(0, testHarness.numProcessingTimeTimers()); assertEquals(0, testHarness.numEventTimeTimers()); assertEquals(2, testHarness.numStateEntries()); assertEquals(1, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(4, 6))); testHarness.mergeWindows(new TimeWindow(0, 8), Lists.newArrayList(new TimeWindow(2, 4), new TimeWindow(4, 6))); assertEquals(1, testHarness.numStateEntries()); assertEquals(0, testHarness.numStateEntries(new TimeWindow(2, 4))); assertEquals(0, testHarness.numStateEntries(new TimeWindow(4, 6))); assertEquals(1, testHarness.numStateEntries(new TimeWindow(0, 8))); assertEquals(TriggerResult.FIRE, testHarness.processElement(new StreamRecord<Object>(1), new TimeWindow(0, 8))); assertEquals(0, testHarness.numStateEntries()); }