Search in sources :

Example 31 with TestingJobMasterGateway

use of org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGateway in project flink by apache.

the class TaskExecutorExecutionDeploymentReconciliationTest method testDeployedExecutionReporting.

@Test
public void testDeployedExecutionReporting() throws Exception {
    final OneShotLatch slotOfferLatch = new OneShotLatch();
    final BlockingQueue<Set<ExecutionAttemptID>> deployedExecutionsQueue = new ArrayBlockingQueue<>(3);
    final CompletableFuture<Void> taskFinishedFuture = new CompletableFuture<>();
    final ResourceID jobManagerResourceId = ResourceID.generate();
    final TestingJobMasterGateway jobMasterGateway = setupJobManagerGateway(slotOfferLatch, deployedExecutionsQueue, taskFinishedFuture, jobManagerResourceId);
    final CompletableFuture<SlotReport> initialSlotReportFuture = new CompletableFuture<>();
    final TestingResourceManagerGateway testingResourceManagerGateway = setupResourceManagerGateway(initialSlotReportFuture);
    final TaskManagerServices taskManagerServices = new TaskManagerServicesBuilder().setTaskSlotTable(TaskSlotUtils.createTaskSlotTable(1, timeout)).setShuffleEnvironment(new NettyShuffleEnvironmentBuilder().build()).build();
    final TestingTaskExecutor taskExecutor = createTestingTaskExecutor(taskManagerServices);
    try {
        taskExecutor.start();
        taskExecutor.waitUntilStarted();
        final TaskExecutorGateway taskExecutorGateway = taskExecutor.getSelfGateway(TaskExecutorGateway.class);
        final TaskDeploymentDescriptor taskDeploymentDescriptor = createTaskDeploymentDescriptor(jobId);
        connectComponentsAndRequestSlot(jobMasterGateway, testingResourceManagerGateway, taskExecutorGateway, taskManagerServices.getJobLeaderService(), initialSlotReportFuture, taskDeploymentDescriptor.getAllocationId());
        TestingInvokable.sync = new BlockerSync();
        // This ensures TM has been successfully registered to JM.
        slotOfferLatch.await();
        AllocatedSlotReport slotAllocationReport = new AllocatedSlotReport(jobId, Collections.singleton(new AllocatedSlotInfo(0, taskDeploymentDescriptor.getAllocationId())));
        // nothing as deployed, so the deployment report should be empty
        taskExecutorGateway.heartbeatFromJobManager(jobManagerResourceId, slotAllocationReport);
        assertThat(deployedExecutionsQueue.take(), hasSize(0));
        taskExecutorGateway.submitTask(taskDeploymentDescriptor, jobMasterGateway.getFencingToken(), timeout).get();
        TestingInvokable.sync.awaitBlocker();
        // task is deployed, so the deployment report should contain it
        taskExecutorGateway.heartbeatFromJobManager(jobManagerResourceId, slotAllocationReport);
        assertThat(deployedExecutionsQueue.take(), hasItem(taskDeploymentDescriptor.getExecutionAttemptId()));
        TestingInvokable.sync.releaseBlocker();
        // task is finished ans was cleaned up, so the deployment report should be empty
        taskFinishedFuture.get();
        taskExecutorGateway.heartbeatFromJobManager(jobManagerResourceId, slotAllocationReport);
        assertThat(deployedExecutionsQueue.take(), hasSize(0));
    } finally {
        RpcUtils.terminateRpcEndpoint(taskExecutor, timeout);
    }
}
Also used : BlockerSync(org.apache.flink.core.testutils.BlockerSync) Set(java.util.Set) AllocatedSlotReport(org.apache.flink.runtime.jobmaster.AllocatedSlotReport) AllocatedSlotReport(org.apache.flink.runtime.jobmaster.AllocatedSlotReport) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) TestingJobMasterGateway(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGateway) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) TaskDeploymentDescriptor(org.apache.flink.runtime.deployment.TaskDeploymentDescriptor) AllocatedSlotInfo(org.apache.flink.runtime.jobmaster.AllocatedSlotInfo) Test(org.junit.Test)

Aggregations

TestingJobMasterGateway (org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGateway)31 CompletableFuture (java.util.concurrent.CompletableFuture)30 TestingJobMasterGatewayBuilder (org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGatewayBuilder)28 Test (org.junit.Test)28 JobID (org.apache.flink.api.common.JobID)26 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)23 SettableLeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService)23 TestLogger (org.apache.flink.util.TestLogger)23 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)22 TestingHighAvailabilityServices (org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices)21 Rule (org.junit.Rule)21 Assert.assertThat (org.junit.Assert.assertThat)20 UUID (java.util.UUID)19 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)19 Time (org.apache.flink.api.common.time.Time)19 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)19 Collection (java.util.Collection)18 Collections (java.util.Collections)18 BlockingQueue (java.util.concurrent.BlockingQueue)18 TimeUnit (java.util.concurrent.TimeUnit)18