Search in sources :

Example 6 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testJobSubmissionWithUserArtifact.

@Test(timeout = 120_000)
public void testJobSubmissionWithUserArtifact() throws Exception {
    try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(new TestJobSubmitHandler())) {
        try (RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort())) {
            TemporaryFolder temporaryFolder = new TemporaryFolder();
            temporaryFolder.create();
            File file = temporaryFolder.newFile();
            Files.write(file.toPath(), "hello world".getBytes(ConfigConstants.DEFAULT_CHARSET));
            // Add file path with scheme
            jobGraph.addUserArtifact("file", new DistributedCache.DistributedCacheEntry(file.toURI().toString(), false));
            // Add file path without scheme
            jobGraph.addUserArtifact("file2", new DistributedCache.DistributedCacheEntry(file.toURI().getPath(), false));
            restClusterClient.submitJob(jobGraph).get();
        }
    }
}
Also used : DistributedCache(org.apache.flink.api.common.cache.DistributedCache) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) TemporaryFolder(org.junit.rules.TemporaryFolder) File(java.io.File) Test(org.junit.Test)

Example 7 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testJobSubmissionRespectsConfiguredRetryPolicy.

@Test
public void testJobSubmissionRespectsConfiguredRetryPolicy() throws Exception {
    final int maxRetryAttempts = 3;
    final AtomicInteger failedRequest = new AtomicInteger(0);
    failHttpRequest = (messageHeaders, messageParameters, requestBody) -> {
        failedRequest.incrementAndGet();
        // Fail all job submissions.
        return true;
    };
    final Configuration clientConfig = new Configuration(restConfig);
    clientConfig.set(RestOptions.RETRY_MAX_ATTEMPTS, maxRetryAttempts);
    clientConfig.set(RestOptions.RETRY_DELAY, 10L);
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(new TestJobSubmitHandler())) {
        final InetSocketAddress serverAddress = Objects.requireNonNull(restServerEndpoint.getServerAddress());
        try (RestClusterClient<?> restClusterClient = createRestClusterClient(serverAddress.getPort(), clientConfig)) {
            final ExecutionException exception = assertThrows(ExecutionException.class, () -> restClusterClient.submitJob(jobGraph).get());
            assertThat(exception, FlinkMatchers.containsCause(FutureUtils.RetryException.class));
            assertEquals(maxRetryAttempts + 1, failedRequest.get());
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) InetSocketAddress(java.net.InetSocketAddress) ExecutionException(java.util.concurrent.ExecutionException) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) Test(org.junit.Test)

Example 8 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testSendIsNotRetriableIfHttpNotFound.

/**
 * Tests that the send operation is not being retried when receiving a NOT_FOUND return code.
 */
@Test
public void testSendIsNotRetriableIfHttpNotFound() throws Exception {
    final String exceptionMessage = "test exception";
    final PingRestHandler pingRestHandler = new PingRestHandler(FutureUtils.completedExceptionally(new RestHandlerException(exceptionMessage, HttpResponseStatus.NOT_FOUND)));
    try (final TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(pingRestHandler)) {
        RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        try {
            restClusterClient.sendRequest(PingRestHandlerHeaders.INSTANCE).get();
            fail("The rest request should have failed.");
        } catch (Exception e) {
            assertThat(ExceptionUtils.findThrowableWithMessage(e, exceptionMessage).isPresent(), is(true));
        } finally {
            restClusterClient.close();
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) FlinkException(org.apache.flink.util.FlinkException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RestClientException(org.apache.flink.runtime.rest.util.RestClientException) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ConfigurationException(org.apache.flink.util.ConfigurationException) Test(org.junit.Test)

Example 9 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint in project flink by apache.

the class RestClusterClientTest method testGetAccumulators.

@Test
public void testGetAccumulators() throws Exception {
    TestAccumulatorHandler accumulatorHandler = new TestAccumulatorHandler();
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(accumulatorHandler)) {
        try (RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort())) {
            JobID id = new JobID();
            Map<String, Object> accumulators = restClusterClient.getAccumulators(id).get();
            assertNotNull(accumulators);
            assertEquals(1, accumulators.size());
            assertTrue(accumulators.containsKey("testKey"));
            assertEquals("testValue", accumulators.get("testKey").toString());
        }
    }
}
Also used : TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 10 with TestRestServerEndpoint

use of org.apache.flink.runtime.rest.util.TestRestServerEndpoint 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

TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)12 Test (org.junit.Test)12 ExecutionException (java.util.concurrent.ExecutionException)5 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)3 FlinkException (org.apache.flink.util.FlinkException)3 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RestClientException (org.apache.flink.runtime.rest.util.RestClientException)2 ConfigurationException (org.apache.flink.util.ConfigurationException)2 SerializedThrowable (org.apache.flink.util.SerializedThrowable)2 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)1 JobID (org.apache.flink.api.common.JobID)1 JobStatus (org.apache.flink.api.common.JobStatus)1