zentol commented on code in PR #22422:
URL: https://github.com/apache/flink/pull/22422#discussion_r1175054869
##########
flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/DefaultLeaderElectionServiceTest.java:
##########
@@ -130,22 +137,101 @@ void testLeaderInformationChangedAndShouldBeCorrected()
throws Exception {
}
@Test
- void testHasLeadership() throws Exception {
+ void testHasLeadershipWithLeadershipButNoGrantEventProcessed() throws
Exception {
new Context() {
{
- runTest(
- () -> {
- testingLeaderElectionDriver.isLeader();
- final UUID currentLeaderSessionId =
- leaderElectionService.getLeaderSessionID();
- assertThat(currentLeaderSessionId).isNotNull();
-
assertThat(leaderElectionService.hasLeadership(currentLeaderSessionId))
+ runTestWithManuallyTriggeredEvents(
+ executorService -> {
+ final UUID expectedSessionID = UUID.randomUUID();
+
+
testingLeaderElectionDriver.isLeader(expectedSessionID);
+
+
assertThat(leaderElectionService.hasLeadership(expectedSessionID))
+ .isFalse();
+
assertThat(leaderElectionService.hasLeadership(UUID.randomUUID()))
+ .isFalse();
+ });
+ }
+ };
+ }
+
+ @Test
+ void testHasLeadershipWithLeadershipAndGrantEventProcessed() throws
Exception {
+ new Context() {
+ {
+ runTestWithManuallyTriggeredEvents(
+ executorService -> {
+ final UUID expectedSessionID = UUID.randomUUID();
+
+
testingLeaderElectionDriver.isLeader(expectedSessionID);
+ executorService.trigger();
+
+
assertThat(leaderElectionService.hasLeadership(expectedSessionID))
.isTrue();
assertThat(leaderElectionService.hasLeadership(UUID.randomUUID()))
.isFalse();
+ });
+ }
+ };
+ }
+
+ @Test
+ void testHasLeadershipWithLeadershipLostButNoRevokeEventProcessed() throws
Exception {
+ new Context() {
+ {
+ runTestWithManuallyTriggeredEvents(
+ executorService -> {
+ final UUID expectedSessionID = UUID.randomUUID();
+
+
testingLeaderElectionDriver.isLeader(expectedSessionID);
+ executorService.trigger();
+ testingLeaderElectionDriver.notLeader();
+
+
assertThat(leaderElectionService.hasLeadership(expectedSessionID))
+ .isFalse();
Review Comment:
That makes sense; a comment would be useful.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]