use of org.apache.flink.state.api.utils.ReduceSum in project flink by apache.
the class SavepointWindowReaderITCase method testReduceWindowStateReader.
@Test
public void testReduceWindowStateReader() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStateBackend(getStateBackend());
env.setParallelism(4);
env.addSource(createSource(numbers)).rebalance().assignTimestampsAndWatermarks(WatermarkStrategy.<Integer>noWatermarks().withTimestampAssigner((event, timestamp) -> 0)).keyBy(id -> id).window(TumblingEventTimeWindows.of(Time.milliseconds(10))).reduce(new ReduceSum()).uid(uid).addSink(new DiscardingSink<>());
String savepointPath = takeSavepoint(env);
SavepointReader savepoint = SavepointReader.read(env, savepointPath, getStateBackend());
List<Integer> results = JobResultRetriever.collect(savepoint.window(TumblingEventTimeWindows.of(Time.milliseconds(10))).reduce(uid, new ReduceSum(), Types.INT, Types.INT));
Assert.assertThat("Unexpected results from keyed state", results, Matchers.containsInAnyOrder(numbers));
}
use of org.apache.flink.state.api.utils.ReduceSum in project flink by apache.
the class SavepointWindowReaderITCase method testReduceEvictorWindowStateReader.
@Test
public void testReduceEvictorWindowStateReader() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStateBackend(getStateBackend());
env.setParallelism(4);
env.addSource(createSource(numbers)).rebalance().assignTimestampsAndWatermarks(WatermarkStrategy.<Integer>noWatermarks().withTimestampAssigner((event, timestamp) -> 0)).keyBy(id -> id).window(TumblingEventTimeWindows.of(Time.milliseconds(10))).evictor(new NoOpEvictor<>()).reduce(new ReduceSum()).uid(uid).addSink(new DiscardingSink<>());
String savepointPath = takeSavepoint(env);
SavepointReader savepoint = SavepointReader.read(env, savepointPath, getStateBackend());
List<Integer> results = JobResultRetriever.collect(savepoint.window(TumblingEventTimeWindows.of(Time.milliseconds(10))).evictor().reduce(uid, new ReduceSum(), Types.INT, Types.INT));
Assert.assertThat("Unexpected results from keyed state", results, Matchers.containsInAnyOrder(numbers));
}
use of org.apache.flink.state.api.utils.ReduceSum in project flink by apache.
the class WindowReaderTest method testSessionWindow.
@Test
public void testSessionWindow() throws Exception {
WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(EventTimeSessionWindows.withGap(Time.milliseconds(3))).reduce(new ReduceSum()));
OperatorState operatorState = getOperatorState(operator);
KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.reduce(new ReduceSum(), new PassThroughReader<>(), Types.INT, new TimeWindow.Serializer(), Types.INT));
List<Integer> list = readState(format);
Assert.assertEquals(Collections.singletonList(2), list);
}
Aggregations