Search in sources :

Example 16 with TestingRestfulGateway

use of org.apache.flink.runtime.webmonitor.TestingRestfulGateway in project flink by apache.

the class SavepointHandlersTest method testTriggerSavepointWithDefaultDirectory.

@Test
public void testTriggerSavepointWithDefaultDirectory() throws Exception {
    final CompletableFuture<String> targetDirectoryFuture = new CompletableFuture<>();
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction((AsynchronousJobOperationKey operationKey, String targetDirectory, SavepointFormatType formatType) -> {
        targetDirectoryFuture.complete(targetDirectory);
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).build();
    final String defaultSavepointDir = "/other/dir";
    final SavepointHandlers savepointHandlers = new SavepointHandlers(defaultSavepointDir);
    final SavepointHandlers.SavepointTriggerHandler savepointTriggerHandler = savepointHandlers.new SavepointTriggerHandler(leaderRetriever, TIMEOUT, Collections.emptyMap());
    savepointTriggerHandler.handleRequest(triggerSavepointRequestWithDefaultDirectory(), testingRestfulGateway).get();
    assertThat(targetDirectoryFuture.get(), equalTo(defaultSavepointDir));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 17 with TestingRestfulGateway

use of org.apache.flink.runtime.webmonitor.TestingRestfulGateway in project flink by apache.

the class SavepointHandlersTest method testQueryStatusOfUnknownOperationReturnsError.

@Test
public void testQueryStatusOfUnknownOperationReturnsError() throws HandlerRequestException, RestHandlerException {
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setGetSavepointStatusFunction(key -> FutureUtils.completedExceptionally(new UnknownOperationKeyException(key))).build();
    final CompletableFuture<AsynchronousOperationResult<SavepointInfo>> statusFuture = savepointStatusHandler.handleRequest(savepointStatusRequest(new TriggerId()), testingRestfulGateway);
    assertThat(statusFuture, RestMatchers.respondsWithError(HttpResponseStatus.NOT_FOUND));
}
Also used : AsynchronousOperationResult(org.apache.flink.runtime.rest.handler.async.AsynchronousOperationResult) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) SavepointTestUtilities.setReferenceToOperationKey(org.apache.flink.runtime.rest.handler.job.savepoints.SavepointTestUtilities.setReferenceToOperationKey) QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) TriggerIdPathParameter(org.apache.flink.runtime.rest.messages.TriggerIdPathParameter) Assert.assertThat(org.junit.Assert.assertThat) SavepointTestUtilities.getResultIfKeyMatches(org.apache.flink.runtime.rest.handler.job.savepoints.SavepointTestUtilities.getResultIfKeyMatches) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Map(java.util.Map) SavepointTriggerRequestBody(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerRequestBody) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Assert.fail(org.junit.Assert.fail) SavepointStatusMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointStatusMessageParameters) UnknownOperationKeyException(org.apache.flink.runtime.dispatcher.UnknownOperationKeyException) HandlerRequestException(org.apache.flink.runtime.rest.handler.HandlerRequestException) RestMatchers(org.apache.flink.runtime.rest.RestMatchers) JobIDPathParameter(org.apache.flink.runtime.rest.messages.JobIDPathParameter) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) OperationResult(org.apache.flink.runtime.rest.handler.async.OperationResult) GatewayRetriever(org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) Test(org.junit.Test) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) SavepointTriggerMessageParameters(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointTriggerMessageParameters) JobID(org.apache.flink.api.common.JobID) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) Assert.assertEquals(org.junit.Assert.assertEquals) UnknownOperationKeyException(org.apache.flink.runtime.dispatcher.UnknownOperationKeyException) AsynchronousOperationResult(org.apache.flink.runtime.rest.handler.async.AsynchronousOperationResult) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Aggregations

TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)17 Test (org.junit.Test)16 AsynchronousJobOperationKey (org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey)11 CompletableFuture (java.util.concurrent.CompletableFuture)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 TriggerId (org.apache.flink.runtime.rest.messages.TriggerId)7 SavepointInfo (org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo)7 JobID (org.apache.flink.api.common.JobID)6 Time (org.apache.flink.api.common.time.Time)6 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)6 SavepointFormatType (org.apache.flink.core.execution.SavepointFormatType)5 TestLogger (org.apache.flink.util.TestLogger)5 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)5 Assert.assertThat (org.junit.Assert.assertThat)5 Assert.fail (org.junit.Assert.fail)5 Before (org.junit.Before)5 Collections (java.util.Collections)4 ExecutionException (java.util.concurrent.ExecutionException)4 FlinkJobNotFoundException (org.apache.flink.runtime.messages.FlinkJobNotFoundException)4 HandlerRequest (org.apache.flink.runtime.rest.handler.HandlerRequest)4