use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class RestClusterClientSavepointTriggerTest method testTriggerSavepointTargetDirectory.
@Test
public void testTriggerSavepointTargetDirectory() throws Exception {
final TriggerId triggerId = new TriggerId();
final String expectedSubmittedSavepointDir = "world";
final String expectedReturnedSavepointDir = "hello";
try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(triggerRequestBody -> {
assertEquals(expectedSubmittedSavepointDir, triggerRequestBody.getTargetDirectory().get());
assertFalse(triggerRequestBody.isCancelJob());
return triggerId;
}, statusRequestTriggerId -> {
assertEquals(triggerId, statusRequestTriggerId);
return new SavepointInfo(expectedReturnedSavepointDir, null);
})) {
final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
final String savepointPath = restClusterClient.triggerSavepoint(new JobID(), expectedSubmittedSavepointDir, SavepointFormatType.CANONICAL).get();
assertEquals(expectedReturnedSavepointDir, savepointPath);
}
}
use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class RestClusterClientSavepointTriggerTest method testTriggerSavepointCancelJob.
@Test
public void testTriggerSavepointCancelJob() throws Exception {
final TriggerId triggerId = new TriggerId();
final String expectedSavepointDir = "hello";
try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(request -> {
assertTrue(request.isCancelJob());
return triggerId;
}, trigger -> {
assertEquals(triggerId, trigger);
return new SavepointInfo(expectedSavepointDir, null);
})) {
final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
final String savepointPath = restClusterClient.cancelWithSavepoint(new JobID(), null, SavepointFormatType.CANONICAL).get();
assertEquals(expectedSavepointDir, savepointPath);
}
}
use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class StopWithSavepointHandlersTest method testSavepointCompletedWithException.
@Test
public void testSavepointCompletedWithException() throws Exception {
AtomicReference<AsynchronousJobOperationKey> keyReference = new AtomicReference<>();
final OperationResult<String> failedResult = OperationResult.failure(new RuntimeException("expected"));
TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setStopWithSavepointFunction(setReferenceToOperationKey(keyReference)).setGetSavepointStatusFunction(getResultIfKeyMatches(failedResult, keyReference)).build();
final TriggerId triggerId = savepointTriggerHandler.handleRequest(triggerSavepointRequest(), testingRestfulGateway).get().getTriggerId();
final AsynchronousOperationResult<SavepointInfo> savepointResponseBody = savepointStatusHandler.handleRequest(savepointStatusRequest(triggerId), testingRestfulGateway).get();
assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
assertThat(savepointResponseBody.resource(), notNullValue());
assertThat(savepointResponseBody.resource().getFailureCause(), notNullValue());
final Throwable savepointError = savepointResponseBody.resource().getFailureCause().deserializeError(ClassLoader.getSystemClassLoader());
assertThat(savepointError.getMessage(), equalTo("expected"));
assertThat(savepointError, instanceOf(RuntimeException.class));
}
use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class StopWithSavepointHandlersTest method testProvidedTriggerId.
@Test
public void testProvidedTriggerId() throws Exception {
final OperationResult<String> successfulResult = OperationResult.success(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
AtomicReference<AsynchronousJobOperationKey> keyReference = new AtomicReference<>();
final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setStopWithSavepointFunction(setReferenceToOperationKey(keyReference)).setGetSavepointStatusFunction(getResultIfKeyMatches(successfulResult, keyReference)).build();
final TriggerId providedTriggerId = new TriggerId();
final TriggerId returnedTriggerId = savepointTriggerHandler.handleRequest(triggerSavepointRequest(DEFAULT_REQUESTED_SAVEPOINT_TARGET_DIRECTORY, SavepointFormatType.CANONICAL, providedTriggerId), testingRestfulGateway).get().getTriggerId();
assertEquals(providedTriggerId, returnedTriggerId);
AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
savepointResponseBody = savepointStatusHandler.handleRequest(savepointStatusRequest(providedTriggerId), testingRestfulGateway).get();
assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
assertThat(savepointResponseBody.resource(), notNullValue());
assertThat(savepointResponseBody.resource().getLocation(), equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
use of org.apache.flink.runtime.rest.messages.TriggerId in project flink by apache.
the class AbstractAsynchronousOperationHandlersTest method testOperationFailure.
/**
* Tests the triggering and exceptional completion of an asynchronous operation.
*/
@Test
public void testOperationFailure() throws Exception {
final FlinkException testException = new FlinkException("Test exception");
testingTriggerHandler.setGatewayCallback((request, gateway) -> FutureUtils.completedExceptionally(testException));
// trigger the operation
final TriggerId triggerId = testingTriggerHandler.handleRequest(triggerOperationRequest(), DUMMY_GATEWAY).get().getTriggerId();
AsynchronousOperationResult<OperationResult> operationResult = testingStatusHandler.handleRequest(statusOperationRequest(triggerId), DUMMY_GATEWAY).get();
assertThat(operationResult.queueStatus().getId(), is(QueueStatus.completed().getId()));
final OperationResult resource = operationResult.resource();
assertThat(resource.throwable, is(testException));
}
Aggregations