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



##########
File path: 
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClientTest.java
##########
@@ -249,4 +265,69 @@ public void testStopAndCleanupCluster() throws Exception {
                this.flinkKubeClient.stopAndCleanupCluster(CLUSTER_ID);
                
assertTrue(this.kubeClient.apps().deployments().inNamespace(NAMESPACE).list().getItems().isEmpty());
        }
+
+       @Test
+       public void testCreateConfigMap() throws Exception {
+               final KubernetesConfigMap configMap = buildTestingConfigMap();
+               this.flinkKubeClient.createConfigMap(configMap).get();
+               final Optional<KubernetesConfigMap> currentOpt = 
this.flinkKubeClient.getConfigMap(TESTING_CONFIG_MAP_NAME);
+               assertThat(currentOpt.isPresent(), is(true));
+               
assertThat(currentOpt.get().getData().get(TESTING_CONFIG_MAP_KEY), 
is(TESTING_CONFIG_MAP_VALUE));
+       }
+
+       @Test
+       public void testDeleteConfigMapByLabels() throws Exception {
+               
this.flinkKubeClient.createConfigMap(buildTestingConfigMap()).get();
+               
assertThat(this.flinkKubeClient.getConfigMap(TESTING_CONFIG_MAP_NAME).isPresent(),
 is(true));
+               this.flinkKubeClient.deleteConfigMapsByLabels(TESTING_LABELS);
+               
assertThat(this.flinkKubeClient.getConfigMap(TESTING_CONFIG_MAP_NAME).isPresent(),
 is(false));
+       }
+
+       @Test
+       public void testDeleteConfigMapByName() throws Exception {
+               
this.flinkKubeClient.createConfigMap(buildTestingConfigMap()).get();
+               
assertThat(this.flinkKubeClient.getConfigMap(TESTING_CONFIG_MAP_NAME).isPresent(),
 is(true));
+               this.flinkKubeClient.deleteConfigMap(TESTING_CONFIG_MAP_NAME);
+               
assertThat(this.flinkKubeClient.getConfigMap(TESTING_CONFIG_MAP_NAME).isPresent(),
 is(false));
+       }
+
+       @Test
+       public void testCheckAndUpdateConfigMap() throws Exception {
+               this.flinkKubeClient.createConfigMap(buildTestingConfigMap());
+
+               // Checker pass
+               this.flinkKubeClient.checkAndUpdateConfigMap(
+                       TESTING_CONFIG_MAP_NAME,
+                       c -> {
+                               c.getData().put(TESTING_CONFIG_MAP_KEY, 
TESTING_CONFIG_MAP_NEW_VALUE);
+                               return Optional.of(c);
+                       }).get();
+
+               final Optional<KubernetesConfigMap> configMapOpt = 
this.flinkKubeClient.getConfigMap(TESTING_CONFIG_MAP_NAME);
+               assertThat(configMapOpt.isPresent(), is(true));
+               
assertThat(configMapOpt.get().getData().get(TESTING_CONFIG_MAP_KEY), 
is(TESTING_CONFIG_MAP_NEW_VALUE));
+       }
+
+       @Test
+       public void testCheckAndUpdateConfigMapWithEmptyResult() throws 
Exception {
+               this.flinkKubeClient.createConfigMap(buildTestingConfigMap());
+
+               // Checker not pass and return empty result
+               
this.flinkKubeClient.checkAndUpdateConfigMap(TESTING_CONFIG_MAP_NAME, c -> 
Optional.empty()).get();
+
+               final Optional<KubernetesConfigMap> configMapOpt = 
this.flinkKubeClient.getConfigMap(TESTING_CONFIG_MAP_NAME);
+               assertThat(configMapOpt.isPresent(), is(true));
+               
assertThat(configMapOpt.get().getData().get(TESTING_CONFIG_MAP_KEY), 
is(TESTING_CONFIG_MAP_VALUE));
+       }
+
+       private KubernetesConfigMap buildTestingConfigMap() {
+               final Map<String, String> data = new HashMap<>();
+               data.put(TESTING_CONFIG_MAP_KEY, TESTING_CONFIG_MAP_VALUE);
+               return new KubernetesConfigMap(new ConfigMapBuilder()
+                       .withNewMetadata()
+                       .withName(TESTING_CONFIG_MAP_NAME)
+                       .withLabels(TESTING_LABELS)
+                       .endMetadata()
+                       .withData(data).build());
+       }

Review comment:
       I will add a test for creating failed and an exception should be thrown.
   
   The reason why I do not test the concurrent writes is that we are using 
`KubernetesMockServer`. Actually, it could not support such semantic, the 
resource version is always null. 




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to