use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.
the class AbstractHandlerITCase method testOOMErrorMessageEnrichment.
@Test
public void testOOMErrorMessageEnrichment() throws Exception {
final TestMessageHeaders<EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> messageHeaders = TestMessageHeaders.emptyBuilder().setTargetRestEndpointURL("/test-handler").build();
final TestRestHandler<RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> testRestHandler = new TestRestHandler<>(mockGatewayRetriever, messageHeaders, FutureUtils.completedExceptionally(new OutOfMemoryError("Metaspace")));
try (final TestRestServerEndpoint server = TestRestServerEndpoint.builder(REST_BASE_CONFIG).withHandler(messageHeaders, testRestHandler).buildAndStart();
final RestClient restClient = createRestClient(server.getServerAddress().getPort())) {
CompletableFuture<EmptyResponseBody> response = restClient.sendRequest(server.getServerAddress().getHostName(), server.getServerAddress().getPort(), messageHeaders, EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance());
try {
response.get();
fail("An ExecutionException was expected here being caused by the OutOfMemoryError.");
} catch (ExecutionException e) {
assertThat(e.getMessage(), StringContains.containsString("Metaspace. The metaspace out-of-memory error has occurred. "));
}
}
}
use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.
the class RestClientTest method testRestClientClosedHandling.
/**
* Tests that we fail the operation if the client closes.
*/
@Test
public void testRestClientClosedHandling() throws Exception {
final Configuration config = new Configuration();
config.setLong(RestOptions.IDLENESS_TIMEOUT, 5000L);
Socket connectionSocket = null;
try (final ServerSocket serverSocket = new ServerSocket(0);
final RestClient restClient = new RestClient(config, TestingUtils.defaultExecutor())) {
final String targetAddress = "localhost";
final int targetPort = serverSocket.getLocalPort();
// start server
final CompletableFuture<Socket> socketCompletableFuture = CompletableFuture.supplyAsync(CheckedSupplier.unchecked(() -> NetUtils.acceptWithoutTimeout(serverSocket)));
final CompletableFuture<EmptyResponseBody> responseFuture = restClient.sendRequest(targetAddress, targetPort, new TestMessageHeaders(), EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance(), Collections.emptyList());
try {
connectionSocket = socketCompletableFuture.get(TIMEOUT, TimeUnit.SECONDS);
} catch (TimeoutException ignored) {
// could not establish a server connection --> see that the response failed
socketCompletableFuture.cancel(true);
}
restClient.close();
try {
responseFuture.get();
} catch (ExecutionException ee) {
if (!ExceptionUtils.findThrowable(ee, IOException.class).isPresent()) {
throw ee;
}
}
} finally {
if (connectionSocket != null) {
connectionSocket.close();
}
}
}
use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.
the class RestClusterClient method cancel.
@Override
public CompletableFuture<Acknowledge> cancel(JobID jobID) {
JobCancellationMessageParameters params = new JobCancellationMessageParameters().resolveJobId(jobID).resolveTerminationMode(TerminationModeQueryParameter.TerminationMode.CANCEL);
CompletableFuture<EmptyResponseBody> responseFuture = sendRequest(JobCancellationHeaders.getInstance(), params);
return responseFuture.thenApply(ignore -> Acknowledge.get());
}
Aggregations