Search in sources :

Example 6 with EventTimeSessionWindows

use of org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows in project flink by apache.

the class EventTimeSessionWindowsTest method testTimeUnits.

@Test
public void testTimeUnits() {
    // sanity check with one other time unit
    final int sessionGap = 5000;
    WindowAssigner.WindowAssignerContext mockContext = mock(WindowAssigner.WindowAssignerContext.class);
    EventTimeSessionWindows assigner = EventTimeSessionWindows.withGap(Time.seconds(sessionGap / 1000));
    assertThat(assigner.assignWindows("String", 0L, mockContext), contains(timeWindow(0, 0 + sessionGap)));
    assertThat(assigner.assignWindows("String", 4999L, mockContext), contains(timeWindow(4999, 4999 + sessionGap)));
    assertThat(assigner.assignWindows("String", 5000L, mockContext), contains(timeWindow(5000, 5000 + sessionGap)));
}
Also used : WindowAssigner(org.apache.flink.streaming.api.windowing.assigners.WindowAssigner) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) EventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows) DynamicEventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicEventTimeSessionWindows) Test(org.junit.Test)

Example 7 with EventTimeSessionWindows

use of org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows 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());
}
Also used : EventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows) DynamicEventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicEventTimeSessionWindows) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) Test(org.junit.Test)

Example 8 with EventTimeSessionWindows

use of org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows in project flink by apache.

the class EventTimeSessionWindowsTest method testProperties.

@Test
public void testProperties() {
    EventTimeSessionWindows assigner = EventTimeSessionWindows.withGap(Time.seconds(5));
    assertTrue(assigner.isEventTime());
    assertEquals(new TimeWindow.Serializer(), assigner.getWindowSerializer(new ExecutionConfig()));
    assertThat(assigner.getDefaultTrigger(mock(StreamExecutionEnvironment.class)), instanceOf(EventTimeTrigger.class));
}
Also used : ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) EventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows) DynamicEventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicEventTimeSessionWindows) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) EventTimeTrigger(org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger) Test(org.junit.Test)

Example 9 with EventTimeSessionWindows

use of org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows 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());
}
Also used : EventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows) DynamicEventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicEventTimeSessionWindows) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) Test(org.junit.Test)

Aggregations

EventTimeSessionWindows (org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows)9 Test (org.junit.Test)9 DynamicEventTimeSessionWindows (org.apache.flink.streaming.api.windowing.assigners.DynamicEventTimeSessionWindows)7 MergingWindowAssigner (org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner)6 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)5 EventTimeTrigger (org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger)3 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)2 WindowAssigner (org.apache.flink.streaming.api.windowing.assigners.WindowAssigner)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 KeySelector (org.apache.flink.api.java.functions.KeySelector)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)1