Search in sources :

Example 6 with TestingDispatcherGateway

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

the class JarRunHandlerParameterTest method setup.

@BeforeClass
public static void setup() throws Exception {
    init();
    final GatewayRetriever<TestingDispatcherGateway> gatewayRetriever = () -> CompletableFuture.completedFuture(restfulGateway);
    final Time timeout = Time.seconds(10);
    final Map<String, String> responseHeaders = Collections.emptyMap();
    final Executor executor = TestingUtils.defaultExecutor();
    final Path jarLocation = Paths.get(System.getProperty("targetDir"));
    final String parameterProgramWithEagerSink = "parameter-program-with-eager-sink.jar";
    jarWithEagerSink = Files.copy(jarLocation.resolve(parameterProgramWithEagerSink), jarDir.resolve("program-with-eager-sink.jar"));
    handler = new JarRunHandler(gatewayRetriever, timeout, responseHeaders, JarRunHeaders.getInstance(), jarDir, new Configuration(), executor, ConfigurationVerifyingDetachedApplicationRunner::new);
}
Also used : Path(java.nio.file.Path) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) EmbeddedExecutor(org.apache.flink.client.deployment.application.executors.EmbeddedExecutor) Executor(java.util.concurrent.Executor) Configuration(org.apache.flink.configuration.Configuration) Time(org.apache.flink.api.common.time.Time) Matchers.containsString(org.hamcrest.Matchers.containsString) BeforeClass(org.junit.BeforeClass)

Example 7 with TestingDispatcherGateway

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

the class ApplicationDispatcherBootstrapTest method testErrorHandlerIsCalledWhenApplicationStatusIsUnknown.

@Test
public void testErrorHandlerIsCalledWhenApplicationStatusIsUnknown() throws Exception {
    // we're "listening" on this to be completed to verify that the cluster
    // is being shut down from the ApplicationDispatcherBootstrap
    final AtomicBoolean shutdownCalled = new AtomicBoolean(false);
    final TestingDispatcherGateway.Builder dispatcherBuilder = canceledJobGatewayBuilder().setRequestJobResultFunction(jobID -> CompletableFuture.completedFuture(createUnknownJobResult(jobID))).setClusterShutdownFunction(status -> {
        shutdownCalled.set(true);
        return CompletableFuture.completedFuture(Acknowledge.get());
    });
    final TestingDispatcherGateway dispatcherGateway = dispatcherBuilder.build();
    final CompletableFuture<Void> errorHandlerFuture = new CompletableFuture<>();
    final ApplicationDispatcherBootstrap bootstrap = createApplicationDispatcherBootstrap(3, dispatcherGateway, scheduledExecutor, errorHandlerFuture::completeExceptionally);
    // check that bootstrap shutdown completes exceptionally
    assertException(bootstrap.getApplicationCompletionFuture(), UnsuccessfulExecutionException.class);
    // and exception gets propagated to error handler
    assertException(bootstrap.getApplicationCompletionFuture(), UnsuccessfulExecutionException.class);
    // and cluster didn't shut down
    assertFalse(shutdownCalled.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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with TestingDispatcherGateway

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

the class ApplicationDispatcherBootstrapTest method testShutdownDisabled.

@ParameterizedTest
@EnumSource(value = JobStatus.class, names = { "FINISHED", "CANCELED", "FAILED" })
public void testShutdownDisabled(JobStatus jobStatus) throws Exception {
    final Configuration configurationUnderTest = getConfiguration();
    configurationUnderTest.set(DeploymentOptions.SHUTDOWN_ON_APPLICATION_FINISH, false);
    final TestingDispatcherGateway dispatcherGateway = dispatcherGatewayBuilder(jobStatus).setClusterShutdownFunction(status -> {
        fail("Cluster shutdown should not be called");
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).build();
    ApplicationDispatcherBootstrap bootstrap = createApplicationDispatcherBootstrap(configurationUnderTest, dispatcherGateway, scheduledExecutor);
    // Wait until bootstrap is finished to make sure cluster shutdown isn't called
    bootstrap.getBootstrapCompletionFuture().get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
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) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Configuration(org.apache.flink.configuration.Configuration) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with TestingDispatcherGateway

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

the class ApplicationDispatcherBootstrapTest method testErrorHandlerIsCalled.

private void testErrorHandlerIsCalled(Supplier<CompletableFuture<Acknowledge>> shutdownFunction) throws Exception {
    final TestingDispatcherGateway.Builder dispatcherBuilder = TestingDispatcherGateway.newBuilder().setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get())).setRequestJobStatusFunction(jobId -> CompletableFuture.completedFuture(JobStatus.FINISHED)).setRequestJobResultFunction(jobId -> CompletableFuture.completedFuture(createJobResult(jobId, ApplicationStatus.SUCCEEDED))).setClusterShutdownFunction(status -> shutdownFunction.get());
    // we're "listening" on this to be completed to verify that the error handler is called.
    // In production, this will shut down the cluster with an exception.
    final CompletableFuture<Void> errorHandlerFuture = new CompletableFuture<>();
    final TestingDispatcherGateway dispatcherGateway = dispatcherBuilder.build();
    final ApplicationDispatcherBootstrap bootstrap = createApplicationDispatcherBootstrap(3, dispatcherGateway, scheduledExecutor, errorHandlerFuture::completeExceptionally);
    final CompletableFuture<Acknowledge> completionFuture = bootstrap.getBootstrapCompletionFuture();
    // we call the error handler
    assertException(errorHandlerFuture, FlinkRuntimeException.class);
    // we return a future that is completed exceptionally
    assertException(completionFuture, FlinkRuntimeException.class);
}
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) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) CompletableFuture(java.util.concurrent.CompletableFuture) Acknowledge(org.apache.flink.runtime.messages.Acknowledge)

