use of org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService in project flink by apache.
the class DefaultJobLeaderServiceTest method doesNotReconnectAfterTargetLostLeadership.
/**
* Tests that the JobLeaderService won't try to reconnect to JobMaster after it has lost the
* leadership. See FLINK-16836.
*/
@Test
public void doesNotReconnectAfterTargetLostLeadership() throws Exception {
final JobID jobId = new JobID();
final SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService();
final TestingHighAvailabilityServices haServices = new TestingHighAvailabilityServicesBuilder().setJobMasterLeaderRetrieverFunction(ignored -> leaderRetrievalService).build();
final TestingJobMasterGateway jobMasterGateway = registerJobMaster();
final OneShotLatch jobManagerGainedLeadership = new OneShotLatch();
final TestingJobLeaderListener testingJobLeaderListener = new TestingJobLeaderListener(ignored -> jobManagerGainedLeadership.trigger());
final JobLeaderService jobLeaderService = createAndStartJobLeaderService(haServices, testingJobLeaderListener);
try {
jobLeaderService.addJob(jobId, jobMasterGateway.getAddress());
leaderRetrievalService.notifyListener(jobMasterGateway.getAddress(), UUID.randomUUID());
jobManagerGainedLeadership.await();
// revoke the leadership
leaderRetrievalService.notifyListener(null, null);
testingJobLeaderListener.waitUntilJobManagerLostLeadership();
jobLeaderService.reconnect(jobId);
} finally {
jobLeaderService.stop();
}
}
use of org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService in project flink by apache.
the class DefaultJobLeaderServiceTest method canReconnectToOldLeaderWithSameLeaderAddress.
/**
* Tests that the JobLeaderService can reconnect to an old leader which seemed to have lost the
* leadership in between. See FLINK-14316.
*/
@Test
public void canReconnectToOldLeaderWithSameLeaderAddress() throws Exception {
final JobID jobId = new JobID();
final SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService();
final TestingHighAvailabilityServices haServices = new TestingHighAvailabilityServicesBuilder().setJobMasterLeaderRetrieverFunction(ignored -> leaderRetrievalService).build();
final TestingJobMasterGateway jobMasterGateway = registerJobMaster();
final BlockingQueue<JobID> leadershipQueue = new ArrayBlockingQueue<>(1);
final TestingJobLeaderListener testingJobLeaderListener = new TestingJobLeaderListener(leadershipQueue::offer);
final JobLeaderService jobLeaderService = createAndStartJobLeaderService(haServices, testingJobLeaderListener);
try {
jobLeaderService.addJob(jobId, jobMasterGateway.getAddress());
final UUID leaderSessionId = UUID.randomUUID();
leaderRetrievalService.notifyListener(jobMasterGateway.getAddress(), leaderSessionId);
// wait for the first leadership
assertThat(leadershipQueue.take(), is(jobId));
// revoke the leadership
leaderRetrievalService.notifyListener(null, null);
testingJobLeaderListener.waitUntilJobManagerLostLeadership();
leaderRetrievalService.notifyListener(jobMasterGateway.getAddress(), leaderSessionId);
// check that we obtain the leadership a second time
assertThat(leadershipQueue.take(), is(jobId));
} finally {
jobLeaderService.stop();
}
}
use of org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService in project flink by apache.
the class DefaultJobLeaderServiceTest method rejectedJobManagerRegistrationCallsJobLeaderListener.
@Test
public void rejectedJobManagerRegistrationCallsJobLeaderListener() throws Exception {
final SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService();
final TestingHighAvailabilityServices haServices = new TestingHighAvailabilityServicesBuilder().setJobMasterLeaderRetrieverFunction(ignored -> leaderRetrievalService).build();
final JobID jobId = new JobID();
final CompletableFuture<JobID> rejectedRegistrationFuture = new CompletableFuture<>();
final TestingJobLeaderListener testingJobLeaderListener = new TestingJobLeaderListener(ignored -> {
}, rejectedRegistrationFuture::complete);
final JobLeaderService jobLeaderService = createAndStartJobLeaderService(haServices, testingJobLeaderListener);
final TestingJobMasterGateway jobMasterGateway = new TestingJobMasterGatewayBuilder().setRegisterTaskManagerFunction((jobID, taskManagerRegistrationInformation) -> CompletableFuture.completedFuture(new JMTMRegistrationRejection("foobar"))).build();
rpcServiceResource.getTestingRpcService().registerGateway(jobMasterGateway.getAddress(), jobMasterGateway);
try {
jobLeaderService.addJob(jobId, "foobar");
leaderRetrievalService.notifyListener(jobMasterGateway.getAddress(), jobMasterGateway.getFencingToken().toUUID());
assertThat(rejectedRegistrationFuture.get(), is(jobId));
} finally {
jobLeaderService.stop();
}
}
Aggregations