Source:
public void testPendingBatchSlotRequestTimeoutAfterSlotRelease() throws Exception { final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); final ManualClock clock = new ManualClock(); final Time batchSlotTimeout = Time.milliseconds(1000L); try (final TestingSlotPoolImpl slotPool = createAndSetUpSlotPool( directMainThreadExecutor, null, batchSlotTimeout, clock)) { final ResourceID taskManagerResourceId = SlotPoolUtils.offerSlots(slotPool, directMainThreadExecutor, Collections.singletonList(resourceProfile)); final List<ResourceProfile> resourceProfiles = Arrays.asList( resourceProfile, ResourceProfile.UNKNOWN, smallerResourceProfile); final List<CompletableFuture<PhysicalSlot>> slotFutures = SlotPoolUtils.requestNewAllocatedBatchSlots( slotPool, directMainThreadExecutor, resourceProfiles ); advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, clock, batchSlotTimeout); assertThat(CompletableFuture.anyOf(slotFutures.toArray(COMPLETABLE_FUTURES_EMPTY_ARRAY)).isDone(), is(false)); SlotPoolUtils.releaseTaskManager(slotPool, directMainThreadExecutor, taskManagerResourceId); advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, clock, batchSlotTimeout); for (CompletableFuture<PhysicalSlot> slotFuture : slotFutures) { assertThat(slotFuture.isCompletedExceptionally(), is(true)); try { slotFuture.get(); fail("Expected that the slot future times out."); } catch (ExecutionException ee) { assertThat(ExceptionUtils.stripExecutionException(ee), instanceOf(TimeoutException.class)); } } } }

Target:
public void testPendingBatchSlotRequestTimeoutAfterSlotRelease() throws Exception { final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread(); final ManualClock clock = new ManualClock(); final Time batchSlotTimeout = Time.milliseconds(1000L); try (final TestingSlotPoolImpl slotPool = createAndSetUpSlotPool( directMainThreadExecutor, null, batchSlotTimeout, clock)) { final ResourceID taskManagerResourceId = SlotPoolUtils.offerSlots(slotPool, directMainThreadExecutor, Collections.singletonList(resourceProfile)); final CompletableFuture<PhysicalSlot> firstSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile); final CompletableFuture<PhysicalSlot> secondSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, ResourceProfile.UNKNOWN); final CompletableFuture<PhysicalSlot> thirdSlotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, smallerResourceProfile); final List<CompletableFuture<PhysicalSlot>> slotFutures = Arrays.asList(firstSlotFuture, secondSlotFuture, thirdSlotFuture); advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, clock, batchSlotTimeout); assertThat(CompletableFuture.anyOf(slotFutures.toArray(COMPLETABLE_FUTURES_EMPTY_ARRAY)).isDone(), is(false)); SlotPoolUtils.releaseTaskManager(slotPool, directMainThreadExecutor, taskManagerResourceId); advanceTimeAndTriggerCheckBatchSlotTimeout(slotPool, clock, batchSlotTimeout); for (CompletableFuture<PhysicalSlot> slotFuture : slotFutures) { assertThat(slotFuture.isCompletedExceptionally(), is(true)); try { slotFuture.get(); fail("Expected that the slot future times out."); } catch (ExecutionException ee) { assertThat(ExceptionUtils.stripExecutionException(ee), instanceOf(TimeoutException.class)); } } } }