XComp commented on code in PR #22380:
URL: https://github.com/apache/flink/pull/22380#discussion_r1169042058
##########
flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/TestingLeaderElectionDriver.java:
##########
@@ -70,22 +77,37 @@ public LeaderInformation getLeaderInformation() {
}
public void isLeader() {
+ isLeader(FutureUtils.completedVoidFuture());
+ }
+
+ public void isLeader(CompletableFuture<Void> grantLeadershipFuture) {
synchronized (lock) {
isLeader.set(true);
- leaderElectionEventHandler.onGrantLeadership(UUID.randomUUID());
+ grantLeadershipFuture.thenRun(
+ () ->
leaderElectionEventHandler.onGrantLeadership(UUID.randomUUID()));
Review Comment:
This is actually simulating what we're already using in
`DefaultLeaderElectionService` in combination with the
`MultipleComponentLeaderElectionDriver` implementations. They call
`MultipleComponentLeaderElectionDriver.Listener.isLeader()` which triggers
[DefaultMultipleComponentLeaderElectionService.isLeader()](https://github.com/apache/flink/blob/e3cd3b311c1c8a6a0e0cdc849d7c951ef8beea5c/flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionService.java#L188).
That method calls `onGrantLeadership` for each `LeaderElectionEventHandler` in
[DefaultMultipleComponentLeaderElectionService:202](https://github.com/apache/flink/blob/e3cd3b311c1c8a6a0e0cdc849d7c951ef8beea5c/flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionService.java#L202).
These calls will be executed in a separate executor in
[DefaultMultipleComponentLeaderElectionService:225](https://github.com/apache/flink/blob/
e3cd3b311c1c8a6a0e0cdc849d7c951ef8beea5c/flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionService.java#L225).
The order of the grant/revoke calls (which is the important bit) is ensured
by the singleThread executor (see
[DefaultMultipleComponentLeaderElectionService:98](https://github.com/apache/flink/blob/e3cd3b311c1c8a6a0e0cdc849d7c951ef8beea5c/flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionService.java#L98).
For test cases that use this feature, the test implementation has to ensure
the right order of calls.
--
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]