use of org.apache.flink.runtime.webmonitor.TestingRestfulGateway in project flink by apache.
the class JobExecutionResultHandlerTest method testCompletedResult.
@Test
public void testCompletedResult() throws Exception {
final JobStatus jobStatus = JobStatus.FINISHED;
final ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder().setJobID(TEST_JOB_ID).setState(jobStatus).build();
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> {
assertThat(jobId, equalTo(TEST_JOB_ID));
return CompletableFuture.completedFuture(jobStatus);
}).setRequestJobResultFunction(jobId -> {
assertThat(jobId, equalTo(TEST_JOB_ID));
return CompletableFuture.completedFuture(JobResult.createFrom(executionGraph));
}).build();
final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
assertThat(responseBody.getStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
assertThat(responseBody.getJobExecutionResult(), not(nullValue()));
}
use of org.apache.flink.runtime.webmonitor.TestingRestfulGateway in project flink by apache.
the class JobExecutionResultHandlerTest method testPropagateFlinkJobNotFoundExceptionAsRestHandlerException.
@Test
public void testPropagateFlinkJobNotFoundExceptionAsRestHandlerException() throws Exception {
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId))).build();
try {
jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
fail("Expected exception not thrown");
} catch (final ExecutionException e) {
final Throwable cause = ExceptionUtils.stripCompletionException(e.getCause());
assertThat(cause, instanceOf(RestHandlerException.class));
assertThat(((RestHandlerException) cause).getHttpResponseStatus(), equalTo(HttpResponseStatus.NOT_FOUND));
}
}
use of org.apache.flink.runtime.webmonitor.TestingRestfulGateway in project flink by apache.
the class JobExecutionResultHandlerTest method setUp.
@Before
public void setUp() throws Exception {
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().build();
jobExecutionResultHandler = new JobExecutionResultHandler(() -> CompletableFuture.completedFuture(testingRestfulGateway), Time.seconds(10), Collections.emptyMap());
testRequest = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new JobMessageParameters(), Collections.singletonMap("jobid", TEST_JOB_ID.toString()), Collections.emptyMap(), Collections.emptyList());
}
use of org.apache.flink.runtime.webmonitor.TestingRestfulGateway in project flink by apache.
the class SavepointHandlersTest method testProvidedTriggerId.
@Test
public void testProvidedTriggerId() throws Exception {
final OperationResult<String> successfulResult = OperationResult.success(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
AtomicReference<AsynchronousJobOperationKey> keyReference = new AtomicReference<>();
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction(setReferenceToOperationKey(keyReference)).setGetSavepointStatusFunction(getResultIfKeyMatches(successfulResult, keyReference)).build();
final TriggerId providedTriggerId = new TriggerId();
final TriggerId returnedTriggerId = savepointTriggerHandler.handleRequest(triggerSavepointRequest(DEFAULT_REQUESTED_SAVEPOINT_TARGET_DIRECTORY, SavepointFormatType.CANONICAL, providedTriggerId), testingRestfulGateway).get().getTriggerId();
assertEquals(providedTriggerId, returnedTriggerId);
AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
savepointResponseBody = savepointStatusHandler.handleRequest(savepointStatusRequest(providedTriggerId), testingRestfulGateway).get();
assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
assertThat(savepointResponseBody.resource(), notNullValue());
assertThat(savepointResponseBody.resource().getLocation(), equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
use of org.apache.flink.runtime.webmonitor.TestingRestfulGateway in project flink by apache.
the class SavepointHandlersTest method testSavepointCompletedSuccessfully.
@Test
public void testSavepointCompletedSuccessfully() throws Exception {
final OperationResult<String> successfulResult = OperationResult.success(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
final AtomicReference<AsynchronousJobOperationKey> keyReference = new AtomicReference<>();
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction(setReferenceToOperationKey(keyReference)).setGetSavepointStatusFunction(getResultIfKeyMatches(successfulResult, keyReference)).build();
final TriggerId triggerId = savepointTriggerHandler.handleRequest(triggerSavepointRequest(), testingRestfulGateway).get().getTriggerId();
AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
savepointResponseBody = savepointStatusHandler.handleRequest(savepointStatusRequest(triggerId), testingRestfulGateway).get();
assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
assertThat(savepointResponseBody.resource(), notNullValue());
assertThat(savepointResponseBody.resource().getLocation(), equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
Aggregations