Search in sources :

Example 6 with TestingRestfulGateway

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

the class SavepointHandlersTest method testSavepointCompletedWithException.

@Test
public void testSavepointCompletedWithException() throws Exception {
    final OperationResult<String> failedResult = OperationResult.failure(new RuntimeException("expected"));
    final AtomicReference<AsynchronousJobOperationKey> keyReference = new AtomicReference<>();
    TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setTriggerSavepointFunction(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));
}
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 7 with TestingRestfulGateway

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

the class MetricFetcherTest method testUpdate.

@Test
public void testUpdate() {
    final Time timeout = Time.seconds(10L);
    // ========= setup TaskManager
    // =================================================================================
    JobID jobID = new JobID();
    ResourceID tmRID = ResourceID.generate();
    // ========= setup QueryServices
    // ================================================================================
    final MetricQueryServiceGateway jmQueryService = new TestingMetricQueryServiceGateway.Builder().setQueryMetricsSupplier(() -> CompletableFuture.completedFuture(new MetricDumpSerialization.MetricSerializationResult(new byte[0], new byte[0], new byte[0], new byte[0], 0, 0, 0, 0))).build();
    MetricDumpSerialization.MetricSerializationResult requestMetricsAnswer = createRequestDumpAnswer(tmRID, jobID);
    final MetricQueryServiceGateway tmQueryService = new TestingMetricQueryServiceGateway.Builder().setQueryMetricsSupplier(() -> CompletableFuture.completedFuture(requestMetricsAnswer)).build();
    // ========= setup JobManager
    // ==================================================================================
    final TestingRestfulGateway restfulGateway = new TestingRestfulGateway.Builder().setRequestMultipleJobDetailsSupplier(() -> CompletableFuture.completedFuture(new MultipleJobsDetails(Collections.emptyList()))).setRequestMetricQueryServiceGatewaysSupplier(() -> CompletableFuture.completedFuture(Collections.singleton(jmQueryService.getAddress()))).setRequestTaskManagerMetricQueryServiceGatewaysSupplier(() -> CompletableFuture.completedFuture(Collections.singleton(Tuple2.of(tmRID, tmQueryService.getAddress())))).build();
    final GatewayRetriever<RestfulGateway> retriever = () -> CompletableFuture.completedFuture(restfulGateway);
    // ========= start MetricFetcher testing
    // =======================================================================
    MetricFetcher fetcher = new MetricFetcherImpl<>(retriever, address -> CompletableFuture.completedFuture(tmQueryService), Executors.directExecutor(), timeout, MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
    // verify that update fetches metrics and updates the store
    fetcher.update();
    MetricStore store = fetcher.getMetricStore();
    synchronized (store) {
        assertEquals("7", store.getJobManagerMetricStore().getMetric("abc.hist_min"));
        assertEquals("6", store.getJobManagerMetricStore().getMetric("abc.hist_max"));
        assertEquals("4.0", store.getJobManagerMetricStore().getMetric("abc.hist_mean"));
        assertEquals("0.5", store.getJobManagerMetricStore().getMetric("abc.hist_median"));
        assertEquals("5.0", store.getJobManagerMetricStore().getMetric("abc.hist_stddev"));
        assertEquals("0.75", store.getJobManagerMetricStore().getMetric("abc.hist_p75"));
        assertEquals("0.9", store.getJobManagerMetricStore().getMetric("abc.hist_p90"));
        assertEquals("0.95", store.getJobManagerMetricStore().getMetric("abc.hist_p95"));
        assertEquals("0.98", store.getJobManagerMetricStore().getMetric("abc.hist_p98"));
        assertEquals("0.99", store.getJobManagerMetricStore().getMetric("abc.hist_p99"));
        assertEquals("0.999", store.getJobManagerMetricStore().getMetric("abc.hist_p999"));
        assertEquals("x", store.getTaskManagerMetricStore(tmRID.toString()).metrics.get("abc.gauge"));
        assertEquals("5.0", store.getJobMetricStore(jobID.toString()).metrics.get("abc.jc"));
        assertEquals("2", store.getTaskMetricStore(jobID.toString(), "taskid").metrics.get("2.abc.tc"));
        assertEquals("1", store.getTaskMetricStore(jobID.toString(), "taskid").metrics.get("2.opname.abc.oc"));
    }
}
Also used : MetricQueryServiceGateway(org.apache.flink.runtime.webmonitor.retriever.MetricQueryServiceGateway) TestingMetricQueryServiceGateway(org.apache.flink.runtime.metrics.dump.TestingMetricQueryServiceGateway) Time(org.apache.flink.api.common.time.Time) MultipleJobsDetails(org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails) MetricDumpSerialization(org.apache.flink.runtime.metrics.dump.MetricDumpSerialization) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) JobID(org.apache.flink.api.common.JobID) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 8 with TestingRestfulGateway

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

