tillrohrmann commented on a change in pull request #10682: [FLINK-15247][Runtime] Wait for all slots to be free before task executor services shutdown upon stopping URL: https://github.com/apache/flink/pull/10682#discussion_r362841392
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/slot/TaskSlotTableTest.java ########## @@ -243,8 +252,181 @@ public void testGenerateSlotReport() throws SlotNotFoundException { } } + @Test + public void testAllocateSlot() { + final JobID jobId = new JobID(); + final AllocationID allocationId = new AllocationID(); + TaskSlotTable taskSlotTable = null; + try { + taskSlotTable = createTaskSlotTableWithAllocatedSlot( + jobId, + allocationId, + new TestingSlotActionsBuilder().build()); + Iterator<TaskSlot> allocatedSlots = taskSlotTable.getAllocatedSlots(jobId); + TaskSlot nextSlot = allocatedSlots.next(); + assertThat(nextSlot.getIndex(), is(0)); + assertThat(nextSlot.getAllocationId(), is(allocationId)); + assertThat(nextSlot.getJobId(), is(jobId)); + assertThat(allocatedSlots.hasNext(), is(false)); + } finally { + stopTable(taskSlotTable); + } + } + + @Test + public void testAddTask() throws Exception { + final JobID jobId = new JobID(); + final ExecutionAttemptID executionAttemptId = new ExecutionAttemptID(); + final AllocationID allocationId = new AllocationID(); + Task task = createTask( + jobId, + executionAttemptId, + allocationId, + EmptyInvokable.class); + TaskSlotTable taskSlotTable = null; + try { + taskSlotTable = createTaskSlotTableWithStartedTask(task, new TestingSlotActionsBuilder().build()); + Iterator<Task> tasks = taskSlotTable.getTasks(jobId); + Task nextTask = tasks.next(); + assertThat(nextTask.getExecutionId(), is(executionAttemptId)); + assertThat(nextTask.getAllocationId(), is(allocationId)); + assertThat(tasks.hasNext(), is(false)); + taskSlotTable.freeSlot(allocationId); + taskSlotTable.removeTask(executionAttemptId); + } finally { + stopTable(taskSlotTable); + } + } + + @Test(timeout = 10000) + public void testRemoveTaskCallsFreeSlotAction() throws Exception { + final JobID jobId = new JobID(); + final ExecutionAttemptID executionAttemptId = new ExecutionAttemptID(); + final AllocationID allocationId = new AllocationID(); + CompletableFuture<AllocationID> freeSlotFuture = new CompletableFuture<>(); + SlotActions slotActions = new TestingSlotActions(freeSlotFuture::complete, (aid, uid) -> {}); + Task task = createTask( + jobId, + executionAttemptId, + allocationId, + EmptyInvokable.class); + TaskSlotTable taskSlotTable = null; + try { + taskSlotTable = createTaskSlotTableWithStartedTask(task, slotActions); + taskSlotTable.freeSlot(allocationId); + taskSlotTable.removeTask(executionAttemptId); + assertThat(freeSlotFuture.get(), is(allocationId)); + } finally { + stopTable(taskSlotTable); + } + } + + @Test(timeout = 10000) + public void testFreeSlotInterruptsSubmittedTask() throws Exception { + final JobID jobId = new JobID(); + final ExecutionAttemptID executionAttemptId = new ExecutionAttemptID(); + final AllocationID allocationId = new AllocationID(); + Task task = createTask( + jobId, + executionAttemptId, + allocationId, + TestInterruptableInvokable.class); + TaskSlotTable taskSlotTable = null; + try { + taskSlotTable = createTaskSlotTableWithStartedTask(task, new TestingSlotActionsBuilder().build()); + TestInterruptableInvokable.STARTED_FUTURE.get(); + assertThat(taskSlotTable.freeSlot(allocationId), is(-1)); + TestInterruptableInvokable.INTERRUPTED_FUTURE.get(); + CompletableFuture<Void> slotFreeFuture = taskSlotTable.freeAllSlots(null); + assertThat(slotFreeFuture.isDone(), is(false)); + TestInterruptableInvokable.DONE_FUTURE.complete(null); + taskSlotTable.removeTask(executionAttemptId); Review comment: Why is this necessary? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services