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