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();
}
}
}
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());
}
}
}
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();
}
}
}
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());
}
}
}
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. "));
}
}
}
Aggregations