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);
}
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());
}
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);
}
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);
}
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());
}
Aggregations