tillrohrmann commented on a change in pull request #13644:
URL: https://github.com/apache/flink/pull/13644#discussion_r516790760



##########
File path: 
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClientITCase.java
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.kubernetes.kubeclient;
+
+import org.apache.flink.kubernetes.KubernetesResource;
+import org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+
+import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * IT Tests for {@link 
org.apache.flink.kubernetes.kubeclient.Fabric8FlinkKubeClient} with real K8s 
server and client.
+ */
+public class Fabric8FlinkKubeClientITCase {
+
+       @ClassRule
+       public static KubernetesResource kubernetesResource = new 
KubernetesResource();
+
+       private static final String TEST_CONFIG_MAP_NAME = "test-config-map";
+
+       private static final long TIMEOUT = 120L * 1000L;
+
+       private static final Map<String, String> data = new HashMap<String, 
String>() {
+               {
+                       put("key1", "0");
+                       put("key2", "0");
+                       put("key3", "0");
+               }
+       };
+
+       private FlinkKubeClient flinkKubeClient;
+
+       @Before
+       public void setup() throws Exception {
+               flinkKubeClient = kubernetesResource.getFlinkKubeClient();
+               flinkKubeClient.createConfigMap(new KubernetesConfigMap(
+                       new ConfigMapBuilder()
+                               .withNewMetadata()
+                               .withName(TEST_CONFIG_MAP_NAME)
+                               .endMetadata()
+                               .withData(data)
+                               .build())).get();
+       }
+
+       @After
+       public void teardown() throws Exception {
+               flinkKubeClient.deleteConfigMap(TEST_CONFIG_MAP_NAME).get();
+       }
+
+       /**
+        * {@link 
org.apache.flink.kubernetes.kubeclient.FlinkKubeClient#checkAndUpdateConfigMap} 
is a transactional
+        * operation, we should definitely guarantee that the concurrent 
modification could work.
+        */
+       @Test
+       public void testCheckAndUpdateConfigMapConcurrently() throws Exception {
+               // Start multiple instances to update ConfigMap concurrently
+               final List<CompletableFuture<Void>> futures = new ArrayList<>();
+               final int target = 10;
+               final int updateIntervalMs = 100;
+               for (String key : data.keySet()) {
+                       
futures.add(FutureUtils.runAfterwardsAsync(FutureUtils.completedVoidFuture(), 
() -> {

Review comment:
       If you use `join` instead of `get`, then you could use 
`CompletableFuture.runAsync(() -> {}, exec)`




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