Java Code Examples for org.apache.flink.runtime.leaderelection.TestingLeaderElectionService#isLeader()
The following examples show how to use
org.apache.flink.runtime.leaderelection.TestingLeaderElectionService#isLeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManualLeaderService.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public void grantLeadership(int index, UUID leaderId) { if (currentLeaderId != null) { revokeLeadership(); } Preconditions.checkNotNull(leaderId); Preconditions.checkArgument(0 <= index && index < leaderElectionServices.size()); TestingLeaderElectionService testingLeaderElectionService = leaderElectionServices.get(index); testingLeaderElectionService.isLeader(leaderId); currentLeaderIndex = index; currentLeaderId = leaderId; }
Example 2
Source File: ManualLeaderService.java From flink with Apache License 2.0 | 5 votes |
public void grantLeadership(int index, UUID leaderId) { if (currentLeaderId != null) { revokeLeadership(); } Preconditions.checkNotNull(leaderId); Preconditions.checkArgument(0 <= index && index < leaderElectionServices.size()); TestingLeaderElectionService testingLeaderElectionService = leaderElectionServices.get(index); testingLeaderElectionService.isLeader(leaderId); currentLeaderIndex = index; currentLeaderId = leaderId; }
Example 3
Source File: ZooKeeperDefaultDispatcherRunnerTest.java From flink with Apache License 2.0 | 5 votes |
private DispatcherGateway grantLeadership(TestingLeaderElectionService dispatcherLeaderElectionService) throws InterruptedException, java.util.concurrent.ExecutionException { final UUID leaderSessionId = UUID.randomUUID(); dispatcherLeaderElectionService.isLeader(leaderSessionId); final LeaderConnectionInfo leaderConnectionInfo = dispatcherLeaderElectionService.getConfirmationFuture().get(); return testingRpcServiceResource.getTestingRpcService().connect( leaderConnectionInfo.getAddress(), DispatcherId.fromUuid(leaderSessionId), DispatcherGateway.class).get(); }
Example 4
Source File: ManualLeaderService.java From flink with Apache License 2.0 | 5 votes |
public void grantLeadership(int index, UUID leaderId) { if (currentLeaderId != null) { revokeLeadership(); } Preconditions.checkNotNull(leaderId); Preconditions.checkArgument(0 <= index && index < leaderElectionServices.size()); TestingLeaderElectionService testingLeaderElectionService = leaderElectionServices.get(index); testingLeaderElectionService.isLeader(leaderId); currentLeaderIndex = index; currentLeaderId = leaderId; }
Example 5
Source File: DispatcherHATest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Tests that interleaved granting and revoking of the leadership won't interfere * with the job recovery and the resulting internal state of the Dispatcher. */ @Test public void testGrantingRevokingLeadership() throws Exception { final TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServices(); final JobGraph nonEmptyJobGraph = createNonEmptyJobGraph(); final SubmittedJobGraph submittedJobGraph = new SubmittedJobGraph(nonEmptyJobGraph); final OneShotLatch enterGetJobIdsLatch = new OneShotLatch(); final OneShotLatch proceedGetJobIdsLatch = new OneShotLatch(); highAvailabilityServices.setSubmittedJobGraphStore(new BlockingSubmittedJobGraphStore(submittedJobGraph, enterGetJobIdsLatch, proceedGetJobIdsLatch)); final TestingLeaderElectionService dispatcherLeaderElectionService = new TestingLeaderElectionService(); highAvailabilityServices.setDispatcherLeaderElectionService(dispatcherLeaderElectionService); final BlockingQueue<DispatcherId> fencingTokens = new ArrayBlockingQueue<>(2); final HATestingDispatcher dispatcher = createDispatcherWithObservableFencingTokens(highAvailabilityServices, fencingTokens); dispatcher.start(); try { // wait until the election service has been started dispatcherLeaderElectionService.getStartFuture().get(); final UUID leaderId = UUID.randomUUID(); dispatcherLeaderElectionService.isLeader(leaderId); dispatcherLeaderElectionService.notLeader(); final DispatcherId firstFencingToken = fencingTokens.take(); assertThat(firstFencingToken, equalTo(NULL_FENCING_TOKEN)); enterGetJobIdsLatch.await(); proceedGetJobIdsLatch.trigger(); assertThat(dispatcher.getNumberJobs(timeout).get(), is(0)); } finally { RpcUtils.terminateRpcEndpoint(dispatcher, timeout); } }
Example 6
Source File: DispatcherHATest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Tests that a Dispatcher does not remove the JobGraph from the submitted job graph store * when losing leadership and recovers it when regaining leadership. */ @Test public void testJobRecoveryWhenChangingLeadership() throws Exception { final InMemorySubmittedJobGraphStore submittedJobGraphStore = new InMemorySubmittedJobGraphStore(); final CompletableFuture<JobID> recoveredJobFuture = new CompletableFuture<>(); submittedJobGraphStore.setRecoverJobGraphFunction((jobID, jobIDSubmittedJobGraphMap) -> { recoveredJobFuture.complete(jobID); return jobIDSubmittedJobGraphMap.get(jobID); }); final TestingLeaderElectionService leaderElectionService = new TestingLeaderElectionService(); final TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServicesBuilder() .setSubmittedJobGraphStore(submittedJobGraphStore) .setDispatcherLeaderElectionService(leaderElectionService) .build(); final ArrayBlockingQueue<DispatcherId> fencingTokens = new ArrayBlockingQueue<>(2); final HATestingDispatcher dispatcher = createDispatcherWithObservableFencingTokens( highAvailabilityServices, fencingTokens); dispatcher.start(); try { // grant leadership and submit a single job final DispatcherId expectedDispatcherId = DispatcherId.generate(); leaderElectionService.isLeader(expectedDispatcherId.toUUID()).get(); assertThat(fencingTokens.take(), is(equalTo(expectedDispatcherId))); final DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class); final JobGraph jobGraph = createNonEmptyJobGraph(); final CompletableFuture<Acknowledge> submissionFuture = dispatcherGateway.submitJob(jobGraph, timeout); submissionFuture.get(); final JobID jobId = jobGraph.getJobID(); assertThat(submittedJobGraphStore.contains(jobId), is(true)); // revoke the leadership --> this should stop all running JobManagerRunners leaderElectionService.notLeader(); assertThat(fencingTokens.take(), is(equalTo(NULL_FENCING_TOKEN))); assertThat(submittedJobGraphStore.contains(jobId), is(true)); assertThat(recoveredJobFuture.isDone(), is(false)); // re-grant leadership leaderElectionService.isLeader(DispatcherId.generate().toUUID()); assertThat(recoveredJobFuture.get(), is(equalTo(jobId))); } finally { RpcUtils.terminateRpcEndpoint(dispatcher, timeout); } }
Example 7
Source File: ResourceManagerTaskExecutorTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private CompletableFuture<UUID> grantLeadership(TestingLeaderElectionService leaderElectionService) { UUID leaderSessionId = UUID.randomUUID(); return leaderElectionService.isLeader(leaderSessionId); }
Example 8
Source File: DispatcherHATest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that interleaved granting and revoking of the leadership won't interfere * with the job recovery and the resulting internal state of the Dispatcher. */ @Test public void testGrantingRevokingLeadership() throws Exception { final TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServices(); final JobGraph nonEmptyJobGraph = createNonEmptyJobGraph(); final SubmittedJobGraph submittedJobGraph = new SubmittedJobGraph(nonEmptyJobGraph); final OneShotLatch enterGetJobIdsLatch = new OneShotLatch(); final OneShotLatch proceedGetJobIdsLatch = new OneShotLatch(); highAvailabilityServices.setSubmittedJobGraphStore(new BlockingSubmittedJobGraphStore(submittedJobGraph, enterGetJobIdsLatch, proceedGetJobIdsLatch)); final TestingLeaderElectionService dispatcherLeaderElectionService = new TestingLeaderElectionService(); highAvailabilityServices.setDispatcherLeaderElectionService(dispatcherLeaderElectionService); final BlockingQueue<DispatcherId> fencingTokens = new ArrayBlockingQueue<>(2); final HATestingDispatcher dispatcher = createDispatcherWithObservableFencingTokens(highAvailabilityServices, fencingTokens); dispatcher.start(); try { // wait until the election service has been started dispatcherLeaderElectionService.getStartFuture().get(); final UUID leaderId = UUID.randomUUID(); dispatcherLeaderElectionService.isLeader(leaderId); dispatcherLeaderElectionService.notLeader(); final DispatcherId firstFencingToken = fencingTokens.take(); assertThat(firstFencingToken, equalTo(NULL_FENCING_TOKEN)); enterGetJobIdsLatch.await(); proceedGetJobIdsLatch.trigger(); assertThat(dispatcher.getNumberJobs(timeout).get(), is(0)); } finally { RpcUtils.terminateRpcEndpoint(dispatcher, timeout); } }
Example 9
Source File: DispatcherHATest.java From flink with Apache License 2.0 | 4 votes |
/** * Tests that a Dispatcher does not remove the JobGraph from the submitted job graph store * when losing leadership and recovers it when regaining leadership. */ @Test public void testJobRecoveryWhenChangingLeadership() throws Exception { final InMemorySubmittedJobGraphStore submittedJobGraphStore = new InMemorySubmittedJobGraphStore(); final CompletableFuture<JobID> recoveredJobFuture = new CompletableFuture<>(); submittedJobGraphStore.setRecoverJobGraphFunction((jobID, jobIDSubmittedJobGraphMap) -> { recoveredJobFuture.complete(jobID); return jobIDSubmittedJobGraphMap.get(jobID); }); final TestingLeaderElectionService leaderElectionService = new TestingLeaderElectionService(); final TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServicesBuilder() .setSubmittedJobGraphStore(submittedJobGraphStore) .setDispatcherLeaderElectionService(leaderElectionService) .build(); final ArrayBlockingQueue<DispatcherId> fencingTokens = new ArrayBlockingQueue<>(2); final HATestingDispatcher dispatcher = createDispatcherWithObservableFencingTokens( highAvailabilityServices, fencingTokens); dispatcher.start(); try { // grant leadership and submit a single job final DispatcherId expectedDispatcherId = DispatcherId.generate(); leaderElectionService.isLeader(expectedDispatcherId.toUUID()).get(); assertThat(fencingTokens.take(), is(equalTo(expectedDispatcherId))); final DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class); final JobGraph jobGraph = createNonEmptyJobGraph(); final CompletableFuture<Acknowledge> submissionFuture = dispatcherGateway.submitJob(jobGraph, timeout); submissionFuture.get(); final JobID jobId = jobGraph.getJobID(); assertThat(submittedJobGraphStore.contains(jobId), is(true)); // revoke the leadership --> this should stop all running JobManagerRunners leaderElectionService.notLeader(); assertThat(fencingTokens.take(), is(equalTo(NULL_FENCING_TOKEN))); assertThat(submittedJobGraphStore.contains(jobId), is(true)); assertThat(recoveredJobFuture.isDone(), is(false)); // re-grant leadership leaderElectionService.isLeader(DispatcherId.generate().toUUID()); assertThat(recoveredJobFuture.get(), is(equalTo(jobId))); } finally { RpcUtils.terminateRpcEndpoint(dispatcher, timeout); } }
Example 10
Source File: ResourceManagerTaskExecutorTest.java From flink with Apache License 2.0 | 4 votes |
private CompletableFuture<UUID> grantLeadership(TestingLeaderElectionService leaderElectionService) { UUID leaderSessionId = UUID.randomUUID(); return leaderElectionService.isLeader(leaderSessionId); }
Example 11
Source File: ResourceManagerTaskExecutorTest.java From flink with Apache License 2.0 | 4 votes |
private CompletableFuture<UUID> grantLeadership(TestingLeaderElectionService leaderElectionService) { UUID leaderSessionId = UUID.randomUUID(); return leaderElectionService.isLeader(leaderSessionId); }