Example 10 with TestingDispatcherGateway

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

the class JarSubmissionITCase method testJarSubmission.

@Test
public void testJarSubmission() throws Exception {
    final TestingDispatcherGateway restfulGateway = TestingDispatcherGateway.newBuilder().setBlobServerPort(blobServerResource.getBlobServerPort()).setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get())).build();
    final JarHandlers handlers = new JarHandlers(temporaryFolder.newFolder().toPath(), restfulGateway);
    final JarUploadHandler uploadHandler = handlers.uploadHandler;
    final JarListHandler listHandler = handlers.listHandler;
    final JarPlanHandler planHandler = handlers.planHandler;
    final JarRunHandler runHandler = handlers.runHandler;
    final JarDeleteHandler deleteHandler = handlers.deleteHandler;
    // targetDir property is set via surefire configuration
    final Path originalJar = Paths.get(System.getProperty("targetDir")).resolve("test-program.jar");
    final Path jar = Files.copy(originalJar, temporaryFolder.getRoot().toPath().resolve("test-program.jar"));
    final String storedJarPath = uploadJar(uploadHandler, jar, restfulGateway);
    final String storedJarName = Paths.get(storedJarPath).getFileName().toString();
    final JarListInfo postUploadListResponse = listJars(listHandler, restfulGateway);
    Assert.assertEquals(1, postUploadListResponse.jarFileList.size());
    final JarListInfo.JarFileInfo listEntry = postUploadListResponse.jarFileList.iterator().next();
    Assert.assertEquals(jar.getFileName().toString(), listEntry.name);
    Assert.assertEquals(storedJarName, listEntry.id);
    final JobPlanInfo planResponse = showPlan(planHandler, storedJarName, restfulGateway);
    // we're only interested in the core functionality so checking for a small detail is
    // sufficient
    Assert.assertThat(planResponse.getJsonPlan(), containsString("TestProgram.java:28"));
    runJar(runHandler, storedJarName, restfulGateway);
    deleteJar(deleteHandler, storedJarName, restfulGateway);
    final JarListInfo postDeleteListResponse = listJars(listHandler, restfulGateway);
    Assert.assertEquals(0, postDeleteListResponse.jarFileList.size());
}
Also used : JarHandlers.deleteJar(org.apache.flink.runtime.webmonitor.handlers.JarHandlers.deleteJar) Files(java.nio.file.Files) JarHandlers.showPlan(org.apache.flink.runtime.webmonitor.handlers.JarHandlers.showPlan) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) BlobServerResource(org.apache.flink.runtime.util.BlobServerResource) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) JobPlanInfo(org.apache.flink.runtime.rest.messages.JobPlanInfo) JarHandlers.listJars(org.apache.flink.runtime.webmonitor.handlers.JarHandlers.listJars) Rule(org.junit.Rule) JarHandlers.uploadJar(org.apache.flink.runtime.webmonitor.handlers.JarHandlers.uploadJar) Paths(java.nio.file.Paths) TestLogger(org.apache.flink.util.TestLogger) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) Assert(org.junit.Assert) Path(java.nio.file.Path) JarHandlers.runJar(org.apache.flink.runtime.webmonitor.handlers.JarHandlers.runJar) Matchers.containsString(org.hamcrest.Matchers.containsString) TemporaryFolder(org.junit.rules.TemporaryFolder) Path(java.nio.file.Path) TestingDispatcherGateway(org.apache.flink.runtime.webmonitor.TestingDispatcherGateway) JobPlanInfo(org.apache.flink.runtime.rest.messages.JobPlanInfo) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

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