You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "TheR1sing3un (via GitHub)" <gi...@apache.org> on 2023/02/16 17:01:32 UTC

[GitHub] [rocketmq] TheR1sing3un commented on a diff in pull request #6068: [ISSUE #6060]Optimize AutoSwitchRoleBase#nextPort method

TheR1sing3un commented on code in PR #6068:
URL: https://github.com/apache/rocketmq/pull/6068#discussion_r1108771653


##########
test/src/test/java/org/apache/rocketmq/test/autoswitchrole/AutoSwitchRoleBase.java:
##########
@@ -69,28 +69,28 @@ protected static void initialize() {
         }
     }
 
-    public static Integer nextPort() throws IOException {
+    public static int nextPort() throws IOException {
         return nextPort(1001, 9999);
     }
 
-    public static Integer nextPort(Integer minPort, Integer maxPort) throws IOException {
+    public static int nextPort(int minPort, int maxPort) throws IOException {
+
         Random random = new Random();
         int tempPort;
         int port;
-        try {
-            while (true) {
+        while (true) {
+            try {
                 tempPort = random.nextInt(maxPort) % (maxPort - minPort + 1) + minPort;
                 ServerSocket serverSocket = new ServerSocket(tempPort);
                 port = serverSocket.getLocalPort();
                 serverSocket.close();
                 break;
+            } catch (IOException ignored) {
+                if (number > 200) {

Review Comment:
   How about merge `numer>200` and `number++` ?  Just `if (number++ >200)`



-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org