Search in sources :

Example 1 with TestingDispatcherGateway

use of org.apache.flink.runtime.webmonitor.TestingDispatcherGateway in project flink by apache.

the class JarHandlerTest method runTest.

private static void runTest(String expectedCapturedStdOut, String expectedCapturedStdErr) throws Exception {
    final TestingDispatcherGateway restfulGateway = TestingDispatcherGateway.newBuilder().build();
    final JarHandlers handlers = new JarHandlers(TMP.newFolder().toPath(), restfulGateway);
    final Path originalJar = Paths.get(System.getProperty("targetDir")).resolve(JAR_NAME);
    final Path jar = Files.copy(originalJar, TMP.newFolder().toPath().resolve(JAR_NAME));
    final String storedJarPath = JarHandlers.uploadJar(handlers.uploadHandler, jar, restfulGateway);
    final String storedJarName = Paths.get(storedJarPath).getFileName().toString();
    try {
        JarHandlers.showPlan(handlers.planHandler, storedJarName, restfulGateway);
        Assert.fail("Should have failed with an exception.");
    } catch (Exception e) {
        Optional<ProgramInvocationException> expected = ExceptionUtils.findThrowable(e, ProgramInvocationException.class);
        if (expected.isPresent()) {
            String message = expected.get().getMessage();
            // original cause is preserved in stack trace
            assertThat(message, containsString("The program plan could not be fetched - the program aborted pre-maturely"));
            // implies the jar was registered for the job graph (otherwise the jar name would
            // not occur in the exception)
            assertThat(message, containsString(JAR_NAME));
            // ensure that no stdout/stderr has been captured
            assertThat(message, containsString("System.out: " + expectedCapturedStdOut));
            assertThat(message, containsString("System.err: " + expectedCapturedStdErr));
        } else {
            throw e;
        }
    }
}
Also used : Path(java.nio.file.Path) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Optional(java.util.Optional) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException)

Example 2 with TestingDispatcherGateway

use of org.apache.flink.runtime.webmonitor.TestingDispatcherGateway in project flink by apache.

the class SessionDispatcherLeaderProcessTest method onAddedJobGraph_submitsRecoveredJob.

@Test
public void onAddedJobGraph_submitsRecoveredJob() throws Exception {
    final CompletableFuture<JobGraph> submittedJobFuture = new CompletableFuture<>();
    final TestingDispatcherGateway testingDispatcherGateway = TestingDispatcherGateway.newBuilder().setSubmitFunction(submittedJob -> {
        submittedJobFuture.complete(submittedJob);
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).build();
    dispatcherServiceFactory = createFactoryBasedOnGenericSupplier(() -> TestingDispatcherGatewayService.newBuilder().setDispatcherGateway(testingDispatcherGateway).build());
    try (final SessionDispatcherLeaderProcess dispatcherLeaderProcess = createDispatcherLeaderProcess()) {
        dispatcherLeaderProcess.start();
        // wait first for the dispatcher service to be created
        dispatcherLeaderProcess.getDispatcherGateway().get();
        jobGraphStore.putJobGraph(JOB_GRAPH);
        dispatcherLeaderProcess.onAddedJobGraph(JOB_GRAPH.getJobID());
        final JobGraph submittedJobGraph = submittedJobFuture.get();
        assertThat(submittedJobGraph.getJobID()).isEqualTo(JOB_GRAPH.getJobID());
    }
}
Also used : OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) FlinkException(org.apache.flink.util.FlinkException) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TestingJobGraphStore(org.apache.flink.runtime.testutils.TestingJobGraphStore) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AfterAll(org.junit.jupiter.api.AfterAll) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) FlinkAssertions(org.apache.flink.core.testutils.FlinkAssertions) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) ThrowingConsumer(org.apache.flink.util.function.ThrowingConsumer) FlinkAssertions.anyCauseMatches(org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches) ExecutorService(java.util.concurrent.ExecutorService) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) JobID(org.apache.flink.api.common.JobID) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) STREAM_THROWABLE(org.apache.flink.core.testutils.FlinkAssertions.STREAM_THROWABLE) JobGraphStore(org.apache.flink.runtime.jobmanager.JobGraphStore) Collections(java.util.Collections) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CompletableFuture(java.util.concurrent.CompletableFuture) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Test(org.junit.jupiter.api.Test)

Example 3 with TestingDispatcherGateway

use of org.apache.flink.runtime.webmonitor.TestingDispatcherGateway in project flink by apache.

the class ApplicationDispatcherBootstrapTest method testClusterIsShutdownInAttachedModeWhenJobCancelled.

@Test
public void testClusterIsShutdownInAttachedModeWhenJobCancelled() throws Exception {
    final CompletableFuture<ApplicationStatus> clusterShutdown = new CompletableFuture<>();
    final TestingDispatcherGateway dispatcherGateway = canceledJobGatewayBuilder().setClusterShutdownFunction(status -> {
        clusterShutdown.complete(status);
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).build();
    final PackagedProgram program = getProgram(2);
    final Configuration configuration = getConfiguration();
    configuration.set(DeploymentOptions.ATTACHED, true);
    final ApplicationDispatcherBootstrap bootstrap = new ApplicationDispatcherBootstrap(program, Collections.emptyList(), configuration, dispatcherGateway, scheduledExecutor, e -> {
    });
    final CompletableFuture<Void> applicationFuture = bootstrap.getApplicationCompletionFuture();
    assertException(applicationFuture, UnsuccessfulExecutionException.class);
    assertEquals(clusterShutdown.get(), ApplicationStatus.CANCELED);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ExceptionUtils(org.apache.flink.util.ExceptionUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) FailingJob(org.apache.flink.client.testjar.FailingJob) ScheduledExecutor(org.apache.flink.util.concurrent.ScheduledExecutor) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Optional(java.util.Optional) PackagedProgram(org.apache.flink.client.program.PackagedProgram) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlinkException(org.apache.flink.util.FlinkException) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EnumSource(org.junit.jupiter.params.provider.EnumSource) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Supplier(java.util.function.Supplier) EmbeddedExecutor(org.apache.flink.client.deployment.application.executors.EmbeddedExecutor) PipelineOptionsInternal(org.apache.flink.configuration.PipelineOptionsInternal) MultiExecuteJob(org.apache.flink.client.testjar.MultiExecuteJob) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) HighAvailabilityMode(org.apache.flink.runtime.jobmanager.HighAvailabilityMode) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Configuration(org.apache.flink.configuration.Configuration) JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) JobID(org.apache.flink.api.common.JobID) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) PackagedProgram(org.apache.flink.client.program.PackagedProgram) CompletableFuture(java.util.concurrent.CompletableFuture) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Configuration(org.apache.flink.configuration.Configuration) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TestingDispatcherGateway

