Search in sources :

Example 16 with TestingJobManagerRunner

use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.

the class DefaultDispatcherRunnerITCase method leaderChange_withBlockingJobManagerTermination_doesNotAffectNewLeader.

/**
 * See FLINK-11843. This is a probabilistic test which needs to be executed several times to
 * fail.
 */
@Test
public void leaderChange_withBlockingJobManagerTermination_doesNotAffectNewLeader() throws Exception {
    final TestingJobMasterServiceLeadershipRunnerFactory jobManagerRunnerFactory = new TestingJobMasterServiceLeadershipRunnerFactory(1);
    final TestingCleanupRunnerFactory cleanupRunnerFactory = new TestingCleanupRunnerFactory();
    dispatcherRunnerFactory = DefaultDispatcherRunnerFactory.createSessionRunner(new TestingDispatcherFactory(jobManagerRunnerFactory, cleanupRunnerFactory));
    jobGraphStore = new SingleJobJobGraphStore(jobGraph);
    try (final DispatcherRunner dispatcherRunner = createDispatcherRunner()) {
        // initial run
        dispatcherLeaderElectionService.isLeader(UUID.randomUUID()).get();
        final TestingJobManagerRunner testingJobManagerRunner = jobManagerRunnerFactory.takeCreatedJobManagerRunner();
        dispatcherLeaderElectionService.notLeader();
        LOG.info("Re-grant leadership first time.");
        dispatcherLeaderElectionService.isLeader(UUID.randomUUID());
        // give the Dispatcher some time to recover jobs
        Thread.sleep(1L);
        dispatcherLeaderElectionService.notLeader();
        LOG.info("Re-grant leadership second time.");
        final UUID leaderSessionId = UUID.randomUUID();
        final CompletableFuture<UUID> leaderFuture = dispatcherLeaderElectionService.isLeader(leaderSessionId);
        assertThat(leaderFuture.isDone(), is(false));
        LOG.info("Complete the termination of the first job manager runner.");
        testingJobManagerRunner.completeTerminationFuture();
        assertThat(leaderFuture.get(TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS), is(equalTo(leaderSessionId)));
        // Wait for job to recover...
        final DispatcherGateway leaderGateway = rpcServiceResource.getTestingRpcService().connect(dispatcherLeaderElectionService.getAddress(), DispatcherId.fromUuid(leaderSessionId), DispatcherGateway.class).get();
        assertEquals(jobGraph.getJobID(), Iterables.getOnlyElement(leaderGateway.listJobs(TIMEOUT).get()));
    }
}
Also used : TestingJobMasterServiceLeadershipRunnerFactory(org.apache.flink.runtime.dispatcher.TestingJobMasterServiceLeadershipRunnerFactory) SingleJobJobGraphStore(org.apache.flink.runtime.dispatcher.SingleJobJobGraphStore) TestingCleanupRunnerFactory(org.apache.flink.runtime.dispatcher.cleanup.TestingCleanupRunnerFactory) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) UUID(java.util.UUID) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Test(org.junit.Test)

Example 17 with TestingJobManagerRunner

use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.

the class MiniDispatcherTest method testSingleJobRecovery.

/**
 * Tests that the {@link MiniDispatcher} recovers the single job with which it was started.
 */
@Test
public void testSingleJobRecovery() throws Exception {
    final MiniDispatcher miniDispatcher = createMiniDispatcher(ClusterEntrypoint.ExecutionMode.DETACHED);
    miniDispatcher.start();
    try {
        final TestingJobManagerRunner testingJobManagerRunner = testingJobManagerRunnerFactory.takeCreatedJobManagerRunner();
        assertThat(testingJobManagerRunner.getJobID(), is(jobGraph.getJobID()));
    } finally {
        RpcUtils.terminateRpcEndpoint(miniDispatcher, timeout);
    }
}
Also used : TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) Test(org.junit.Test)

Example 18 with TestingJobManagerRunner

use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.

the class MiniDispatcherTest method testDirtyJobResultCleanup.

/**
 * Tests that the {@link MiniDispatcher} recovers the single job with which it was started.
 */
@Test
public void testDirtyJobResultCleanup() throws Exception {
    final JobID jobId = new JobID();
    final MiniDispatcher miniDispatcher = createMiniDispatcher(ClusterEntrypoint.ExecutionMode.DETACHED, null, TestingJobResultStore.createSuccessfulJobResult(jobId));
    miniDispatcher.start();
    try {
        final TestingJobManagerRunner testingCleanupRunner = testingCleanupRunnerFactory.takeCreatedJobManagerRunner();
        assertThat(testingCleanupRunner.getJobID(), is(jobId));
    } finally {
        RpcUtils.terminateRpcEndpoint(miniDispatcher, timeout);
    }
}
Also used : TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 19 with TestingJobManagerRunner

use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.

the class MiniDispatcherTest method testJobResultRetrieval.

/**
 * Tests that the {@link MiniDispatcher} only terminates in {@link
 * ClusterEntrypoint.ExecutionMode#NORMAL} after it has served the {@link
 * org.apache.flink.runtime.jobmaster.JobResult} once.
 */
@Test
public void testJobResultRetrieval() throws Exception {
    final MiniDispatcher miniDispatcher = createMiniDispatcher(ClusterEntrypoint.ExecutionMode.NORMAL);
    miniDispatcher.start();
    try {
        // wait until we have submitted the job
        final TestingJobManagerRunner testingJobManagerRunner = testingJobManagerRunnerFactory.takeCreatedJobManagerRunner();
        testingJobManagerRunner.completeResultFuture(executionGraphInfo);
        assertFalse(miniDispatcher.getTerminationFuture().isDone());
        final DispatcherGateway dispatcherGateway = miniDispatcher.getSelfGateway(DispatcherGateway.class);
        final CompletableFuture<JobResult> jobResultFuture = dispatcherGateway.requestJobResult(jobGraph.getJobID(), timeout);
        final JobResult jobResult = jobResultFuture.get();
        assertThat(jobResult.getJobId(), is(jobGraph.getJobID()));
    } finally {
        RpcUtils.terminateRpcEndpoint(miniDispatcher, timeout);
    }
}
Also used : JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) Test(org.junit.Test)

Example 20 with TestingJobManagerRunner

use of org.apache.flink.runtime.jobmaster.TestingJobManagerRunner in project flink by apache.

the class MiniDispatcherTest method testNotTerminationWithoutGloballyTerminalState.

/**
 * Tests that in detached mode, the {@link MiniDispatcher} will not complete the future that
 * signals job termination if the JobStatus is not globally terminal state.
 */
@Test
public void testNotTerminationWithoutGloballyTerminalState() throws Exception {
    final MiniDispatcher miniDispatcher = createMiniDispatcher(ClusterEntrypoint.ExecutionMode.DETACHED);
    miniDispatcher.start();
    try {
        // wait until we have submitted the job
        final TestingJobManagerRunner testingJobManagerRunner = testingJobManagerRunnerFactory.takeCreatedJobManagerRunner();
        testingJobManagerRunner.completeResultFuture(new ExecutionGraphInfo(new ArchivedExecutionGraphBuilder().setJobID(jobGraph.getJobID()).setState(JobStatus.SUSPENDED).build()));
        testingJobManagerRunner.getTerminationFuture().get();
        Assertions.assertThat(miniDispatcher.getShutDownFuture()).isNotDone();
    } finally {
        RpcUtils.terminateRpcEndpoint(miniDispatcher, timeout);
    }
}
Also used : ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) 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