Search in sources :

Example 31 with TestingTaskExecutorGatewayBuilder

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

the class JobMasterQueryableStateTest method registerSlotsRequiredForJobExecution.

private static void registerSlotsRequiredForJobExecution(JobMasterGateway jobMasterGateway, JobID jobId) throws ExecutionException, InterruptedException {
    final OneShotLatch oneTaskSubmittedLatch = new OneShotLatch();
    final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setSubmitTaskConsumer((taskDeploymentDescriptor, jobMasterId) -> {
        oneTaskSubmittedLatch.trigger();
        return CompletableFuture.completedFuture(Acknowledge.get());
    }).createTestingTaskExecutorGateway();
    JobMasterTestUtils.registerTaskExecutorAndOfferSlots(rpcService, jobMasterGateway, jobId, PARALLELISM, taskExecutorGateway, testingTimeout);
    oneTaskSubmittedLatch.await();
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) BeforeClass(org.junit.BeforeClass) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobMasterBuilder(org.apache.flink.runtime.jobmaster.utils.JobMasterBuilder) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) CoreMatchers.either(org.hamcrest.CoreMatchers.either) JobStatus(org.apache.flink.api.common.JobStatus) JobType(org.apache.flink.runtime.jobgraph.JobType) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) InetAddress(java.net.InetAddress) Assert.assertThat(org.junit.Assert.assertThat) After(org.junit.After) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) AfterClass(org.junit.AfterClass) UnknownKvStateLocation(org.apache.flink.runtime.query.UnknownKvStateLocation) KvStateLocation(org.apache.flink.runtime.query.KvStateLocation) FlinkMatchers.containsCause(org.apache.flink.core.testutils.FlinkMatchers.containsCause) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) ExecutionException(java.util.concurrent.ExecutionException) JobID(org.apache.flink.api.common.JobID) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) Time(org.apache.flink.api.common.time.Time) KvStateID(org.apache.flink.queryablestate.KvStateID) Assert.assertEquals(org.junit.Assert.assertEquals) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)

Example 32 with TestingTaskExecutorGatewayBuilder

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

the class ResourceManagerTest method testRequestTaskManagerInfo.

/**
 * Tests that we can retrieve the correct {@link TaskManagerInfo} from the {@link
 * ResourceManager}.
 */
@Test
public void testRequestTaskManagerInfo() 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<TaskManagerInfoWithSlots> taskManagerInfoFuture = resourceManagerGateway.requestTaskManagerDetailsInfo(taskManagerId, TestingUtils.TIMEOUT);
    TaskManagerInfoWithSlots taskManagerInfoWithSlots = taskManagerInfoFuture.get();
    TaskManagerInfo taskManagerInfo = taskManagerInfoWithSlots.getTaskManagerInfo();
    assertEquals(taskManagerId, taskManagerInfo.getResourceId());
    assertEquals(hardwareDescription, taskManagerInfo.getHardwareDescription());
    assertEquals(taskExecutorGateway.getAddress(), taskManagerInfo.getAddress());
    assertEquals(dataPort, taskManagerInfo.getDataPort());
    assertEquals(jmxPort, taskManagerInfo.getJmxPort());
    assertEquals(0, taskManagerInfo.getNumberSlots());
    assertEquals(0, taskManagerInfo.getNumberAvailableSlots());
    assertThat(taskManagerInfoWithSlots.getAllocatedSlots(), is(empty()));
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TaskManagerInfo(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerInfo) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) Test(org.junit.Test)

Example 33 with TestingTaskExecutorGatewayBuilder

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

the class ResourceManagerTest method testDisconnectTaskManager.

