wangyang0918 commented on a change in pull request #13644:
URL: https://github.com/apache/flink/pull/13644#discussion_r507402293
##########
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);
+ }
+
+ private KubernetesConfigMap buildHAConfigMap() {
+ final Map<String, String> data = new HashMap<>();
+ data.put(LEADER_ADDRESS_KEY, LEADER_ADDRESS);
+ return new KubernetesConfigMap(new ConfigMapBuilder()
+ .withNewMetadata()
+ .withName(LEADER_CONFIG_MAP_NAME)
+ .withLabels(haLabels)
+ .endMetadata()
+ .withData(data).build());
+ }
Review comment:
Will update.
##########
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));
+ }
Review comment:
Will update.
----------------------------------------------------------------
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]