use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.
the class RestClusterClientTest method testSubmitJobAndWaitForExecutionResult.
@Test
public void testSubmitJobAndWaitForExecutionResult() throws Exception {
final TestJobExecutionResultHandler testJobExecutionResultHandler = new TestJobExecutionResultHandler(new RestHandlerException("should trigger retry", HttpResponseStatus.SERVICE_UNAVAILABLE), JobExecutionResultResponseBody.inProgress(), // On an UNKNOWN JobResult it should be retried
JobExecutionResultResponseBody.created(new JobResult.Builder().applicationStatus(ApplicationStatus.UNKNOWN).jobId(jobId).netRuntime(Long.MAX_VALUE).accumulatorResults(Collections.singletonMap("testName", new SerializedValue<>(OptionalFailure.of(1.0)))).build()), JobExecutionResultResponseBody.created(new JobResult.Builder().applicationStatus(ApplicationStatus.SUCCEEDED).jobId(jobId).netRuntime(Long.MAX_VALUE).accumulatorResults(Collections.singletonMap("testName", new SerializedValue<>(OptionalFailure.of(1.0)))).build()), JobExecutionResultResponseBody.created(new JobResult.Builder().applicationStatus(ApplicationStatus.FAILED).jobId(jobId).netRuntime(Long.MAX_VALUE).serializedThrowable(new SerializedThrowable(new RuntimeException("expected"))).build()));
// Fail the first JobExecutionResult HTTP polling attempt, which should not be a problem
// because of the retries.
final AtomicBoolean firstExecutionResultPollFailed = new AtomicBoolean(false);
// Fail the first JobSubmit HTTP request, which should not be a problem because of the
// retries.
final AtomicBoolean firstSubmitRequestFailed = new AtomicBoolean(false);
failHttpRequest = (messageHeaders, messageParameters, requestBody) -> {
if (messageHeaders instanceof JobExecutionResultHeaders) {
return !firstExecutionResultPollFailed.getAndSet(true);
}
if (messageHeaders instanceof JobSubmitHeaders) {
return !firstSubmitRequestFailed.getAndSet(true);
}
return false;
};
try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(testJobExecutionResultHandler, new TestJobSubmitHandler())) {
try (RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort())) {
final JobExecutionResult jobExecutionResult = restClusterClient.submitJob(jobGraph).thenCompose(restClusterClient::requestJobResult).get().toJobExecutionResult(ClassLoader.getSystemClassLoader());
assertTrue(firstExecutionResultPollFailed.get());
assertTrue(firstSubmitRequestFailed.get());
assertThat(jobExecutionResult.getJobID(), equalTo(jobId));
assertThat(jobExecutionResult.getNetRuntime(), equalTo(Long.MAX_VALUE));
assertThat(jobExecutionResult.getAllAccumulatorResults(), equalTo(Collections.singletonMap("testName", 1.0)));
try {
restClusterClient.submitJob(jobGraph).thenCompose(restClusterClient::requestJobResult).get().toJobExecutionResult(ClassLoader.getSystemClassLoader());
fail("Expected exception not thrown.");
} catch (final Exception e) {
final Optional<RuntimeException> cause = ExceptionUtils.findThrowable(e, RuntimeException.class);
assertThat(cause.isPresent(), is(true));
assertThat(cause.get().getMessage(), equalTo("expected"));
}
}
}
}
use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.
the class RestClusterClientTest method testRetriableSendOperationIfConnectionErrorOrServiceUnavailable.
/**
* Tests that the send operation is being retried.
*/
@Test
public void testRetriableSendOperationIfConnectionErrorOrServiceUnavailable() throws Exception {
final PingRestHandler pingRestHandler = new PingRestHandler(FutureUtils.completedExceptionally(new RestHandlerException("test exception", HttpResponseStatus.SERVICE_UNAVAILABLE)), CompletableFuture.completedFuture(EmptyResponseBody.getInstance()));
try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(pingRestHandler)) {
RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
try {
final AtomicBoolean firstPollFailed = new AtomicBoolean();
failHttpRequest = (messageHeaders, messageParameters, requestBody) -> messageHeaders instanceof PingRestHandlerHeaders && !firstPollFailed.getAndSet(true);
restClusterClient.sendRequest(PingRestHandlerHeaders.INSTANCE).get();
} finally {
restClusterClient.close();
}
}
}
Aggregations