@Test
public void testDisconnectTaskManager() throws Exception {
    final ResourceID taskExecutorId = ResourceID.generate();
    final CompletableFuture<Exception> disconnectFuture = new CompletableFuture<>();
    final CompletableFuture<ResourceID> stopWorkerFuture = new CompletableFuture<>();
    final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setDisconnectResourceManagerConsumer(disconnectFuture::complete).createTestingTaskExecutorGateway();
    rpcService.registerGateway(taskExecutorGateway.getAddress(), taskExecutorGateway);
    resourceManager = new ResourceManagerBuilder().withStopWorkerFunction(stopWorkerFuture::complete).buildAndStart();
    registerTaskExecutor(resourceManager, taskExecutorId, taskExecutorGateway.getAddress());
    resourceManager.disconnectTaskManager(taskExecutorId, new FlinkException("Test exception"));
    assertThat(disconnectFuture.get(), instanceOf(FlinkException.class));
    assertThat(stopWorkerFuture.get(), is(taskExecutorId));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) TimeoutException(java.util.concurrent.TimeoutException) FlinkException(org.apache.flink.util.FlinkException) ResourceManagerException(org.apache.flink.runtime.resourcemanager.exceptions.ResourceManagerException) RecipientUnreachableException(org.apache.flink.runtime.rpc.exceptions.RecipientUnreachableException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 34 with TestingTaskExecutorGatewayBuilder

use of org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder 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 35 with TestingTaskExecutorGatewayBuilder

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

the class ResourceManagerTest method testTaskExecutorBecomesUnreachableTriggersDisconnect.

@Test
public void testTaskExecutorBecomesUnreachableTriggersDisconnect() throws Exception {
    final ResourceID taskExecutorId = ResourceID.generate();
    final CompletableFuture<Exception> disconnectFuture = new CompletableFuture<>();
    final CompletableFuture<ResourceID> stopWorkerFuture = new CompletableFuture<>();
    final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setAddress(UUID.randomUUID().toString()).setDisconnectResourceManagerConsumer(disconnectFuture::complete).setHeartbeatResourceManagerFunction(resourceId -> FutureUtils.completedExceptionally(new RecipientUnreachableException("sender", "recipient", "task executor is unreachable"))).createTestingTaskExecutorGateway();
    rpcService.registerGateway(taskExecutorGateway.getAddress(), taskExecutorGateway);
    runHeartbeatTargetBecomesUnreachableTest(builder -> builder.withStopWorkerFunction((worker) -> {
        stopWorkerFuture.complete(worker);
        return true;
    }), resourceManagerGateway -> registerTaskExecutor(resourceManagerGateway, taskExecutorId, taskExecutorGateway.getAddress()), resourceManagerResourceId -> {
        assertThat(disconnectFuture.get(), instanceOf(ResourceManagerException.class));
        assertThat(stopWorkerFuture.get(), is(taskExecutorId));
    });
}
Also used : RegistrationResponse(org.apache.flink.runtime.registration.RegistrationResponse) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) ResourceRequirement(org.apache.flink.runtime.slots.ResourceRequirement) TimeoutException(java.util.concurrent.TimeoutException) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) SettableLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService) TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) After(org.junit.After) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestLogger(org.apache.flink.util.TestLogger) TestingJobMasterGatewayBuilder(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGatewayBuilder) Assert.fail(org.junit.Assert.fail) AfterClass(org.junit.AfterClass) UUID(java.util.UUID) ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) TestingUtils(org.apache.flink.testutils.TestingUtils) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Matchers.anyOf(org.hamcrest.Matchers.anyOf) Time(org.apache.flink.api.common.time.Time) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) FlinkException(org.apache.flink.util.FlinkException) BeforeClass(org.junit.BeforeClass) TaskExecutorMemoryConfiguration(org.apache.flink.runtime.taskexecutor.TaskExecutorMemoryConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) Function(java.util.function.Function) TestingJobMasterGateway(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGateway) DeclarativeSlotManagerBuilder(org.apache.flink.runtime.resourcemanager.slotmanager.DeclarativeSlotManagerBuilder) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) ResourceManagerException(org.apache.flink.runtime.resourcemanager.exceptions.ResourceManagerException) NoOpResourceManagerPartitionTracker(org.apache.flink.runtime.io.network.partition.NoOpResourceManagerPartitionTracker) SlotManager(org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ResourceRequirements(org.apache.flink.runtime.slots.ResourceRequirements) ThrowingConsumer(org.apache.flink.util.function.ThrowingConsumer) Before(org.junit.Before) Matchers.empty(org.hamcrest.Matchers.empty) TestingLeaderElectionService(org.apache.flink.runtime.leaderelection.TestingLeaderElectionService) HardwareDescription(org.apache.flink.runtime.instance.HardwareDescription) TaskManagerInfo(org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerInfo) Test(org.junit.Test) TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) JobID(org.apache.flink.api.common.JobID) UnregisteredMetricGroups(org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) TestingSlotManagerBuilder(org.apache.flink.runtime.resourcemanager.slotmanager.TestingSlotManagerBuilder) TestingHighAvailabilityServices(org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RecipientUnreachableException(org.apache.flink.runtime.rpc.exceptions.RecipientUnreachableException) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) RecipientUnreachableException(org.apache.flink.runtime.rpc.exceptions.RecipientUnreachableException) TaskExecutorGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorGateway) TestingTaskExecutorGatewayBuilder(org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder) ResourceManagerException(org.apache.flink.runtime.resourcemanager.exceptions.ResourceManagerException) TimeoutException(java.util.concurrent.TimeoutException) FlinkException(org.apache.flink.util.FlinkException) ResourceManagerException(org.apache.flink.runtime.resourcemanager.exceptions.ResourceManagerException) RecipientUnreachableException(org.apache.flink.runtime.rpc.exceptions.RecipientUnreachableException) Test(org.junit.Test)

Aggregations

TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)60 Test (org.junit.Test)56 CompletableFuture (java.util.concurrent.CompletableFuture)45 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)45 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)43 JobID (org.apache.flink.api.common.JobID)39 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)37 TaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TaskExecutorGateway)37 Acknowledge (org.apache.flink.runtime.messages.Acknowledge)36 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)35 Matchers.empty (org.hamcrest.Matchers.empty)30 Collections (java.util.Collections)29 TestLogger (org.apache.flink.util.TestLogger)29 Matchers.equalTo (org.hamcrest.Matchers.equalTo)29 Matchers.is (org.hamcrest.Matchers.is)29 ArrayList (java.util.ArrayList)28 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)28 ResourceManagerId (org.apache.flink.runtime.resourcemanager.ResourceManagerId)28 TaskExecutorConnection (org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)28 SlotReport (org.apache.flink.runtime.taskexecutor.SlotReport)28