1996fanrui commented on code in PR #25134: URL: https://github.com/apache/flink/pull/25134#discussion_r1705068636
########## flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DeclarativeSlotPoolBridgeResourceDeclarationTest.java: ########## @@ -205,12 +223,36 @@ void testRequirementsDecreasedOnSlotAllocationFailure() throws Exception { .isZero(); } - private static final class RequirementListener { + /** Requirement listener for testing. */ + static final class RequirementListener { Review Comment: After refactor, the original private may be enough, right? ########## flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DeclarativeSlotPoolBridgeTest.java: ########## @@ -252,4 +261,76 @@ void testIfJobIsRestartingAllOfferedSlotsWillBeRegistered() throws Exception { registerSlotsCalledFuture.join(); } } + + @TestTemplate + void testSlotsBatchAllocatableLogic() throws Exception { + final SlotRequestId slotRequestId1 = new SlotRequestId(); + final AllocationID expectedAllocationId1 = new AllocationID(); + final PhysicalSlot allocatedSlot1 = createAllocatedSlot(expectedAllocationId1); + final SlotRequestId slotRequestId2 = new SlotRequestId(); + final AllocationID expectedAllocationId2 = new AllocationID(); + final PhysicalSlot allocatedSlot2 = createAllocatedSlot(expectedAllocationId2); + final Set<AllocationID> availableSlotsIds = new HashSet<>(); + final List<PhysicalSlot> freeSlotsInformation = new ArrayList<>(); + + try (DeclarativeSlotPoolBridge declarativeSlotPoolBridge = + createDeclarativeSlotPoolBridge(freeSlotsInformation, availableSlotsIds)) { + + declarativeSlotPoolBridge.start(JOB_MASTER_ID, "localhost"); + CompletableFuture<PhysicalSlot> slotAllocationFuture1 = + declarativeSlotPoolBridge.requestNewAllocatedSlot( + slotRequestId1, ResourceProfile.UNKNOWN, null); + CompletableFuture<PhysicalSlot> slotAllocationFuture2 = + declarativeSlotPoolBridge.requestNewAllocatedSlot( + slotRequestId2, ResourceProfile.UNKNOWN, null); + tryWaitSlotRequestIsDone(declarativeSlotPoolBridge); + + availableSlotsIds.add(allocatedSlot1.getAllocationId()); + freeSlotsInformation.add(allocatedSlot1); + declarativeSlotPoolBridge.newSlotsAreAvailable(Collections.singleton(allocatedSlot1)); + if (slotBatchAllocatable) { + assertThatFuture(slotAllocationFuture1) + .willNotCompleteWithin(slotRequestMaxInterval.plus(Duration.ofMillis(50))); + assertThatFuture(slotAllocationFuture2) + .willNotCompleteWithin(slotRequestMaxInterval.plus(Duration.ofMillis(50))); + } else { + slotAllocationFuture1.join(); + } + + availableSlotsIds.add(allocatedSlot2.getAllocationId()); + freeSlotsInformation.add(allocatedSlot2); + declarativeSlotPoolBridge.newSlotsAreAvailable(Collections.singleton(allocatedSlot2)); + if (slotBatchAllocatable) { + slotAllocationFuture1.join(); + slotAllocationFuture2.join(); + } else { + slotAllocationFuture2.join(); + } + } + } + + void tryWaitSlotRequestIsDone(DeclarativeSlotPoolBridge declarativeSlotPoolBridge) { Review Comment: Could it be private? -- 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. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org