use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class ContinuousEventTimeTriggerTest method testMergingWindows.
@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());
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.mergeWindows(new TimeWindow(0, 4), Lists.newArrayList(new TimeWindow(0, 2), new TimeWindow(2, 4)));
assertEquals(1, testHarness.numStateEntries());
assertEquals(0, testHarness.numProcessingTimeTimers());
// on merging, timers are not cleaned up
assertEquals(5, testHarness.numEventTimeTimers());
assertEquals(2, testHarness.numEventTimeTimers(new TimeWindow(0, 2)));
assertEquals(2, testHarness.numEventTimeTimers(new TimeWindow(2, 4)));
assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 4)));
Collection<Tuple2<TimeWindow, TriggerResult>> triggerResults = testHarness.advanceWatermark(4);
boolean sawFiring = false;
for (Tuple2<TimeWindow, TriggerResult> r : triggerResults) {
if (r.f0.equals(new TimeWindow(0, 4))) {
sawFiring = true;
assertTrue(r.f1.equals(TriggerResult.FIRE));
}
}
assertTrue(sawFiring);
assertEquals(1, testHarness.numStateEntries());
assertEquals(0, testHarness.numProcessingTimeTimers());
assertEquals(1, testHarness.numEventTimeTimers());
}
use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class InternalWindowFunctionTest method testInternalSingleValueWindowFunction.
@SuppressWarnings("unchecked")
@Test
public void testInternalSingleValueWindowFunction() throws Exception {
WindowFunctionMock mock = mock(WindowFunctionMock.class);
InternalSingleValueWindowFunction<Long, String, Long, TimeWindow> windowFunction = new InternalSingleValueWindowFunction<>(mock);
// check setOutputType
TypeInformation<String> stringType = BasicTypeInfo.STRING_TYPE_INFO;
ExecutionConfig execConf = new ExecutionConfig();
execConf.setParallelism(42);
StreamingFunctionUtils.setOutputType(windowFunction, stringType, execConf);
verify(mock).setOutputType(stringType, execConf);
// check open
Configuration config = new Configuration();
windowFunction.open(config);
verify(mock).open(config);
// check setRuntimeContext
RuntimeContext rCtx = mock(RuntimeContext.class);
windowFunction.setRuntimeContext(rCtx);
verify(mock).setRuntimeContext(rCtx);
// check apply
TimeWindow w = mock(TimeWindow.class);
Collector<String> c = (Collector<String>) mock(Collector.class);
windowFunction.apply(42L, w, 23L, c);
verify(mock).apply(eq(42L), eq(w), (Iterable<Long>) argThat(IsIterableContainingInOrder.contains(23L)), eq(c));
// check close
windowFunction.close();
verify(mock).close();
}
use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class CountTriggerTest method testMergeSubsumingWindow.
@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());
}
use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class EventTimeSessionWindowsTest method testMergeCoveringWindow.
@Test
public void testMergeCoveringWindow() {
MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
EventTimeSessionWindows assigner = EventTimeSessionWindows.withGap(Time.milliseconds(5000));
assigner.mergeWindows(Lists.newArrayList(new TimeWindow(1, 1), new TimeWindow(0, 2), new TimeWindow(4, 7), new TimeWindow(5, 6)), callback);
verify(callback, times(1)).merge((Collection<TimeWindow>) argThat(containsInAnyOrder(new TimeWindow(1, 1), new TimeWindow(0, 2))), eq(new TimeWindow(0, 2)));
verify(callback, times(1)).merge((Collection<TimeWindow>) argThat(containsInAnyOrder(new TimeWindow(5, 6), new TimeWindow(4, 7))), eq(new TimeWindow(4, 7)));
verify(callback, times(2)).merge(anyCollection(), Matchers.anyObject());
}
use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class EventTimeSessionWindowsTest method testMergeConsecutiveWindows.
@Test
public void testMergeConsecutiveWindows() {
MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
EventTimeSessionWindows assigner = EventTimeSessionWindows.withGap(Time.milliseconds(5000));
assigner.mergeWindows(Lists.newArrayList(new TimeWindow(0, 1), new TimeWindow(1, 2), new TimeWindow(2, 3), new TimeWindow(4, 5), new TimeWindow(5, 6)), callback);
verify(callback, times(1)).merge((Collection<TimeWindow>) argThat(containsInAnyOrder(new TimeWindow(0, 1), new TimeWindow(1, 2), new TimeWindow(2, 3))), eq(new TimeWindow(0, 3)));
verify(callback, times(1)).merge((Collection<TimeWindow>) argThat(containsInAnyOrder(new TimeWindow(4, 5), new TimeWindow(5, 6))), eq(new TimeWindow(4, 6)));
verify(callback, times(2)).merge(anyCollection(), Matchers.anyObject());
}
Aggregations