use of org.apache.flink.state.api.utils.ReduceSum in project flink by apache.
the class SavepointWindowReaderITCase method testWindowTriggerStateReader.
@Test
public void testWindowTriggerStateReader() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStateBackend(getStateBackend());
env.setParallelism(4);
env.addSource(createSource(numbers)).rebalance().keyBy(id -> id).window(GlobalWindows.create()).trigger(PurgingTrigger.of(CountTrigger.of(10))).reduce(new ReduceSum()).uid(uid).addSink(new DiscardingSink<>());
String savepointPath = takeSavepoint(env);
SavepointReader savepoint = SavepointReader.read(env, savepointPath, getStateBackend());
List<Long> results = JobResultRetriever.collect(savepoint.window(new GlobalWindow.Serializer()).reduce(uid, new ReduceSum(), new TriggerReaderFunction(), Types.INT, Types.INT, Types.LONG));
Assert.assertThat("Unexpected results from trigger state", results, Matchers.contains(1L, 1L, 1L));
}
use of org.apache.flink.state.api.utils.ReduceSum in project flink by apache.
the class WindowReaderTest method testReducingWindow.
@Test
public void testReducingWindow() throws Exception {
WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).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(Arrays.asList(1, 1), list);
}
use of org.apache.flink.state.api.utils.ReduceSum in project flink by apache.
the class DataSetSavepointWindowReaderITCase 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);
ExecutionEnvironment batchEnv = ExecutionEnvironment.getExecutionEnvironment();
ExistingSavepoint savepoint = Savepoint.load(batchEnv, savepointPath, getStateBackend());
List<Integer> results = savepoint.window(TumblingEventTimeWindows.of(Time.milliseconds(10))).reduce(uid, new ReduceSum(), Types.INT, Types.INT).collect();
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 DataSetSavepointWindowReaderITCase 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);
ExecutionEnvironment batchEnv = ExecutionEnvironment.getExecutionEnvironment();
ExistingSavepoint savepoint = Savepoint.load(batchEnv, savepointPath, getStateBackend());
List<Integer> results = savepoint.window(TumblingEventTimeWindows.of(Time.milliseconds(10))).evictor().reduce(uid, new ReduceSum(), Types.INT, Types.INT).collect();
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 DataSetSavepointWindowReaderITCase method testWindowTriggerStateReader.
@Test
public void testWindowTriggerStateReader() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStateBackend(getStateBackend());
env.setParallelism(4);
env.addSource(createSource(numbers)).rebalance().keyBy(id -> id).window(GlobalWindows.create()).trigger(PurgingTrigger.of(CountTrigger.of(10))).reduce(new ReduceSum()).uid(uid).addSink(new DiscardingSink<>());
String savepointPath = takeSavepoint(env);
ExecutionEnvironment batchEnv = ExecutionEnvironment.getExecutionEnvironment();
ExistingSavepoint savepoint = Savepoint.load(batchEnv, savepointPath, getStateBackend());
List<Long> results = savepoint.window(new GlobalWindow.Serializer()).reduce(uid, new ReduceSum(), new TriggerReaderFunction(), Types.INT, Types.INT, Types.LONG).collect();
Assert.assertThat("Unexpected results from trigger state", results, Matchers.contains(1L, 1L, 1L));
}
Aggregations