use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.
the class DispatcherResourceCleanupTest method testJobSubmissionUnderSameJobId.
/**
* Tests that the previous JobManager needs to be completely terminated before a new job with
* the same {@link JobID} is started.
*/
@Test
public void testJobSubmissionUnderSameJobId() throws Exception {
final TestingJobManagerRunnerFactory jobManagerRunnerFactory = startDispatcherAndSubmitJob(1);
final TestingJobManagerRunner testingJobManagerRunner = jobManagerRunnerFactory.takeCreatedJobManagerRunner();
suspendJob(testingJobManagerRunner);
// wait until termination JobManagerRunner closeAsync has been called.
// this is necessary to avoid race conditions with completion of the 1st job and the
// submission of the 2nd job (DuplicateJobSubmissionException).
testingJobManagerRunner.getCloseAsyncCalledLatch().await();
final CompletableFuture<Acknowledge> submissionFuture = dispatcherGateway.submitJob(jobGraph, timeout);
try {
submissionFuture.get(10L, TimeUnit.MILLISECONDS);
fail("The job submission future should not complete until the previous JobManager " + "termination future has been completed.");
} catch (TimeoutException ignored) {
// expected
} finally {
testingJobManagerRunner.completeTerminationFuture();
}
assertThat(submissionFuture.get(), equalTo(Acknowledge.get()));
}
use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.
the class DispatcherResourceCleanupTest method testLocalCleanupWhenJobNotFinished.
@Test
public void testLocalCleanupWhenJobNotFinished() throws Exception {
final TestingJobManagerRunnerFactory jobManagerRunnerFactory = startDispatcherAndSubmitJob();
// job not finished
final TestingJobManagerRunner testingJobManagerRunner = jobManagerRunnerFactory.takeCreatedJobManagerRunner();
suspendJob(testingJobManagerRunner);
assertLocalCleanupTriggered(jobId);
}
use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.
the class MiniDispatcherTest method testShutdownIfJobCancelledInNormalMode.
@Test
public void testShutdownIfJobCancelledInNormalMode() throws Exception {
final MiniDispatcher miniDispatcher = createMiniDispatcher(ClusterEntrypoint.ExecutionMode.NORMAL);
miniDispatcher.start();
try {
// wait until we have submitted the job
final TestingJobManagerRunner testingJobManagerRunner = testingJobManagerRunnerFactory.takeCreatedJobManagerRunner();
assertFalse(miniDispatcher.getTerminationFuture().isDone());
final DispatcherGateway dispatcherGateway = miniDispatcher.getSelfGateway(DispatcherGateway.class);
dispatcherGateway.cancelJob(jobGraph.getJobID(), Time.seconds(10L));
testingJobManagerRunner.completeResultFuture(new ExecutionGraphInfo(new ArchivedExecutionGraphBuilder().setJobID(jobGraph.getJobID()).setState(JobStatus.CANCELED).build()));
ApplicationStatus applicationStatus = miniDispatcher.getShutDownFuture().get();
assertThat(applicationStatus, is(ApplicationStatus.CANCELED));
} finally {
RpcUtils.terminateRpcEndpoint(miniDispatcher, timeout);
}
}
use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.
the class DispatcherTest method testJobCleanupWithoutRecoveredJobGraph.
@Test
public void testJobCleanupWithoutRecoveredJobGraph() throws Exception {
final JobID jobIdOfRecoveredDirtyJobs = new JobID();
final TestingJobMasterServiceLeadershipRunnerFactory jobManagerRunnerFactory = new TestingJobMasterServiceLeadershipRunnerFactory();
final TestingCleanupRunnerFactory cleanupRunnerFactory = new TestingCleanupRunnerFactory();
final OneShotLatch dispatcherBootstrapLatch = new OneShotLatch();
dispatcher = createTestingDispatcherBuilder().setJobManagerRunnerFactory(jobManagerRunnerFactory).setCleanupRunnerFactory(cleanupRunnerFactory).setRecoveredDirtyJobs(Collections.singleton(new JobResult.Builder().jobId(jobIdOfRecoveredDirtyJobs).applicationStatus(ApplicationStatus.SUCCEEDED).netRuntime(1).build())).setDispatcherBootstrapFactory((ignoredDispatcherGateway, ignoredScheduledExecutor, ignoredFatalErrorHandler) -> {
dispatcherBootstrapLatch.trigger();
return new NoOpDispatcherBootstrap();
}).build();
dispatcher.start();
dispatcherBootstrapLatch.await();
final TestingJobManagerRunner cleanupRunner = cleanupRunnerFactory.takeCreatedJobManagerRunner();
assertThat("The CleanupJobManagerRunner has the wrong job ID attached.", cleanupRunner.getJobID(), is(jobIdOfRecoveredDirtyJobs));
assertThat("No JobMaster should have been started.", jobManagerRunnerFactory.getQueueSize(), is(0));
}
use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.
the class DispatcherTest method testFatalErrorIfRecoveredJobsCannotBeStarted.
/**
* Tests that the {@link Dispatcher} fails fatally if the recovered jobs cannot be started. See
* FLINK-9097.
*/
@Test
public void testFatalErrorIfRecoveredJobsCannotBeStarted() throws Exception {
final FlinkException testException = new FlinkException("Test exception");
jobMasterLeaderElectionService.isLeader(UUID.randomUUID());
final TestingJobMasterServiceLeadershipRunnerFactory jobManagerRunnerFactory = new TestingJobMasterServiceLeadershipRunnerFactory();
dispatcher = createTestingDispatcherBuilder().setJobManagerRunnerFactory(jobManagerRunnerFactory).setRecoveredJobs(Collections.singleton(JobGraphTestUtils.emptyJobGraph())).build();
dispatcher.start();
final TestingFatalErrorHandler fatalErrorHandler = testingFatalErrorHandlerResource.getFatalErrorHandler();
final TestingJobManagerRunner testingJobManagerRunner = jobManagerRunnerFactory.takeCreatedJobManagerRunner();
// Let the initialization of the JobManagerRunner fail
testingJobManagerRunner.completeResultFuture(JobManagerRunnerResult.forInitializationFailure(new ExecutionGraphInfo(ArchivedExecutionGraph.createSparseArchivedExecutionGraph(jobId, jobGraph.getName(), JobStatus.FAILED, testException, jobGraph.getCheckpointingSettings(), 1L)), testException));
final Throwable error = fatalErrorHandler.getErrorFuture().get(TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
assertThat(ExceptionUtils.findThrowableWithMessage(error, testException.getMessage()).isPresent(), is(true));
fatalErrorHandler.clearError();
}
Aggregations