Search in sources :

Example 1 with DynamicProcessingTimeSessionWindows

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

the class DynamicProcessingTimeSessionWindowsTest method testProperties.

@Test
public void testProperties() {
    SessionWindowTimeGapExtractor extractor = mock(SessionWindowTimeGapExtractor.class);
    when(extractor.extract(any())).thenReturn(5000L);
    DynamicProcessingTimeSessionWindows assigner = DynamicProcessingTimeSessionWindows.withDynamicGap(extractor);
    assertFalse(assigner.isEventTime());
    assertEquals(new TimeWindow.Serializer(), assigner.getWindowSerializer(new ExecutionConfig()));
    assertThat(assigner.getDefaultTrigger(mock(StreamExecutionEnvironment.class)), instanceOf(ProcessingTimeTrigger.class));
}
Also used : DynamicProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicProcessingTimeSessionWindows) 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) SessionWindowTimeGapExtractor(org.apache.flink.streaming.api.windowing.assigners.SessionWindowTimeGapExtractor) Test(org.junit.Test)

Example 2 with DynamicProcessingTimeSessionWindows

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

the class DynamicProcessingTimeSessionWindowsTest method testMergeSinglePointWindow.

@Test
public void testMergeSinglePointWindow() {
    MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
    SessionWindowTimeGapExtractor extractor = mock(SessionWindowTimeGapExtractor.class);
    when(extractor.extract(any())).thenReturn(5000L);
    DynamicProcessingTimeSessionWindows assigner = DynamicProcessingTimeSessionWindows.withDynamicGap(extractor);
    assigner.mergeWindows(Lists.newArrayList(new TimeWindow(0, 0)), callback);
    verify(callback, never()).merge(anyCollection(), Matchers.anyObject());
}
Also used : DynamicProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicProcessingTimeSessionWindows) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) SessionWindowTimeGapExtractor(org.apache.flink.streaming.api.windowing.assigners.SessionWindowTimeGapExtractor) Test(org.junit.Test)

Example 3 with DynamicProcessingTimeSessionWindows

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

the class DynamicProcessingTimeSessionWindowsTest method testInvalidParameters.

@Test
public void testInvalidParameters() {
    WindowAssigner.WindowAssignerContext mockContext = mock(WindowAssigner.WindowAssignerContext.class);
    try {
        SessionWindowTimeGapExtractor extractor = mock(SessionWindowTimeGapExtractor.class);
        when(extractor.extract(any())).thenReturn(-1L);
        DynamicProcessingTimeSessionWindows assigner = DynamicProcessingTimeSessionWindows.withDynamicGap(extractor);
        assigner.assignWindows(Lists.newArrayList(new Object()), 1, mockContext);
        fail("should fail");
    } catch (IllegalArgumentException e) {
        assertThat(e.toString(), containsString("0 < gap"));
    }
    try {
        SessionWindowTimeGapExtractor extractor = mock(SessionWindowTimeGapExtractor.class);
        when(extractor.extract(any())).thenReturn(-1L);
        DynamicProcessingTimeSessionWindows assigner = DynamicProcessingTimeSessionWindows.withDynamicGap(extractor);
        assigner.assignWindows(Lists.newArrayList(new Object()), 1, mockContext);
        fail("should fail");
    } catch (IllegalArgumentException e) {
        assertThat(e.toString(), containsString("0 < gap"));
    }
}
Also used : WindowAssigner(org.apache.flink.streaming.api.windowing.assigners.WindowAssigner) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) DynamicProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicProcessingTimeSessionWindows) SessionWindowTimeGapExtractor(org.apache.flink.streaming.api.windowing.assigners.SessionWindowTimeGapExtractor) Test(org.junit.Test)

Example 4 with DynamicProcessingTimeSessionWindows

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

the class DynamicProcessingTimeSessionWindowsTest method testMergeCoveringWindow.

@Test
public void testMergeCoveringWindow() {
    MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
    SessionWindowTimeGapExtractor extractor = mock(SessionWindowTimeGapExtractor.class);
    when(extractor.extract(any())).thenReturn(5000L);
    DynamicProcessingTimeSessionWindows assigner = DynamicProcessingTimeSessionWindows.withDynamicGap(extractor);
    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 : DynamicProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicProcessingTimeSessionWindows) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) SessionWindowTimeGapExtractor(org.apache.flink.streaming.api.windowing.assigners.SessionWindowTimeGapExtractor) Test(org.junit.Test)

Example 5 with DynamicProcessingTimeSessionWindows

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

the class DynamicProcessingTimeSessionWindowsTest method testMergeSingleWindow.

@Test
public void testMergeSingleWindow() {
    MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
    SessionWindowTimeGapExtractor extractor = mock(SessionWindowTimeGapExtractor.class);
    when(extractor.extract(any())).thenReturn(5000L);
    DynamicProcessingTimeSessionWindows assigner = DynamicProcessingTimeSessionWindows.withDynamicGap(extractor);
    assigner.mergeWindows(Lists.newArrayList(new TimeWindow(0, 1)), callback);
    verify(callback, never()).merge(anyCollection(), Matchers.anyObject());
}
Also used : DynamicProcessingTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.DynamicProcessingTimeSessionWindows) MergingWindowAssigner(org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner) TimeWindow(org.apache.flink.streaming.api.windowing.windows.TimeWindow) SessionWindowTimeGapExtractor(org.apache.flink.streaming.api.windowing.assigners.SessionWindowTimeGapExtractor) Test(org.junit.Test)

Aggregations

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