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