Search in sources :

Example 1 with ProcessingTimeSessionWindows

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

the class ProcessingTimeSessionWindowsTest method testProperties.

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

Example 2 with ProcessingTimeSessionWindows

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

the class ProcessingTimeSessionWindowsTest method testWindowAssignment.

@Test
public void testWindowAssignment() {
    WindowAssigner.WindowAssignerContext mockContext = mock(WindowAssigner.WindowAssignerContext.class);
    ProcessingTimeSessionWindows assigner = ProcessingTimeSessionWindows.withGap(Time.milliseconds(5000));
    when(mockContext.getCurrentProcessingTime()).thenReturn(0L);
    assertThat(assigner.assignWindows("String", Long.MIN_VALUE, mockContext), contains(timeWindow(0, 5000)));
    when(mockContext.getCurrentProcessingTime()).thenReturn(4999L);
    assertThat(assigner.assignWindows("String", Long.MIN_VALUE, mockContext), contains(timeWindow(4999, 9999)));
    when(mockContext.getCurrentProcessingTime()).thenReturn(5000L);
    assertThat(assigner.assignWindows("String", Long.MIN_VALUE, mockContext), contains(timeWindow(5000, 10000)));
}
Also used : MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) WindowAssigner(org.apache.flink.streaming.api.windowing.assigners.WindowAssigner) ProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.ProcessingTimeSessionWindows) Test(org.junit.Test)

Example 3 with ProcessingTimeSessionWindows

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

the class ProcessingTimeSessionWindowsTest method testTimeUnits.

@Test
public void testTimeUnits() {
    // sanity check with one other time unit
    WindowAssigner.WindowAssignerContext mockContext = mock(WindowAssigner.WindowAssignerContext.class);
    ProcessingTimeSessionWindows assigner = ProcessingTimeSessionWindows.withGap(Time.seconds(5));
    when(mockContext.getCurrentProcessingTime()).thenReturn(0L);
    assertThat(assigner.assignWindows("String", Long.MIN_VALUE, mockContext), contains(timeWindow(0, 5000)));
    when(mockContext.getCurrentProcessingTime()).thenReturn(4999L);
    assertThat(assigner.assignWindows("String", Long.MIN_VALUE, mockContext), contains(timeWindow(4999, 9999)));
    when(mockContext.getCurrentProcessingTime()).thenReturn(5000L);
    assertThat(assigner.assignWindows("String", Long.MIN_VALUE, mockContext), contains(timeWindow(5000, 10000)));
}
Also used : MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) WindowAssigner(org.apache.flink.streaming.api.windowing.assigners.WindowAssigner) ProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.ProcessingTimeSessionWindows) Test(org.junit.Test)

Example 4 with ProcessingTimeSessionWindows

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

the class ProcessingTimeSessionWindowsTest method testMergeSinglePointWindow.

@Test
public void testMergeSinglePointWindow() {
    MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
    ProcessingTimeSessionWindows assigner = ProcessingTimeSessionWindows.withGap(Time.milliseconds(5000));
    assigner.mergeWindows(Lists.newArrayList(new TimeWindow(0, 0)), callback);
    verify(callback, never()).merge(anyCollection(), Matchers.anyObject());
}
Also used : ProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.ProcessingTimeSessionWindows) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) Test(org.junit.Test)

Example 5 with ProcessingTimeSessionWindows

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

the class ProcessingTimeSessionWindowsTest method testMergeConsecutiveWindows.

@Test
public void testMergeConsecutiveWindows() {
    MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
    ProcessingTimeSessionWindows assigner = ProcessingTimeSessionWindows.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 : ProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.ProcessingTimeSessionWindows) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) Test(org.junit.Test)

Aggregations

ProcessingTimeSessionWindows (org.apache.flink.streaming.api.windowing.assigners.ProcessingTimeSessionWindows)7 Test (org.junit.Test)7 MergingWindowAssigner (org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner)6 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)5 WindowAssigner (org.apache.flink.streaming.api.windowing.assigners.WindowAssigner)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 ProcessingTimeTrigger (org.apache.flink.streaming.api.windowing.triggers.ProcessingTimeTrigger)1