use of org.apache.flink.runtime.webmonitor.TestingDispatcherGateway in project flink by apache.

the class ApplicationDispatcherBootstrapTest method testSubmitFailedJobOnApplicationError.

private void testSubmitFailedJobOnApplicationError(Configuration configuration, BiConsumer<JobID, Throwable> failedJobAssertion) throws Exception {
    final CompletableFuture<Void> submitted = new CompletableFuture<>();
    final TestingDispatcherGateway dispatcherGateway = TestingDispatcherGateway.newBuilder().setSubmitFailedFunction((jobId, jobName, t) -> {
        try {
            failedJobAssertion.accept(jobId, t);
            submitted.complete(null);
            return CompletableFuture.completedFuture(Acknowledge.get());
        } catch (Throwable assertion) {
            submitted.completeExceptionally(assertion);
            return FutureUtils.completedExceptionally(assertion);
        }
    }).setRequestJobStatusFunction(jobId -> submitted.thenApply(ignored -> JobStatus.FAILED)).setRequestJobResultFunction(jobId -> submitted.thenApply(ignored -> createJobResult(jobId, ApplicationStatus.FAILED))).build();
    final ApplicationDispatcherBootstrap bootstrap = new ApplicationDispatcherBootstrap(FailingJob.getProgram(), Collections.emptyList(), configuration, dispatcherGateway, scheduledExecutor, exception -> {
    });
    bootstrap.getBootstrapCompletionFuture().get();
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ExceptionUtils(org.apache.flink.util.ExceptionUtils) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) FailingJob(org.apache.flink.client.testjar.FailingJob) ScheduledExecutor(org.apache.flink.util.concurrent.ScheduledExecutor) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) Executors(java.util.concurrent.Executors) ExecutorUtils(org.apache.flink.util.ExecutorUtils) Test(org.junit.jupiter.api.Test) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Optional(java.util.Optional) PackagedProgram(org.apache.flink.client.program.PackagedProgram) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlinkException(org.apache.flink.util.FlinkException) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EnumSource(org.junit.jupiter.params.provider.EnumSource) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) Supplier(java.util.function.Supplier) EmbeddedExecutor(org.apache.flink.client.deployment.application.executors.EmbeddedExecutor) PipelineOptionsInternal(org.apache.flink.configuration.PipelineOptionsInternal) MultiExecuteJob(org.apache.flink.client.testjar.MultiExecuteJob) JobResult(org.apache.flink.runtime.jobmaster.JobResult) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) HighAvailabilityMode(org.apache.flink.runtime.jobmanager.HighAvailabilityMode) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) Configuration(org.apache.flink.configuration.Configuration) JobCancellationException(org.apache.flink.runtime.client.JobCancellationException) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) JobID(org.apache.flink.api.common.JobID) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) CompletableFuture(java.util.concurrent.CompletableFuture) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Example 5 with TestingDispatcherGateway

use of org.apache.flink.runtime.webmonitor.TestingDispatcherGateway in project flink by apache.

the class JobManagerCustomLogHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    initializeFolderStructure();
    final TestingDispatcherGateway dispatcherGateway = TestingDispatcherGateway.newBuilder().build();
    testInstance = new JobManagerCustomLogHandler(() -> CompletableFuture.completedFuture(dispatcherGateway), TestingUtils.TIMEOUT, Collections.emptyMap(), JobManagerCustomLogHeaders.getInstance(), logRoot);
}
Also used : TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Before(org.junit.Before)

Aggregations

TestingDispatcherGateway (org.apache.flink.runtime.webmonitor.TestingDispatcherGateway)13 CompletableFuture (java.util.concurrent.CompletableFuture)9 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)9 Test (org.junit.jupiter.api.Test)9 Collections (java.util.Collections)8 Executors (java.util.concurrent.Executors)8 TimeUnit (java.util.concurrent.TimeUnit)8 Supplier (java.util.function.Supplier)8 JobID (org.apache.flink.api.common.JobID)8 DuplicateJobSubmissionException (org.apache.flink.runtime.client.DuplicateJobSubmissionException)8 JobResult (org.apache.flink.runtime.jobmaster.JobResult)8 ExecutorUtils (org.apache.flink.util.ExecutorUtils)8 FlinkException (org.apache.flink.util.FlinkException)8 TestLoggerExtension (org.apache.flink.util.TestLoggerExtension)8 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)8 AfterEach (org.junit.jupiter.api.AfterEach)8 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)8 Optional (java.util.Optional)6 EmbeddedExecutor (org.apache.flink.client.deployment.application.executors.EmbeddedExecutor)6 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)6