XComp commented on code in PR #21137: URL: https://github.com/apache/flink/pull/21137#discussion_r1008330056
########## flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/JobMasterServiceLeadershipRunnerTest.java: ########## @@ -683,21 +665,66 @@ public void testJobAlreadyDone() throws Exception { jobManagerRunner.getResultFuture(); JobManagerRunnerResult result = resultFuture.get(); - assertEquals( - JobStatus.FAILED, - result.getExecutionGraphInfo().getArchivedExecutionGraph().getState()); + assertThat(result.getExecutionGraphInfo().getArchivedExecutionGraph().getState()) + .isEqualTo(JobStatus.FAILED); } } + @Test + void testJobMasterServiceLeadershipRunnerCloseWhenElectionServiceGrantLeaderShip() + throws Exception { + final TestingLeaderElectionDriver.TestingLeaderElectionDriverFactory + testingLeaderElectionDriverFactory = + new TestingLeaderElectionDriver.TestingLeaderElectionDriverFactory(); + final LeaderElectionService defaultLeaderElectionService = + new DefaultLeaderElectionService(testingLeaderElectionDriverFactory); + + final JobMasterServiceLeadershipRunner jobManagerRunner = + newJobMasterServiceLeadershipRunnerBuilder() + .setJobMasterServiceProcessFactory( + TestingJobMasterServiceProcessFactory.newBuilder().build()) + .setLeaderElectionService(defaultLeaderElectionService) + .build(); + + jobManagerRunner.start(); + final TestingLeaderElectionDriver currentLeaderDriver = + Preconditions.checkNotNull( + testingLeaderElectionDriverFactory.getCurrentLeaderDriver()); + + final CheckedThread contenderCloseThread = + new CheckedThread() { + @Override + public void go() { + try { + jobManagerRunner.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }; + contenderCloseThread.start(); + + // grant leadership. + currentLeaderDriver.isLeader(); Review Comment: I went ahead and created a PR with a running example. See reswqa/flink#1 and feel free to edit it. Please see the PRs description. It's not meant to be merged as is but rather an example on how you would be able to test it. I'm happy to discuss any questions you have. But I hope the inline comments are helpful already. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org