use of org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices in project flink by apache.
the class DefaultJobLeaderIdServiceTest method testLeaderFutureWaitsForValidLeader.
/**
* Tests that the leaderId future is only completed once the service is notified about an actual
* leader being elected. Specifically, it tests that the future is not completed if the
* leadership was revoked without a new leader having been elected.
*/
@Test(timeout = 10000)
public void testLeaderFutureWaitsForValidLeader() throws Exception {
final JobID jobId = new JobID();
TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServices();
SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService(null, null);
highAvailabilityServices.setJobMasterLeaderRetriever(jobId, leaderRetrievalService);
JobLeaderIdService jobLeaderIdService = new DefaultJobLeaderIdService(highAvailabilityServices, new ManuallyTriggeredScheduledExecutor(), Time.milliseconds(5000L));
jobLeaderIdService.start(new NoOpJobLeaderIdActions());
jobLeaderIdService.addJob(jobId);
// elect some leader
leaderRetrievalService.notifyListener("foo", UUID.randomUUID());
// notify about leadership loss
leaderRetrievalService.notifyListener(null, null);
final CompletableFuture<JobMasterId> leaderIdFuture = jobLeaderIdService.getLeaderId(jobId);
// there is currently no leader, so this should not be completed
assertThat(leaderIdFuture.isDone(), is(false));
// elect a new leader
final UUID newLeaderId = UUID.randomUUID();
leaderRetrievalService.notifyListener("foo", newLeaderId);
assertThat(leaderIdFuture.get(), is(JobMasterId.fromUuidOrNull(newLeaderId)));
}
use of org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices in project flink by apache.
the class DefaultJobLeaderIdServiceTest method testIsStarted.
/**
* Tests that whether the service has been started.
*/
@Test
public void testIsStarted() throws Exception {
final JobID jobId = new JobID();
TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServices();
SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService(null, null);
highAvailabilityServices.setJobMasterLeaderRetriever(jobId, leaderRetrievalService);
ScheduledExecutor scheduledExecutor = mock(ScheduledExecutor.class);
Time timeout = Time.milliseconds(5000L);
JobLeaderIdActions jobLeaderIdActions = mock(JobLeaderIdActions.class);
DefaultJobLeaderIdService jobLeaderIdService = new DefaultJobLeaderIdService(highAvailabilityServices, scheduledExecutor, timeout);
assertFalse(jobLeaderIdService.isStarted());
jobLeaderIdService.start(jobLeaderIdActions);
assertTrue(jobLeaderIdService.isStarted());
jobLeaderIdService.stop();
assertFalse(jobLeaderIdService.isStarted());
}
use of org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices in project flink by apache.
the class DefaultJobLeaderIdServiceTest method testRemovingJob.
/**
* Tests that removing a job completes the job leader id future exceptionally.
*/
@Test(timeout = 10000)
public void testRemovingJob() throws Exception {
final JobID jobId = new JobID();
TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServices();
SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService(null, null);
highAvailabilityServices.setJobMasterLeaderRetriever(jobId, leaderRetrievalService);
ScheduledExecutor scheduledExecutor = mock(ScheduledExecutor.class);
Time timeout = Time.milliseconds(5000L);
JobLeaderIdActions jobLeaderIdActions = mock(JobLeaderIdActions.class);
JobLeaderIdService jobLeaderIdService = new DefaultJobLeaderIdService(highAvailabilityServices, scheduledExecutor, timeout);
jobLeaderIdService.start(jobLeaderIdActions);
jobLeaderIdService.addJob(jobId);
CompletableFuture<JobMasterId> leaderIdFuture = jobLeaderIdService.getLeaderId(jobId);
// remove the job before we could find a leader
jobLeaderIdService.removeJob(jobId);
assertFalse(jobLeaderIdService.containsJob(jobId));
try {
leaderIdFuture.get();
fail("The leader id future should be completed exceptionally.");
} catch (ExecutionException ignored) {
// expected exception
}
}
use of org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices in project flink by apache.
the class DefaultJobLeaderIdServiceTest method testAddingJob.
/**
* Tests adding a job and finding out its leader id.
*/
@Test(timeout = 10000)
public void testAddingJob() throws Exception {
final JobID jobId = new JobID();
final String address = "foobar";
final JobMasterId leaderId = JobMasterId.generate();
TestingHighAvailabilityServices highAvailabilityServices = new TestingHighAvailabilityServices();
SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService(null, null);
highAvailabilityServices.setJobMasterLeaderRetriever(jobId, leaderRetrievalService);
ScheduledExecutor scheduledExecutor = mock(ScheduledExecutor.class);
Time timeout = Time.milliseconds(5000L);
JobLeaderIdActions jobLeaderIdActions = mock(JobLeaderIdActions.class);
JobLeaderIdService jobLeaderIdService = new DefaultJobLeaderIdService(highAvailabilityServices, scheduledExecutor, timeout);
jobLeaderIdService.start(jobLeaderIdActions);
jobLeaderIdService.addJob(jobId);
CompletableFuture<JobMasterId> leaderIdFuture = jobLeaderIdService.getLeaderId(jobId);
// notify the leader id service about the new leader
leaderRetrievalService.notifyListener(address, leaderId.toUUID());
assertEquals(leaderId, leaderIdFuture.get());
assertTrue(jobLeaderIdService.containsJob(jobId));
}
use of org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices in project flink by apache.
the class DefaultJobLeaderServiceTest method removeJobWithFailingLeaderRetrievalServiceStopWillStopListeningToLeaderNotifications.
@Test
public void removeJobWithFailingLeaderRetrievalServiceStopWillStopListeningToLeaderNotifications() throws Exception {
final FailingSettableLeaderRetrievalService leaderRetrievalService = new FailingSettableLeaderRetrievalService();
final TestingHighAvailabilityServices haServices = new TestingHighAvailabilityServicesBuilder().setJobMasterLeaderRetrieverFunction(ignored -> leaderRetrievalService).build();
final JobID jobId = new JobID();
final CompletableFuture<JobID> newLeaderFuture = new CompletableFuture<>();
final TestingJobLeaderListener testingJobLeaderListener = new TestingJobLeaderListener(newLeaderFuture::complete);
final TestingJobMasterGateway jobMasterGateway = new TestingJobMasterGatewayBuilder().build();
rpcServiceResource.getTestingRpcService().registerGateway(jobMasterGateway.getAddress(), jobMasterGateway);
final JobLeaderService jobLeaderService = createAndStartJobLeaderService(haServices, testingJobLeaderListener);
try {
jobLeaderService.addJob(jobId, "foobar");
jobLeaderService.removeJob(jobId);
leaderRetrievalService.notifyListener(jobMasterGateway.getAddress(), jobMasterGateway.getFencingToken().toUUID());
try {
newLeaderFuture.get(10, TimeUnit.MILLISECONDS);
fail("The leader future should not be completed.");
} catch (TimeoutException expected) {
}
} finally {
jobLeaderService.stop();
}
}
Aggregations