mayuehappy commented on a change in pull request #17525:
URL: https://github.com/apache/flink/pull/17525#discussion_r742800068



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/state/StateBackendTestBase.java
##########
@@ -5084,6 +5084,58 @@ public void testMapStateGetKeys() throws Exception {
         }
     }
 
+    @Test
+    public void testMapStateGetKeysAndNamespaces() throws Exception {
+        final int elementsNum = 1000;
+        String fieldName = "get-keys-test";
+        CheckpointableKeyedStateBackend<Integer> backend =
+                createKeyedBackend(IntSerializer.INSTANCE);
+        try {
+            final String ns1 = "ns1";
+            MapState<String, Integer> keyedState1 =
+                    backend.getPartitionedState(
+                            ns1,
+                            StringSerializer.INSTANCE,
+                            new MapStateDescriptor<>(
+                                    fieldName, StringSerializer.INSTANCE, 
IntSerializer.INSTANCE));
+
+            final String ns2 = "ns2";
+            MapState<String, Integer> keyedState2 =
+                    backend.getPartitionedState(
+                            ns2,
+                            StringSerializer.INSTANCE,
+                            new MapStateDescriptor<>(
+                                    fieldName, StringSerializer.INSTANCE, 
IntSerializer.INSTANCE));
+
+            for (int key = 0; key < elementsNum; key++) {
+                backend.setCurrentKey(key);
+                keyedState1.put("he", key * 2);
+                keyedState1.put("ho", key * 2);
+                keyedState2.put("he", key * 2);
+                keyedState2.put("ho", key * 2);
+            }
+
+            try (Stream<Tuple2<Integer, String>> stream = 
backend.getKeysAndNamespaces(fieldName)) {
+                final Map<String, Set<Integer>> keysByNamespace = new 
HashMap<>();
+                stream.forEach(
+                        entry -> {
+                            assertThat("Unexpected namespace", entry.f1, 
isOneOf(ns1, ns2));

Review comment:
       Thank you very much for your patience, sorry for not understanding your 
meaning before. It seems that the code will be more concise. I have updated it.
   




-- 
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: [email protected]

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


Reply via email to