use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.
the class RestServerEndpointITCase method setup.
@Before
public void setup() throws Exception {
config.setString(WebOptions.UPLOAD_DIR, temporaryFolder.newFolder().getCanonicalPath());
defaultSSLContext = SSLContext.getDefault();
defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
final SSLContext sslClientContext = SSLUtils.createRestSSLContext(config, true);
if (sslClientContext != null) {
SSLContext.setDefault(sslClientContext);
HttpsURLConnection.setDefaultSSLSocketFactory(sslClientContext.getSocketFactory());
}
RestfulGateway mockRestfulGateway = new TestingRestfulGateway.Builder().build();
final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () -> CompletableFuture.completedFuture(mockRestfulGateway);
testHandler = new TestHandler(mockGatewayRetriever, RpcUtils.INF_TIMEOUT);
TestVersionHandler testVersionHandler = new TestVersionHandler(mockGatewayRetriever, RpcUtils.INF_TIMEOUT);
TestRestHandler<RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> testVersionSelectionHandler1 = new TestRestHandler<>(mockGatewayRetriever, TestVersionSelectionHeaders1.INSTANCE, FutureUtils.completedExceptionally(new RestHandlerException("test failure 1", HttpResponseStatus.OK)));
TestRestHandler<RestfulGateway, EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters> testVersionSelectionHandler2 = new TestRestHandler<>(mockGatewayRetriever, TestVersionSelectionHeaders2.INSTANCE, FutureUtils.completedExceptionally(new RestHandlerException("test failure 2", HttpResponseStatus.ACCEPTED)));
testUploadHandler = new TestUploadHandler(mockGatewayRetriever, RpcUtils.INF_TIMEOUT);
final StaticFileServerHandler<RestfulGateway> staticFileServerHandler = new StaticFileServerHandler<>(mockGatewayRetriever, RpcUtils.INF_TIMEOUT, temporaryFolder.getRoot());
serverEndpoint = TestRestServerEndpoint.builder(config).withHandler(new TestHeaders(), testHandler).withHandler(TestUploadHeaders.INSTANCE, testUploadHandler).withHandler(testVersionHandler).withHandler(testVersionSelectionHandler1).withHandler(testVersionSelectionHandler2).withHandler(WebContentHandlerSpecification.getInstance(), staticFileServerHandler).buildAndStart();
restClient = new TestRestClient(config);
serverAddress = serverEndpoint.getServerAddress();
}
use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.
the class RestServerSSLAuthITCase method testConnectFailure.
@Test
public void testConnectFailure() throws Exception {
RestClient restClient = null;
RestServerEndpoint serverEndpoint = null;
try {
RestfulGateway restfulGateway = new TestingRestfulGateway.Builder().build();
RestServerEndpointITCase.TestVersionHandler testVersionHandler = new RestServerEndpointITCase.TestVersionHandler(() -> CompletableFuture.completedFuture(restfulGateway), RpcUtils.INF_TIMEOUT);
serverEndpoint = TestRestServerEndpoint.builder(serverConfig).withHandler(testVersionHandler.getMessageHeaders(), testVersionHandler).buildAndStart();
restClient = new RestServerEndpointITCase.TestRestClient(clientConfig);
CompletableFuture<EmptyResponseBody> response = restClient.sendRequest(serverEndpoint.getServerAddress().getHostName(), serverEndpoint.getServerAddress().getPort(), RestServerEndpointITCase.TestVersionHeaders.INSTANCE, EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance(), Collections.emptyList());
response.get(60, TimeUnit.SECONDS);
fail("should never complete normally");
} catch (ExecutionException exception) {
// that is what we want
assertTrue(ExceptionUtils.findThrowable(exception, SSLException.class).isPresent());
} finally {
if (restClient != null) {
restClient.shutdown(timeout);
}
if (serverEndpoint != null) {
serverEndpoint.close();
}
}
}
use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.
the class RestClientTest method testConnectionClosedHandling.
/**
* Tests that we fail the operation if the remote connection closes.
*/
@Test
public void testConnectionClosedHandling() throws Exception {
final Configuration config = new Configuration();
config.setLong(RestOptions.IDLENESS_TIMEOUT, 5000L);
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());
Socket connectionSocket = null;
try {
connectionSocket = socketCompletableFuture.get(TIMEOUT, TimeUnit.SECONDS);
} catch (TimeoutException ignored) {
// could not establish a server connection --> see that the response failed
socketCompletableFuture.cancel(true);
}
if (connectionSocket != null) {
// close connection
connectionSocket.close();
}
try {
responseFuture.get();
} catch (ExecutionException ee) {
if (!ExceptionUtils.findThrowable(ee, IOException.class).isPresent()) {
throw ee;
}
}
}
}
use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.
the class RestClientTest method testInvalidVersionRejection.
@Test
public void testInvalidVersionRejection() throws Exception {
try (final RestClient restClient = new RestClient(new Configuration(), Executors.directExecutor())) {
CompletableFuture<EmptyResponseBody> invalidVersionResponse = restClient.sendRequest(unroutableIp, 80, new TestMessageHeaders(), EmptyMessageParameters.getInstance(), EmptyRequestBody.getInstance(), Collections.emptyList(), RestAPIVersion.V0);
Assert.fail("The request should have been rejected due to a version mismatch.");
} catch (IllegalArgumentException e) {
// expected
}
}
use of org.apache.flink.runtime.rest.messages.EmptyResponseBody in project flink by apache.
the class JobCancellationHandlerTest method testResponse.
private static void testResponse(Function<JobID, CompletableFuture<Acknowledge>> cancelJobFunction, ThrowingConsumer<CompletableFuture<EmptyResponseBody>, Exception> assertion) throws Exception {
final RestfulGateway gateway = createGateway(cancelJobFunction);
final JobCancellationHandler jobCancellationHandler = createHandler(gateway);
final JobCancellationMessageParameters messageParameters = jobCancellationHandler.getMessageHeaders().getUnresolvedMessageParameters().resolveJobId(new JobID());
final CompletableFuture<EmptyResponseBody> cancellationFuture = jobCancellationHandler.handleRequest(HandlerRequest.create(EmptyRequestBody.getInstance(), messageParameters), gateway);
assertion.accept(cancellationFuture);
}
Aggregations