sjwiesman commented on a change in pull request #13384:
URL: https://github.com/apache/flink/pull/13384#discussion_r489576528



##########
File path: 
flink-libraries/flink-state-processing-api/src/test/java/org/apache/flink/state/api/SavepointWindowReaderITCase.java
##########
@@ -0,0 +1,370 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.state.api;
+
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.ExecutionEnvironment;
+import org.apache.flink.runtime.state.StateBackend;
+import org.apache.flink.state.api.functions.WindowReaderFunction;
+import org.apache.flink.state.api.utils.AggregateSum;
+import org.apache.flink.state.api.utils.ReduceSum;
+import org.apache.flink.state.api.utils.SavepointTestBase;
+import org.apache.flink.streaming.api.TimeCharacteristic;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
+import 
org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
+import org.apache.flink.streaming.api.functions.windowing.WindowFunction;
+import org.apache.flink.streaming.api.windowing.evictors.Evictor;
+import org.apache.flink.streaming.api.windowing.time.Time;
+import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
+import org.apache.flink.streaming.api.windowing.windows.Window;
+import org.apache.flink.streaming.runtime.operators.windowing.TimestampedValue;
+import org.apache.flink.util.Collector;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * IT Case for reading window operator state.
+ */
+public abstract class SavepointWindowReaderITCase<B extends StateBackend> 
extends SavepointTestBase {
+       private static final String uid = "stateful-operator";
+
+       private static final Integer[] numbers = { 1, 2, 3 };
+
+       protected abstract B getStateBackend();
+
+       @Test
+       public void testReduceWindowStateReader() throws Exception {
+               String savepointPath = takeSavepoint(numbers, source -> {
+                       StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+                       
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
+                       env.setStateBackend(getStateBackend());
+                       env.setParallelism(4);
+
+                       env
+                               .addSource(source)
+                               .rebalance()
+                               .assignTimestampsAndWatermarks(WatermarkStrategy
+                                       .<Integer>noWatermarks()
+                                       .withTimestampAssigner((event, 
timestamp) -> 0))
+                               .keyBy(id -> id)
+                               .timeWindow(Time.milliseconds(10))
+                               .reduce(new ReduceSum())
+                               .uid(uid)
+                               .addSink(new DiscardingSink<>());
+
+                       return env;
+               });
+
+               ExecutionEnvironment batchEnv = 
ExecutionEnvironment.getExecutionEnvironment();
+               ExistingSavepoint savepoint = Savepoint.load(batchEnv, 
savepointPath, getStateBackend());
+
+               List<Integer> results = savepoint
+                       .timeWindow()
+                       .reduce(uid, new ReduceSum(), Types.INT, Types.INT)
+                       .collect();
+
+               Assert.assertThat("Unexpected results from keyed state", 
results, Matchers.containsInAnyOrder(numbers));

Review comment:
       Yes, the number is the key and the value so they each go to a different 
window pane. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to