wangyang0918 commented on a change in pull request #13644: URL: https://github.com/apache/flink/pull/13644#discussion_r507403885
########## File path: flink-kubernetes/src/test/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClientTest.java ########## @@ -249,4 +265,58 @@ public void testStopAndCleanupCluster() throws Exception { this.flinkKubeClient.stopAndCleanupCluster(CLUSTER_ID); assertTrue(this.kubeClient.apps().deployments().inNamespace(NAMESPACE).list().getItems().isEmpty()); } + + @Test + public void testCreateAndDeleteConfigMap() { + this.flinkKubeClient.createConfigMap(buildHAConfigMap()); + assertThat(this.flinkKubeClient.getConfigMap(LEADER_CONFIG_MAP_NAME).isPresent(), is(true)); + this.flinkKubeClient.deleteConfigMapsByLabels(haLabels); + assertThat(this.flinkKubeClient.getConfigMap(LEADER_CONFIG_MAP_NAME).isPresent(), is(false)); + } + + @Test + public void testCheckAndUpdateConfigMap() throws Exception { + this.flinkKubeClient.createConfigMap(buildHAConfigMap()); + + final Supplier<Exception> configMapNotExistException = () -> new Exception("ConfigMap not exist"); + FunctionWithException<KubernetesConfigMap, KubernetesConfigMap, ?> function = c -> { + c.getData().put(LEADER_ADDRESS_KEY, LEADER_ADDRESS_NEW); + return c; + }; + this.flinkKubeClient.getConfigMap(LEADER_CONFIG_MAP_NAME).map( + configMap -> { + assertThat(configMap.getData().get(LEADER_ADDRESS_KEY), is(LEADER_ADDRESS)); + return configMap; + } + ).orElseThrow(configMapNotExistException); + + // Checker not pass + this.flinkKubeClient.checkAndUpdateConfigMap(LEADER_CONFIG_MAP_NAME, c -> false, function).get(); + this.flinkKubeClient.getConfigMap(LEADER_CONFIG_MAP_NAME).map( + configMap -> { + assertThat(configMap.getData().get(LEADER_ADDRESS_KEY), is(LEADER_ADDRESS)); + return configMap; + } + ).orElseThrow(configMapNotExistException); + + // Checker pass + this.flinkKubeClient.checkAndUpdateConfigMap(LEADER_CONFIG_MAP_NAME, c -> true, function).get(); + this.flinkKubeClient.getConfigMap(LEADER_CONFIG_MAP_NAME).map( + configMap -> { + assertThat(configMap.getData().get(LEADER_ADDRESS_KEY), is(LEADER_ADDRESS_NEW)); + return configMap; + } + ).orElseThrow(configMapNotExistException); + } Review comment: Actually, I change the implementation from `assertThat(configMapOpt.isPresent(), true);` to throw `configMapNotExistException`. I could get them back and split into two cases. ---------------------------------------------------------------- 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