XComp commented on code in PR #22919:
URL: https://github.com/apache/flink/pull/22919#discussion_r1253187439
##########
flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/DefaultLeaderElectionServiceTest.java:
##########
@@ -180,25 +186,117 @@ void testCloseGrantDeadlock() throws Exception {
}
@Test
- void testGrantCallWhileInstantiatingDriver() throws Exception {
- final UUID expectedLeaderSessionID = UUID.randomUUID();
+ void testLazyDriverInstantiation() throws Exception {
+ final AtomicBoolean driverCreated = new AtomicBoolean();
try (final DefaultLeaderElectionService testInstance =
new DefaultLeaderElectionService(
(listener, errorHandler) -> {
- listener.isLeader(expectedLeaderSessionID);
+ driverCreated.set(true);
return TestingLeaderElectionDriver.newNoOpBuilder()
.build(listener, errorHandler);
},
fatalErrorHandlerExtension.getTestingFatalErrorHandler(),
Executors.newDirectExecutorService())) {
- testInstance.startLeaderElectionBackend();
+ assertThat(driverCreated)
+ .as("The driver shouldn't have been created during service
creation.")
+ .isFalse();
+
+ try (final LeaderElection leaderElection =
+ testInstance.createLeaderElection("contender-id")) {
+ assertThat(driverCreated)
+ .as(
+ "The driver shouldn't have been created during
LeaderElection creation.")
+ .isFalse();
+
+ leaderElection.startLeaderElection(
+ TestingGenericLeaderContender.newBuilder().build());
+ assertThat(driverCreated)
+ .as(
+ "The driver should have been created when
registering the contender in the LeaderElection.")
+ .isTrue();
+ }
+ }
+ }
+
+ @Test
+ void testReuseOfServiceIsRestricted() throws Exception {
+ final DefaultLeaderElectionService testInstance =
+ new DefaultLeaderElectionService(
+ new TestingLeaderElectionDriver.Factory(
+ TestingLeaderElectionDriver.newNoOpBuilder()));
+
+ // The driver hasn't started, yet, which prevents the service from
going into running state.
+ // This results in the close method not having any effect.
+ testInstance.close();
+
+ try (final LeaderElection leaderElection =
+ testInstance.createLeaderElection("contender-id")) {
Review Comment:
The new commit implementing the behavior described in [the comment
above](https://github.com/apache/flink/pull/22919#discussion_r1253186428) will
make the call fail from now on. :+1:
--
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]