wsry commented on a change in pull request #18365:
URL: https://github.com/apache/flink/pull/18365#discussion_r785651059



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/PartitionRequestClientFactoryTest.java
##########
@@ -112,6 +115,35 @@ public void testExceptionsAreNotCached() throws Exception {
         }
     }
 
+    @Test
+    public void testReuseNettyPartitionRequestClient() throws Exception {
+        NettyTestUtil.NettyServerAndClient nettyServerAndClient = 
createNettyServerAndClient();
+        try {
+            checkReuseNettyPartitionRequestClient(nettyServerAndClient, 1);
+            checkReuseNettyPartitionRequestClient(nettyServerAndClient, 2);
+            checkReuseNettyPartitionRequestClient(nettyServerAndClient, 5);
+            checkReuseNettyPartitionRequestClient(nettyServerAndClient, 10);
+        } finally {
+            nettyServerAndClient.client().shutdown();
+            nettyServerAndClient.server().shutdown();
+        }
+    }
+
+    private void checkReuseNettyPartitionRequestClient(
+            NettyTestUtil.NettyServerAndClient nettyServerAndClient, int 
maxNumberOfConnections)
+            throws Exception {
+        Set<NettyPartitionRequestClient> set = new HashSet<>();
+
+        final PartitionRequestClientFactory factory =
+                new PartitionRequestClientFactory(
+                        nettyServerAndClient.client(), 0, 
maxNumberOfConnections);
+        for (int i = 0; i < Math.max(100, maxNumberOfConnections); i++) {
+            final ConnectionID connectionID = 
nettyServerAndClient.getConnectionID(i);
+            set.add(factory.createPartitionRequestClient(connectionID));
+        }
+        assertEquals(maxNumberOfConnections, set.size());

Review comment:
       @1996fanrui Hi, thanks for your update. Maybe I did not express it 
clearly which caused misunderstanding. I mean to use random connection index, 
not random connection index count. Because the real connection index is also 
randomly generated, you can refer to the IntermediateResult class for more 
information. In a word, I mean something like this:
   ```
           final Random random = new Random();
           for (int i = 0; i < Math.max(100, maxNumberOfConnections); i++) {
               final ConnectionID connectionID =
                       
nettyServerAndClient.getConnectionID(random.nextInt(Integer.MAX_VALUE));
               set.add(factory.createPartitionRequestClient(connectionID));
           }
           assertTrue(set.size() <= maxNumberOfConnections);
   ```




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