wqshr12345 commented on code in PR #25233:
URL: https://github.com/apache/flink/pull/25233#discussion_r1735477237


##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/v2/AsyncKeyedStateBackendAdaptorTest.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.runtime.state.v2;
+
+import org.apache.flink.api.common.state.State;
+import org.apache.flink.api.common.state.ValueState;
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.runtime.state.KeyGroupedInternalPriorityQueue;
+import org.apache.flink.runtime.state.Keyed;
+import org.apache.flink.runtime.state.KeyedStateBackend;
+import org.apache.flink.runtime.state.KeyedStateFunction;
+import org.apache.flink.runtime.state.PriorityComparable;
+import org.apache.flink.runtime.state.StateSnapshotTransformer;
+import org.apache.flink.runtime.state.heap.HeapPriorityQueueElement;
+import org.apache.flink.runtime.state.v2.adaptor.AsyncKeyedStateBackendAdaptor;
+
+import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests for {@link AsyncKeyedStateBackendAdaptor}. */
+public class AsyncKeyedStateBackendAdaptorTest {
+
+    @Test
+    public void testAdapt() throws Exception {
+        KeyedStateBackend<Integer> keyedStateBackend = new 
TestKeyedStateBackend();
+        AsyncKeyedStateBackendAdaptor<Integer> adaptor =
+                new AsyncKeyedStateBackendAdaptor(keyedStateBackend);
+        StateDescriptor descriptor =
+                new ValueStateDescriptor<>("testState", 
BasicTypeInfo.INT_TYPE_INFO);
+
+        org.apache.flink.api.common.state.v2.ValueState<Integer> valueState =
+                (org.apache.flink.api.common.state.v2.ValueState<Integer>)
+                        adaptor.createState(null, null, descriptor);
+
+        // test synchronous interfaces.
+        valueState.clear();
+        valueState.update(10);
+        assertEquals(10, valueState.value().intValue());
+
+        // test asynchronous interfaces.
+        valueState
+                .asyncClear()
+                .thenAccept(
+                        clear -> {
+                            valueState
+                                    .asyncUpdate(20)
+                                    .thenAccept(
+                                            update -> {

Review Comment:
   The comment has been addressed.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/v2/adaptor/ValueStateWrapper.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.runtime.state.v2.adaptor;
+
+import org.apache.flink.api.common.state.v2.StateFuture;
+import org.apache.flink.api.common.state.v2.ValueState;
+import org.apache.flink.core.state.StateFutureUtils;
+
+import java.io.IOException;
+
+/**
+ * A wrapper that transforms {@link 
org.apache.flink.api.common.state.ValueState} into {@link
+ * ValueState}.
+ *
+ * @param <V> Type of the value in the state.
+ */
+public class ValueStateWrapper<V> implements ValueState<V> {
+    private final org.apache.flink.api.common.state.ValueState<V> valueState;
+
+    public ValueStateWrapper(org.apache.flink.api.common.state.ValueState<V> 
valueState) {
+        this.valueState = valueState;
+    }
+
+    public StateFuture<V> asyncValue() {
+        try {
+            return StateFutureUtils.completedFuture(valueState.value());
+        } catch (Exception e) {
+            throw new RuntimeException("Error while getting value from raw 
ValueState", e);
+        }
+    }
+
+    public StateFuture<Void> asyncUpdate(V value) {
+        try {
+            valueState.update(value);
+        } catch (IOException e) {
+            throw new RuntimeException("Error while updating value from raw 
ValueState", e);
+        }
+        return StateFutureUtils.completedFuture(null);

Review Comment:
   The comment has been addressed.



-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to