Search in sources :

Example 6 with TestingJobManagerRunner

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()));
}
Also used : Acknowledge(org.apache.flink.runtime.messages.Acknowledge) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 7 with TestingJobManagerRunner

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);
}
Also used : TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) Test(org.junit.Test)

Example 8 with TestingJobManagerRunner

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);
    }
}
Also used : ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) Test(org.junit.Test)

Example 9 with TestingJobManagerRunner

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));
}
Also used : JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestingCleanupRunnerFactory(org.apache.flink.runtime.dispatcher.cleanup.TestingCleanupRunnerFactory) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 10 with TestingJobManagerRunner

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();
}
Also used : TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Aggregations

TestingJobManagerRunner (org.apache.flink.runtime.jobmaster.TestingJobManagerRunner)22 Test (org.junit.Test)16 ExecutionGraphInfo (org.apache.flink.runtime.scheduler.ExecutionGraphInfo)7 ArchivedExecutionGraphBuilder (org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder)5 JobID (org.apache.flink.api.common.JobID)4 FlinkException (org.apache.flink.util.FlinkException)4 ArrayDeque (java.util.ArrayDeque)3 TimeoutException (java.util.concurrent.TimeoutException)3 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)3 ArchivedExecutionGraph (org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph)3 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)3 JobManagerRunner (org.apache.flink.runtime.jobmaster.JobManagerRunner)3 Test (org.junit.jupiter.api.Test)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Optional (java.util.Optional)2 Queue (java.util.Queue)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2