Search in sources :

Example 1 with TestingRestfulGateway

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

the class JobExecutionResultHandlerTest method testCompletedResult.

@Test
public void testCompletedResult() throws Exception {
    final JobStatus jobStatus = JobStatus.FINISHED;
    final ArchivedExecutionGraph executionGraph = new ArchivedExecutionGraphBuilder().setJobID(TEST_JOB_ID).setState(jobStatus).build();
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> {
        assertThat(jobId, equalTo(TEST_JOB_ID));
        return CompletableFuture.completedFuture(jobStatus);
    }).setRequestJobResultFunction(jobId -> {
        assertThat(jobId, equalTo(TEST_JOB_ID));
        return CompletableFuture.completedFuture(JobResult.createFrom(executionGraph));
    }).build();
    final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
    assertThat(responseBody.getStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
    assertThat(responseBody.getJobExecutionResult(), not(nullValue()));
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) Matchers.not(org.hamcrest.Matchers.not) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Assert.assertThat(org.junit.Assert.assertThat) JobResult(org.apache.flink.runtime.jobmaster.JobResult) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Test(org.junit.Test) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 2 with TestingRestfulGateway

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

the class JobExecutionResultHandlerTest method testPropagateFlinkJobNotFoundExceptionAsRestHandlerException.

@Test
public void testPropagateFlinkJobNotFoundExceptionAsRestHandlerException() throws Exception {
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> FutureUtils.completedExceptionally(new FlinkJobNotFoundException(jobId))).build();
    try {
        jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
        fail("Expected exception not thrown");
    } catch (final ExecutionException e) {
        final Throwable cause = ExceptionUtils.stripCompletionException(e.getCause());
        assertThat(cause, instanceOf(RestHandlerException.class));
        assertThat(((RestHandlerException) cause).getHttpResponseStatus(), equalTo(HttpResponseStatus.NOT_FOUND));
    }
}
Also used : QueueStatus(org.apache.flink.runtime.rest.messages.queue.QueueStatus) Matchers.not(org.hamcrest.Matchers.not) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) HttpResponseStatus(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) Assert.assertThat(org.junit.Assert.assertThat) JobResult(org.apache.flink.runtime.jobmaster.JobResult) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestLogger(org.apache.flink.util.TestLogger) HandlerRequest(org.apache.flink.runtime.rest.handler.HandlerRequest) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Test(org.junit.Test) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) JobID(org.apache.flink.api.common.JobID) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Time(org.apache.flink.api.common.time.Time) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) Test(org.junit.Test)

Example 3 with TestingRestfulGateway

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

the class JobExecutionResultHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().build();
    jobExecutionResultHandler = new JobExecutionResultHandler(() -> CompletableFuture.completedFuture(testingRestfulGateway), Time.seconds(10), Collections.emptyMap());
    testRequest = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new JobMessageParameters(), Collections.singletonMap("jobid", TEST_JOB_ID.toString()), Collections.emptyMap(), Collections.emptyList());
}
Also used : TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) JobMessageParameters(org.apache.flink.runtime.rest.messages.JobMessageParameters) Before(org.junit.Before)

Example 4 with TestingRestfulGateway

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

the class SavepointHandlersTest 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().setTriggerSavepointFunction(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));
}
Also used : TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) AtomicReference(java.util.concurrent.atomic.AtomicReference) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 5 with TestingRestfulGateway

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

the class SavepointHandlersTest method testSavepointCompletedSuccessfully.

@Test
public void testSavepointCompletedSuccessfully() throws Exception {
    final OperationResult<String> successfulResult = OperationResult.success(COMPLETED_SAVEPOINT_EXTERNAL_POINTER);
    final AtomicReference<AsynchronousJobOperationKey> keyReference = new AtomicReference<>();
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction(setReferenceToOperationKey(keyReference)).setGetSavepointStatusFunction(getResultIfKeyMatches(successfulResult, keyReference)).build();
    final TriggerId triggerId = savepointTriggerHandler.handleRequest(triggerSavepointRequest(), testingRestfulGateway).get().getTriggerId();
    AsynchronousOperationResult<SavepointInfo> savepointResponseBody;
    savepointResponseBody = savepointStatusHandler.handleRequest(savepointStatusRequest(triggerId), testingRestfulGateway).get();
    assertThat(savepointResponseBody.queueStatus().getId(), equalTo(QueueStatus.Id.COMPLETED));
    assertThat(savepointResponseBody.resource(), notNullValue());
    assertThat(savepointResponseBody.resource().getLocation(), equalTo(COMPLETED_SAVEPOINT_EXTERNAL_POINTER));
}
Also used : TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) AsynchronousJobOperationKey(org.apache.flink.runtime.rest.handler.job.AsynchronousJobOperationKey) AtomicReference(java.util.concurrent.atomic.AtomicReference) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) 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