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