use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.
the class JobSubmitHandlerTest method testSerializationFailureHandling.
@Test
public void testSerializationFailureHandling() throws Exception {
final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
DispatcherGateway mockGateway = TestingDispatcherGateway.newBuilder().setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get())).build();
JobSubmitHandler handler = new JobSubmitHandler(() -> CompletableFuture.completedFuture(mockGateway), RpcUtils.INF_TIMEOUT, Collections.emptyMap(), TestingUtils.defaultExecutor(), configuration);
JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.toString(), Collections.emptyList(), Collections.emptyList());
try {
handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance()), mockGateway);
Assert.fail();
} catch (RestHandlerException rhe) {
Assert.assertEquals(HttpResponseStatus.BAD_REQUEST, rhe.getHttpResponseStatus());
}
}
use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.
the class JobSubmitHandlerTest method testSuccessfulJobSubmission.
@Test
public void testSuccessfulJobSubmission() throws Exception {
final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
objectOut.writeObject(JobGraphTestUtils.emptyJobGraph());
}
TestingDispatcherGateway.Builder builder = TestingDispatcherGateway.newBuilder();
builder.setBlobServerPort(blobServer.getPort()).setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get())).setHostname("localhost");
DispatcherGateway mockGateway = builder.build();
JobSubmitHandler handler = new JobSubmitHandler(() -> CompletableFuture.completedFuture(mockGateway), RpcUtils.INF_TIMEOUT, Collections.emptyMap(), TestingUtils.defaultExecutor(), configuration);
JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());
handler.handleRequest(HandlerRequest.create(request, EmptyMessageParameters.getInstance(), Collections.singleton(jobGraphFile.toFile())), mockGateway).get();
}
use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.
the class AbstractMetricsHandlerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final MetricStore metricStore = new MetricStore();
metricStore.add(new MetricDump.CounterDump(new QueryScopeInfo.JobManagerQueryScopeInfo(), TEST_METRIC_NAME, TEST_METRIC_VALUE));
when(mockMetricFetcher.getMetricStore()).thenReturn(metricStore);
testMetricsHandler = new TestMetricsHandler(new GatewayRetriever<DispatcherGateway>() {
@Override
public CompletableFuture<DispatcherGateway> getFuture() {
return CompletableFuture.completedFuture(mockDispatcherGateway);
}
}, Time.milliseconds(50), Collections.emptyMap(), new TestMetricsHeaders(), mockMetricFetcher);
}
use of org.apache.flink.runtime.dispatcher.DispatcherGateway in project flink by apache.
the class MetricsHandlerTestBase method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
this.leaderRetriever = new GatewayRetriever<DispatcherGateway>() {
@Override
public CompletableFuture<DispatcherGateway> getFuture() {
return CompletableFuture.completedFuture(mockDispatcherGateway);
}
};
this.pathParameters = getPathParameters();
this.metricsHandler = getMetricsHandler();
final MetricStore metricStore = new MetricStore();
metricStore.add(new MetricDump.CounterDump(getQueryScopeInfo(), TEST_METRIC_NAME, TEST_METRIC_VALUE));
when(mockMetricFetcher.getMetricStore()).thenReturn(metricStore);
}
use of org.apache.flink.runtime.dispatcher.DispatcherGateway 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()));
}
}
Aggregations