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));
}
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)));
}
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());
}
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);
}
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());
}
Aggregations