use of org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows in project flink by apache.
the class AllWindowTranslationTest method testReduceWithEvictorAndProcessFunction.
@Test
@SuppressWarnings("rawtypes")
public void testReduceWithEvictorAndProcessFunction() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStream<Tuple2<String, Integer>> source = env.fromElements(Tuple2.of("hello", 1), Tuple2.of("hello", 2));
DummyReducer reducer = new DummyReducer();
DataStream<Tuple2<String, Integer>> window1 = source.windowAll(SlidingEventTimeWindows.of(Time.of(1, TimeUnit.SECONDS), Time.of(100, TimeUnit.MILLISECONDS))).evictor(CountEvictor.of(100)).reduce(reducer, new ProcessAllWindowFunction<Tuple2<String, Integer>, Tuple2<String, Integer>, TimeWindow>() {
@Override
public void process(Context context, Iterable<Tuple2<String, Integer>> elements, Collector<Tuple2<String, Integer>> out) throws Exception {
for (Tuple2<String, Integer> in : elements) {
out.collect(in);
}
}
});
OneInputTransformation<Tuple2<String, Integer>, Tuple2<String, Integer>> transform = (OneInputTransformation<Tuple2<String, Integer>, Tuple2<String, Integer>>) window1.getTransformation();
OneInputStreamOperator<Tuple2<String, Integer>, Tuple2<String, Integer>> operator = transform.getOperator();
Assert.assertTrue(operator instanceof EvictingWindowOperator);
EvictingWindowOperator<String, Tuple2<String, Integer>, ?, ?> winOperator = (EvictingWindowOperator<String, Tuple2<String, Integer>, ?, ?>) operator;
Assert.assertTrue(winOperator.getTrigger() instanceof EventTimeTrigger);
Assert.assertTrue(winOperator.getEvictor() instanceof CountEvictor);
Assert.assertTrue(winOperator.getWindowAssigner() instanceof SlidingEventTimeWindows);
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.SlidingEventTimeWindows in project flink by apache.
the class SlidingEventTimeWindowsTest method testWindowAssignmentWithOffset.
@Test
public void testWindowAssignmentWithOffset() {
WindowAssigner.WindowAssignerContext mockContext = mock(WindowAssigner.WindowAssignerContext.class);
SlidingEventTimeWindows assigner = SlidingEventTimeWindows.of(Time.milliseconds(5000), Time.milliseconds(1000), Time.milliseconds(100));
assertThat(assigner.assignWindows("String", 100L, mockContext), containsInAnyOrder(timeWindow(-3900, 1100), timeWindow(-2900, 2100), timeWindow(-1900, 3100), timeWindow(-900, 4100), timeWindow(100, 5100)));
assertThat(assigner.assignWindows("String", 5099L, mockContext), containsInAnyOrder(timeWindow(100, 5100), timeWindow(1100, 6100), timeWindow(2100, 7100), timeWindow(3100, 8100), timeWindow(4100, 9100)));
assertThat(assigner.assignWindows("String", 5100L, mockContext), containsInAnyOrder(timeWindow(1100, 6100), timeWindow(2100, 7100), timeWindow(3100, 8100), timeWindow(4100, 9100), timeWindow(5100, 10100)));
}
use of org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows in project flink by apache.
the class SlidingEventTimeWindowsTest method testWindowAssignmentWithNegativeOffset.
@Test
public void testWindowAssignmentWithNegativeOffset() {
WindowAssigner.WindowAssignerContext mockContext = mock(WindowAssigner.WindowAssignerContext.class);
SlidingEventTimeWindows assigner = SlidingEventTimeWindows.of(Time.milliseconds(5000), Time.milliseconds(1000), Time.milliseconds(-100));
assertThat(assigner.assignWindows("String", 0L, mockContext), containsInAnyOrder(timeWindow(-4100, 900), timeWindow(-3100, 1900), timeWindow(-2100, 2900), timeWindow(-1100, 3900), timeWindow(-100, 4900)));
assertThat(assigner.assignWindows("String", 4899L, mockContext), containsInAnyOrder(timeWindow(-100, 4900), timeWindow(900, 5900), timeWindow(1900, 6900), timeWindow(2900, 7900), timeWindow(3900, 8900)));
assertThat(assigner.assignWindows("String", 4900L, mockContext), containsInAnyOrder(timeWindow(900, 5900), timeWindow(1900, 6900), timeWindow(2900, 7900), timeWindow(3900, 8900), timeWindow(4900, 9900)));
}
use of org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows in project flink by apache.
the class SlidingEventTimeWindowsTest method testWindowAssignment.
@Test
public void testWindowAssignment() {
WindowAssigner.WindowAssignerContext mockContext = mock(WindowAssigner.WindowAssignerContext.class);
SlidingEventTimeWindows assigner = SlidingEventTimeWindows.of(Time.milliseconds(5000), Time.milliseconds(1000));
assertThat(assigner.assignWindows("String", 0L, mockContext), containsInAnyOrder(timeWindow(-4000, 1000), timeWindow(-3000, 2000), timeWindow(-2000, 3000), timeWindow(-1000, 4000), timeWindow(0, 5000)));
assertThat(assigner.assignWindows("String", 4999L, mockContext), containsInAnyOrder(timeWindow(0, 5000), timeWindow(1000, 6000), timeWindow(2000, 7000), timeWindow(3000, 8000), timeWindow(4000, 9000)));
assertThat(assigner.assignWindows("String", 5000L, mockContext), containsInAnyOrder(timeWindow(1000, 6000), timeWindow(2000, 7000), timeWindow(3000, 8000), timeWindow(4000, 9000), timeWindow(5000, 10000)));
}
Aggregations