zentol commented on a change in pull request #7654: [FLINK-11524] Solve race 
condition in EmbeddedLeaderService
URL: https://github.com/apache/flink/pull/7654#discussion_r254219140
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/embedded/EmbeddedHaServicesTest.java
 ##########
 @@ -164,4 +171,70 @@ public void testResourceManagerLeaderRetrieval() throws 
Exception {
 
                
verify(leaderRetrievalListener).notifyLeaderAddress(eq(address), eq(leaderId));
        }
+
+       /**
+        * Tests that concurrent leadership operations (granting and revoking) 
leadership leave the
+        * system in a sane state.
+        */
+       @Test
+       public void testConcurrentLeadershipOperations() throws Exception {
+               final LeaderElectionService dispatcherLeaderElectionService = 
embeddedHaServices.getDispatcherLeaderElectionService();
+               final ArrayBlockingQueue<UUID> offeredSessionIds = new 
ArrayBlockingQueue<>(2);
+               final TestingLeaderContender leaderContender = new 
TestingLeaderContender(offeredSessionIds);
+
+               dispatcherLeaderElectionService.start(leaderContender);
+
+               final UUID oldLeaderSessionId = offeredSessionIds.take();
+
+               
assertThat(dispatcherLeaderElectionService.hasLeadership(oldLeaderSessionId), 
is(true));
+
+               
embeddedHaServices.getDispatcherLeaderService().revokeLeadership().get();
+               
assertThat(dispatcherLeaderElectionService.hasLeadership(oldLeaderSessionId), 
is(false));
+
+               
embeddedHaServices.getDispatcherLeaderService().grantLeadership();
+               final UUID newLeaderSessionId = offeredSessionIds.take();
+
+               
assertThat(dispatcherLeaderElectionService.hasLeadership(newLeaderSessionId), 
is(true));
+
+               
dispatcherLeaderElectionService.confirmLeaderSessionID(oldLeaderSessionId);
+               
dispatcherLeaderElectionService.confirmLeaderSessionID(newLeaderSessionId);
 
 Review comment:
   Before the fix, this is where we would've set `isLeader` to false for the 
current leader, correct?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services

Reply via email to