the class StopWithSavepointHandlersTest method testSavepointCompletedSuccessfully.

@Test
public void testSavepointCompletedSuccessfully() 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 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)

Example 9 with TestingRestfulGateway

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

the class DefaultExecutionGraphCacheTest method testCacheEntryCleanup.

/**
 * Tests that cache entries are cleaned up when their TTL has expired upon calling {@link
 * DefaultExecutionGraphCache#cleanup()}.
 */
@Test
public void testCacheEntryCleanup() throws Exception {
    final Time timeout = Time.milliseconds(100L);
    final Time timeToLive = Time.milliseconds(1L);
    final JobID expectedJobId2 = new JobID();
    final ExecutionGraphInfo expectedExecutionGraphInfo2 = new ExecutionGraphInfo(new ArchivedExecutionGraphBuilder().build());
    final AtomicInteger requestJobCalls = new AtomicInteger(0);
    final TestingRestfulGateway restfulGateway = new TestingRestfulGateway.Builder().setRequestExecutionGraphInfoFunction(jobId -> {
        requestJobCalls.incrementAndGet();
        if (jobId.equals(expectedJobId)) {
            return CompletableFuture.completedFuture(expectedExecutionGraphInfo);
        } else if (jobId.equals(expectedJobId2)) {
            return CompletableFuture.completedFuture(expectedExecutionGraphInfo2);
        } else {
            throw new AssertionError("Invalid job id received.");
        }
    }).build();
    try (ExecutionGraphCache executionGraphCache = new DefaultExecutionGraphCache(timeout, timeToLive)) {
        CompletableFuture<ExecutionGraphInfo> executionGraph1Future = executionGraphCache.getExecutionGraphInfo(expectedJobId, restfulGateway);
        CompletableFuture<ExecutionGraphInfo> executionGraph2Future = executionGraphCache.getExecutionGraphInfo(expectedJobId2, restfulGateway);
        assertEquals(expectedExecutionGraphInfo, executionGraph1Future.get());
        assertEquals(expectedExecutionGraphInfo2, executionGraph2Future.get());
        assertThat(requestJobCalls.get(), Matchers.equalTo(2));
        Thread.sleep(timeToLive.toMilliseconds());
        executionGraphCache.cleanup();
        assertTrue(executionGraphCache.size() == 0);
    }
}
Also used : FlinkException(org.apache.flink.util.FlinkException) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) CompletableFuture(java.util.concurrent.CompletableFuture) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) ExecutorService(java.util.concurrent.ExecutorService) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Collection(java.util.Collection) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) Test(org.junit.Test) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) Preconditions(org.apache.flink.util.Preconditions) ExecutorUtils(org.apache.flink.util.ExecutorUtils) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JobID(org.apache.flink.api.common.JobID) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Time(org.apache.flink.api.common.time.Time) Assert.assertEquals(org.junit.Assert.assertEquals) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Time(org.apache.flink.api.common.time.Time) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) JobID(org.apache.flink.api.common.JobID) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Example 10 with TestingRestfulGateway

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

the class JobExecutionResultHandlerTest method testResultInProgress.

@Test
public void testResultInProgress() throws Exception {
    final TestingRestfulGateway testingRestfulGateway = new TestingRestfulGateway.Builder().setRequestJobStatusFunction(jobId -> CompletableFuture.completedFuture(JobStatus.RUNNING)).build();
    final JobExecutionResultResponseBody responseBody = jobExecutionResultHandler.handleRequest(testRequest, testingRestfulGateway).get();
    assertThat(responseBody.getStatus().getId(), equalTo(QueueStatus.Id.IN_PROGRESS));
}
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) JobExecutionResultResponseBody(org.apache.flink.runtime.rest.messages.job.JobExecutionResultResponseBody) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) 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