Search in sources :

Example 1 with EmptyMessageParameters

use of org.apache.flink.runtime.rest.messages.EmptyMessageParameters 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();
}
Also used : SSLContext(javax.net.ssl.SSLContext) EmptyResponseBody(org.apache.flink.runtime.rest.messages.EmptyResponseBody) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) StaticFileServerHandler(org.apache.flink.runtime.rest.handler.legacy.files.StaticFileServerHandler) TestRestHandler(org.apache.flink.runtime.rest.util.TestRestHandler) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) Before(org.junit.Before)

Example 2 with EmptyMessageParameters

use of org.apache.flink.runtime.rest.messages.EmptyMessageParameters 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. "));
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestClient(org.apache.flink.runtime.rest.RestClient) TestRestHandler(org.apache.flink.runtime.rest.util.TestRestHandler) EmptyResponseBody(org.apache.flink.runtime.rest.messages.EmptyResponseBody) ExecutionException(java.util.concurrent.ExecutionException) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) EmptyMessageParameters(org.apache.flink.runtime.rest.messages.EmptyMessageParameters) Test(org.junit.Test)

Aggregations

EmptyMessageParameters (org.apache.flink.runtime.rest.messages.EmptyMessageParameters)2 EmptyRequestBody (org.apache.flink.runtime.rest.messages.EmptyRequestBody)2 EmptyResponseBody (org.apache.flink.runtime.rest.messages.EmptyResponseBody)2 TestRestHandler (org.apache.flink.runtime.rest.util.TestRestHandler)2 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)2 ExecutionException (java.util.concurrent.ExecutionException)1 SSLContext (javax.net.ssl.SSLContext)1 RestClient (org.apache.flink.runtime.rest.RestClient)1 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)1 StaticFileServerHandler (org.apache.flink.runtime.rest.handler.legacy.files.StaticFileServerHandler)1 TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)1 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)1 Before (org.junit.Before)1 Test (org.junit.Test)1