zhijiangW commented on a change in pull request #9993: 
[FLINK-14498][runtime]Introduce NetworkBufferPool#isAvailable() for interacting 
with LocalBufferPool.
URL: https://github.com/apache/flink/pull/9993#discussion_r339398713
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPoolTest.java
 ##########
 @@ -518,4 +528,176 @@ public void go() throws Exception {
                        globalPool.destroy();
                }
        }
+
+       /**
+        * Tests {@link NetworkBufferPool#isAvailable()}, verifying that the 
buffer availability is
+        * correctly maintained and the future callback is correctly processed.
+        */
+       @Test
+       public void testBufferAvailabilityAndFutureCallback() throws Exception {
+               final int numBuffers = 10;
+               final int numberOfSegmentsToRequest = 5;
+               final Duration requestSegmentsTimeout = Duration.ofSeconds(10L);
+
+               final NetworkBufferPool globalPool = new NetworkBufferPool(
+                               numBuffers,
+                               128,
+                               numberOfSegmentsToRequest,
+                               requestSegmentsTimeout);
+
+               try {
+                       assertTrue(globalPool.isAvailable().isDone());
+
+                       List<MemorySegment> segments = new 
ArrayList<>(numberOfSegmentsToRequest);
+                       for (int i = 0; i < numberOfSegmentsToRequest; ++i) {
+                               MemorySegment segment = 
globalPool.requestMemorySegment();
+                               assertNotNull(segment);
+                               segments.add(segment);
+                               assertTrue(globalPool.isAvailable().isDone());
+                       }
 
 Review comment:
   It is better to extract a separate test for only verifying the logic of 
`globalPool.requestMemorySegment()`. E.g. before requesting the single segment 
the global pool is available, and after requesting it becomes unavailable.
   
   This test mixes many functions to be  verified together, then it is 
difficult to trace the logic and maintain the code future.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to