Source:
private void runSlotRequestCompletionTest( Supplier<SlotPoolImpl> slotPoolSupplier, Consumer<SlotPoolImpl> actionAfterSlotRequest) throws Exception { try (final SlotPoolImpl slotPool = slotPoolSupplier.get()) { final int requestNum = 10; final List<SlotRequestId> slotRequestIds = IntStream.range(0, requestNum) .mapToObj(ignored -> new SlotRequestId()) .collect(Collectors.toList()); final List<SlotRequest> rmReceivedSlotRequests = new ArrayList<>(requestNum); resourceManagerGateway.setRequestSlotConsumer(request -> rmReceivedSlotRequests.add(request)); final List<CompletableFuture<PhysicalSlot>> slotRequests = slotRequestIds .stream() .map(slotRequestId -> slotPool.requestNewAllocatedSlot(slotRequestId, ResourceProfile.UNKNOWN, TIMEOUT)) .collect(Collectors.toList()); actionAfterSlotRequest.accept(slotPool); final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation(); slotPool.registerTaskManager(taskManagerLocation.getResourceID()); final AllocationID lastAllocationId = rmReceivedSlotRequests.get(requestNum - 1).getAllocationId(); final SlotOffer slotOffer = new SlotOffer(lastAllocationId, 0, ResourceProfile.ANY); final Collection<SlotOffer> acceptedSlots = slotPool.offerSlots(taskManagerLocation, new SimpleAckingTaskManagerGateway(), Collections.singleton(slotOffer)); assertThat(acceptedSlots, containsInAnyOrder(slotOffer)); final FlinkException testingReleaseException = new FlinkException("Testing release exception"); for (int i = 0; i < slotRequestIds.size(); i++) { final CompletableFuture<PhysicalSlot> slotRequestFuture = slotRequests.get(i); assertThat(slotRequestFuture.getNow(null), not(is(nullValue()))); slotPool.releaseSlot(slotRequestIds.get(i), testingReleaseException); } } }

Target:
private void runSlotRequestCompletionTest( Supplier<SlotPoolImpl> slotPoolSupplier, Consumer<SlotPoolImpl> actionAfterSlotRequest) { try (final SlotPoolImpl slotPool = slotPoolSupplier.get()) { final int requestNum = 10; final List<SlotRequestId> slotRequestIds = IntStream.range(0, requestNum) .mapToObj(ignored -> new SlotRequestId()) .collect(Collectors.toList()); final List<SlotRequest> rmReceivedSlotRequests = new ArrayList<>(requestNum); resourceManagerGateway.setRequestSlotConsumer(request -> rmReceivedSlotRequests.add(request)); final List<CompletableFuture<PhysicalSlot>> slotRequests = slotRequestIds .stream() .map(slotRequestId -> slotPool.requestNewAllocatedSlot(slotRequestId, ResourceProfile.UNKNOWN, TIMEOUT)) .collect(Collectors.toList()); actionAfterSlotRequest.accept(slotPool); final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation(); slotPool.registerTaskManager(taskManagerLocation.getResourceID()); final AllocationID lastAllocationId = rmReceivedSlotRequests.get(requestNum - 1).getAllocationId(); final SlotOffer slotOffer = new SlotOffer(lastAllocationId, 0, ResourceProfile.ANY); final Collection<SlotOffer> acceptedSlots = slotPool.offerSlots(taskManagerLocation, new SimpleAckingTaskManagerGateway(), Collections.singleton(slotOffer)); assertThat(acceptedSlots, containsInAnyOrder(slotOffer)); final FlinkException testingReleaseException = new FlinkException("Testing release exception"); for (int i = 0; i < slotRequestIds.size(); i++) { final CompletableFuture<PhysicalSlot> slotRequestFuture = slotRequests.get(i); assertThat(slotRequestFuture.getNow(null), is(not(nullValue()))); slotPool.releaseSlot(slotRequestIds.get(i), testingReleaseException); } } }