dawidwys commented on a change in pull request #18865:
URL: https://github.com/apache/flink/pull/18865#discussion_r814647353
##########
File path:
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPoolTest.java
##########
@@ -292,6 +292,52 @@ public void
testRequestMemorySegmentsMoreThanTotalBuffers() {
}
}
+ /**
+ * Tests {@link NetworkBufferPool#requestUnpooledMemorySegments(int)} with
the total number of
+ * allocated buffers for several requests exceeding the capacity of {@link
NetworkBufferPool}.
+ */
+ @Test
+ public void testInsufficientNumberOfBuffers() throws Exception {
+ final int numberOfSegmentsToRequest = 5;
+
+ final NetworkBufferPool globalPool = new
NetworkBufferPool(numberOfSegmentsToRequest, 128);
+
+ try {
+ // the global pool should be in available state initially
+ assertTrue(globalPool.getAvailableFuture().isDone());
+
+ // request 5 segments
+ List<MemorySegment> segments1 =
+
globalPool.requestUnpooledMemorySegments(numberOfSegmentsToRequest);
+ assertFalse(globalPool.getAvailableFuture().isDone());
+ assertEquals(numberOfSegmentsToRequest, segments1.size());
+
+ try {
+ // request only 1 segment
+ globalPool.requestUnpooledMemorySegments(1);
+
+ fail("Request for the new buffer should fail since buffers are
not enough.");
+ } catch (IOException insufficientNumberOfBuffer) {
+ assertTrue(
+ insufficientNumberOfBuffer
+ .getMessage()
+ .contains("Insufficient number of network
buffers"));
+ }
Review comment:
Use `assertThrows`?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]