Search in sources :

Example 1 with TaskExecutorThreadInfoGateway

use of org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway in project flink by apache.

the class ThreadInfoRequestCoordinatorTest method createMockTaskManagerGateway.

private static CompletableFuture<TaskExecutorThreadInfoGateway> createMockTaskManagerGateway(CompletionType completionType) {
    final CompletableFuture<TaskThreadInfoResponse> responseFuture = new CompletableFuture<>();
    switch(completionType) {
        case SUCCESSFULLY:
            ThreadInfoSample sample = JvmUtils.createThreadInfoSample(Thread.currentThread().getId(), 100).get();
            responseFuture.complete(new TaskThreadInfoResponse(Collections.singletonList(sample)));
            break;
        case EXCEPTIONALLY:
            responseFuture.completeExceptionally(new RuntimeException("Request failed."));
            break;
        case TIMEOUT:
            executorService.schedule(() -> responseFuture.completeExceptionally(new TimeoutException(REQUEST_TIMEOUT_MESSAGE)), REQUEST_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
            break;
        case NEVER_COMPLETE:
            // do nothing
            break;
        default:
            throw new RuntimeException("Unknown completion type.");
    }
    final TaskExecutorThreadInfoGateway executorGateway = (taskExecutionAttemptId, requestParams, timeout) -> responseFuture;
    return CompletableFuture.completedFuture(executorGateway);
}
Also used : Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) TaskThreadInfoResponse(org.apache.flink.runtime.messages.TaskThreadInfoResponse) BeforeClass(org.junit.BeforeClass) Matchers.not(org.hamcrest.Matchers.not) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) After(org.junit.After) Duration(java.time.Duration) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) Timeout(org.junit.rules.Timeout) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) AfterClass(org.junit.AfterClass) JvmUtils(org.apache.flink.runtime.util.JvmUtils) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) List(java.util.List) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) TaskThreadInfoResponse(org.apache.flink.runtime.messages.TaskThreadInfoResponse) CompletableFuture(java.util.concurrent.CompletableFuture) ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with TaskExecutorThreadInfoGateway

use of org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway in project flink by apache.

the class ResourceManagerTest method testRequestTaskExecutorGateway.

/**
 * Tests that we can retrieve the correct {@link TaskExecutorGateway} from the {@link
 * ResourceManager}.
 */
@Test
public void testRequestTaskExecutorGateway() throws Exception {
    final ResourceID taskManagerId = ResourceID.generate();
    final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setAddress(UUID.randomUUID().toString()).createTestingTaskExecutorGateway();
    rpcService.registerGateway(taskExecutorGateway.getAddress(), taskExecutorGateway);
    resourceManager = new ResourceManagerBuilder().buildAndStart();
    final ResourceManagerGateway resourceManagerGateway = resourceManager.getSelfGateway(ResourceManagerGateway.class);
    registerTaskExecutor(resourceManagerGateway, taskManagerId, taskExecutorGateway.getAddress());
    CompletableFuture<TaskExecutorThreadInfoGateway> taskExecutorGatewayFuture = resourceManagerGateway.requestTaskExecutorThreadInfoGateway(taskManagerId, TestingUtils.TIMEOUT);
    TaskExecutorThreadInfoGateway taskExecutorGatewayResult = taskExecutorGatewayFuture.get();
    assertEquals(taskExecutorGateway, taskExecutorGatewayResult);
}
Also used : TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) Test(org.junit.Test)

Example 3 with TaskExecutorThreadInfoGateway

use of org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway in project flink by apache.

the class JobVertexThreadInfoTrackerTest method createMockResourceManagerGateway.

private static CompletableFuture<ResourceManagerGateway> createMockResourceManagerGateway() {
    // ignored in TestingThreadInfoRequestCoordinator
    Function<ResourceID, CompletableFuture<TaskExecutorThreadInfoGateway>> function = (resourceID) -> CompletableFuture.completedFuture(null);
    TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
    testingResourceManagerGateway.setRequestTaskExecutorGatewayFunction(function);
    return CompletableFuture.completedFuture(testingResourceManagerGateway);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) BeforeClass(org.junit.BeforeClass) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) RemovalListener(org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener) RemovalNotification(org.apache.flink.shaded.guava30.com.google.common.cache.RemovalNotification) Assert.assertThat(org.junit.Assert.assertThat) Cache(org.apache.flink.shaded.guava30.com.google.common.cache.Cache) Duration(java.time.Duration) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) Timeout(org.junit.rules.Timeout) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) Nonnull(javax.annotation.Nonnull) ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) AfterClass(org.junit.AfterClass) Executor(java.util.concurrent.Executor) JvmUtils(org.apache.flink.runtime.util.JvmUtils) ExecutionGraphTestUtils(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) Assert.assertTrue(org.junit.Assert.assertTrue) CacheBuilder(org.apache.flink.shaded.guava30.com.google.common.cache.CacheBuilder) Test(org.junit.Test) TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) Instant(java.time.Instant) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TestingUtils(org.apache.flink.testutils.TestingUtils) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway) List(java.util.List) JobID(org.apache.flink.api.common.JobID) Rule(org.junit.Rule) ChronoUnit(java.time.temporal.ChronoUnit) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceManagerGateway(org.apache.flink.runtime.resourcemanager.ResourceManagerGateway) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway)

Aggregations

TaskExecutorThreadInfoGateway (org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway)3 Test (org.junit.Test)3 Duration (java.time.Duration)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 TimeUnit (java.util.concurrent.TimeUnit)2 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)2 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)2 ThreadInfoSample (org.apache.flink.runtime.messages.ThreadInfoSample)2 JvmUtils (org.apache.flink.runtime.util.JvmUtils)2 TestLogger (org.apache.flink.util.TestLogger)2 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1