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



##########
File path: 
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/highavailability/KubernetesLeaderElectionDriverTest.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.highavailability;
+
+import org.apache.flink.kubernetes.kubeclient.FlinkKubeClient;
+import org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap;
+import org.apache.flink.runtime.leaderelection.LeaderInformation;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import static 
org.apache.flink.kubernetes.utils.Constants.LABEL_CONFIGMAP_TYPE_HIGH_AVAILABILITY;
+import static 
org.apache.flink.kubernetes.utils.Constants.LABEL_CONFIGMAP_TYPE_KEY;
+import static org.apache.flink.kubernetes.utils.Constants.LEADER_ADDRESS_KEY;
+import static 
org.apache.flink.kubernetes.utils.Constants.LEADER_SESSION_ID_KEY;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for the {@link KubernetesLeaderElectionDriver}.
+ */
+public class KubernetesLeaderElectionDriverTest extends 
KubernetesHighAvailabilityTestBase {
+
+       @Test
+       public void testIsLeader() throws Exception {
+               new Context() {{
+                       runTest(
+                               () -> {
+                                       // Grant leadership
+                                       leaderCallbackGrantLeadership();
+                                       
assertThat(electionEventHandler.isLeader(), is(true));
+                                       
assertThat(electionEventHandler.getConfirmedLeaderInformation(), 
is(LEADER_INFORMATION));
+                               });
+               }};
+       }
+
+       @Test
+       public void testNotLeader() throws Exception {
+               new Context() {{
+                       runTest(
+                               () -> {
+                                       leaderCallbackGrantLeadership();
+                                       // Revoke leadership
+                                       getLeaderCallback().notLeader();
+
+                                       
electionEventHandler.waitForRevokeLeader(TIMEOUT);
+                                       
assertThat(electionEventHandler.isLeader(), is(false));
+                                       
assertThat(electionEventHandler.getConfirmedLeaderInformation(), 
is(LeaderInformation.empty()));
+                                       // The ConfigMap should also be cleared
+                                       
assertThat(getLeaderConfigMap().getData().get(LEADER_ADDRESS_KEY), 
is(nullValue()));
+                                       
assertThat(getLeaderConfigMap().getData().get(LEADER_SESSION_ID_KEY), 
is(nullValue()));

Review comment:
       ah ok. Thanks for the explanation.




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