xintongsong commented on a change in pull request #11615: [FLINK-16605] Add max limitation to the total number of slots URL: https://github.com/apache/flink/pull/11615#discussion_r407408627
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerImplTest.java ########## @@ -1540,6 +1555,85 @@ public void testSpreadOutSlotAllocationStrategy() throws Exception { } } + /** + * Test that the slot manager respect the max limitation of the number of slots when allocate new resource. + */ + @Test + public void testRespectMaxLimitBeforeAllocateResource() throws Exception { + final int numberSlots = 1; + final int maxSlotNum = 1; + + final ResourceManagerId resourceManagerId = ResourceManagerId.generate(); + final JobID jobId = new JobID(); + + final AtomicInteger resourceRequests = new AtomicInteger(0); + ResourceActions resourceManagerActions = new TestingResourceActionsBuilder() + .setAllocateResourceFunction( + ignored -> { + resourceRequests.incrementAndGet(); + return true; + }) + .build(); + + final Configuration configuration = new Configuration(); + configuration.setInteger(ResourceManagerOptions.MAX_SLOT_NUM, maxSlotNum); + configuration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, numberSlots); + + try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions, configuration)) { + + assertTrue("The slot request should be accepted", slotManager.registerSlotRequest(createSlotRequest(jobId))); + assertThat(resourceRequests.get(), is(1)); + + // The second slot request should not try to allocate a new resource because of the max limitation. + assertTrue("The slot request should be accepted", slotManager.registerSlotRequest(createSlotRequest(jobId))); + assertThat(resourceRequests.get(), is(1)); + } + } + + /** + * Test that the slot manager release resource when the number of slots exceed max limit when new TaskExecutor registered. + */ + @Test + public void testReleaseResourceWhenExceedMaxLimit() throws Exception { Review comment: ```suggestion public void testMaxSlotLimitRegisterResource() throws Exception { ``` ---------------------------------------------------------------- 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