Search in sources :

Example 1 with EventTimeSessionWindows

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

the class AllWindowTranslationTest method testMergingWindowsWithEvictor.

@Test
@SuppressWarnings("rawtypes")
public void testMergingWindowsWithEvictor() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<Tuple2<String, Integer>> source = env.fromElements(Tuple2.of("hello", 1), Tuple2.of("hello", 2));
    DataStream<Tuple3<String, String, Integer>> window1 = source.windowAll(EventTimeSessionWindows.withGap(Time.seconds(5))).evictor(CountEvictor.of(5)).process(new TestProcessAllWindowFunction());
    OneInputTransformation<Tuple2<String, Integer>, Tuple3<String, String, Integer>> transform = (OneInputTransformation<Tuple2<String, Integer>, Tuple3<String, String, Integer>>) window1.getTransformation();
    OneInputStreamOperator<Tuple2<String, Integer>, Tuple3<String, String, Integer>> operator = transform.getOperator();
    Assert.assertTrue(operator instanceof WindowOperator);
    WindowOperator<String, Tuple2<String, Integer>, ?, ?, ?> winOperator = (WindowOperator<String, Tuple2<String, Integer>, ?, ?, ?>) operator;
    Assert.assertTrue(winOperator.getTrigger() instanceof EventTimeTrigger);
    Assert.assertTrue(winOperator.getWindowAssigner() instanceof EventTimeSessionWindows);
    Assert.assertTrue(winOperator.getStateDescriptor() instanceof ListStateDescriptor);
    processElementAndEnsureOutput(winOperator, winOperator.getKeySelector(), BasicTypeInfo.STRING_TYPE_INFO, new Tuple2<>("hello", 1));
}
Also used : ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Tuple3(org.apache.flink.api.java.tuple.Tuple3) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) EventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) EventTimeTrigger(org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger) Test(org.junit.Test)

Example 2 with EventTimeSessionWindows

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

the class EventTimeSessionWindowsTest method testWindowAssignment.

@Test
public void testWindowAssignment() {
    final int sessionGap = 5000;
    WindowAssigner.WindowAssignerContext mockContext = mock(WindowAssigner.WindowAssignerContext.class);
    EventTimeSessionWindows assigner = EventTimeSessionWindows.withGap(Time.milliseconds(sessionGap));
    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 3 with EventTimeSessionWindows

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

the class EventTimeSessionWindowsTest method testMergeSingleWindow.

@Test
public void testMergeSingleWindow() {
    MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
    EventTimeSessionWindows assigner = EventTimeSessionWindows.withGap(Time.milliseconds(5000));
    assigner.mergeWindows(Lists.newArrayList(new TimeWindow(0, 1)), callback);
    verify(callback, never()).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 4 with EventTimeSessionWindows

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

the class WindowTranslationTest method testMergingWindowsWithEvictor.

@Test
@SuppressWarnings("rawtypes")
public void testMergingWindowsWithEvictor() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<Integer> source = env.fromElements(1, 2);
    DataStream<String> window1 = source.keyBy(new KeySelector<Integer, String>() {

        @Override
        public String getKey(Integer value) throws Exception {
            return value.toString();
        }
    }).window(EventTimeSessionWindows.withGap(Time.seconds(5))).evictor(CountEvictor.of(5)).process(new TestProcessWindowFunction());
    final OneInputTransformation<Integer, String> transform = (OneInputTransformation<Integer, String>) window1.getTransformation();
    final OneInputStreamOperator<Integer, String> operator = transform.getOperator();
    Assert.assertTrue(operator instanceof WindowOperator);
    WindowOperator<String, Integer, ?, ?, ?> winOperator = (WindowOperator<String, Integer, ?, ?, ?>) operator;
    Assert.assertTrue(winOperator.getTrigger() instanceof EventTimeTrigger);
    Assert.assertTrue(winOperator.getWindowAssigner() instanceof EventTimeSessionWindows);
    Assert.assertTrue(winOperator.getStateDescriptor() instanceof ListStateDescriptor);
    processElementAndEnsureOutput(winOperator, winOperator.getKeySelector(), BasicTypeInfo.STRING_TYPE_INFO, 1);
}
Also used : ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) KeySelector(org.apache.flink.api.java.functions.KeySelector) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) EventTimeSessionWindows(org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) EventTimeTrigger(org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger) Test(org.junit.Test)

Example 5 with EventTimeSessionWindows

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

the class EventTimeSessionWindowsTest method testMergeSinglePointWindow.

@Test
public void testMergeSinglePointWindow() {
    MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
    EventTimeSessionWindows assigner = EventTimeSessionWindows.withGap(Time.milliseconds(5000));
    assigner.mergeWindows(Lists.newArrayList(new TimeWindow(0, 0)), callback);
    verify(callback, never()).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