jiangxin369 commented on code in PR #23957:
URL: https://github.com/apache/flink/pull/23957#discussion_r1446955961


##########
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/storage/TieredStorageMemoryManagerImplTest.java:
##########
@@ -242,19 +173,49 @@ void testCanNotTransferOwnershipForEvent() throws 
IOException {
                 .isInstanceOf(IllegalStateException.class);
     }
 
+    @Test
+    void testEnsureCapacity() throws IOException {
+        final int numBuffers = 5;
+        final int guaranteedReclaimableBuffers = 3;
+
+        BufferPool bufferPool = globalPool.createBufferPool(numBuffers, 
numBuffers);
+        TieredStorageMemoryManagerImpl storageMemoryManager =
+                createStorageMemoryManager(
+                        bufferPool,
+                        Arrays.asList(
+                                new TieredStorageMemorySpec(
+                                        new Object(), 
guaranteedReclaimableBuffers, true),
+                                new TieredStorageMemorySpec(this, 0, false)));
+        assertThat(storageMemoryManager.ensureCapacity(0)).isTrue();
+        assertThat(bufferPool.bestEffortGetNumOfUsedBuffers())
+                .isEqualTo(guaranteedReclaimableBuffers);
+
+        assertThat(storageMemoryManager.ensureCapacity(numBuffers - 
guaranteedReclaimableBuffers))
+                .isTrue();
+        
assertThat(bufferPool.bestEffortGetNumOfUsedBuffers()).isEqualTo(numBuffers);
+
+        assertThat(
+                        storageMemoryManager.ensureCapacity(
+                                numBuffers - guaranteedReclaimableBuffers + 1))

Review Comment:
   `EnsureCapacity` only requests buffers from the local buffer pool when the 
requested buffers are less than `numGuaranteedReclaimableBuffers + 
numAdditionalBuffers`. If we replace the value with `1`, the capacity we need 
to ensure is `guaranteedReclaimableBuffers(3) + numAdditionalBuffers(1) = 4`, 
so the requested buffers in the queue are already satisfied and the 
`ensureCapacity` will return `true`. However, what I want to test is the 
situation that fails to `ensureCapacity`.



-- 
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

Reply via email to