ayushtkn commented on a change in pull request #4028:
URL: https://github.com/apache/hadoop/pull/4028#discussion_r816760498



##########
File path: 
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/TestMiniJournalCluster.java
##########
@@ -52,4 +58,86 @@ public void testStartStop() throws IOException {
       c.shutdown();
     }
   }
+
+  @Test
+  public void testStartStopWithPorts() throws Exception {
+    Configuration conf = new Configuration();
+
+    LambdaTestUtils.intercept(
+        IllegalArgumentException.class,
+        "Num of http ports (1) should match num of JournalNodes (3)",
+        "MiniJournalCluster port validation failed",
+        () -> {
+          new MiniJournalCluster.Builder(conf).setHttpPorts(8481).build();
+        });
+
+    LambdaTestUtils.intercept(
+        IllegalArgumentException.class,
+        "Num of rpc ports (2) should match num of JournalNodes (3)",
+        "MiniJournalCluster port validation failed",
+        () -> {
+          new MiniJournalCluster.Builder(conf).setRpcPorts(8481, 8482).build();
+        });
+
+    LambdaTestUtils.intercept(
+        IllegalArgumentException.class,
+        "Num of rpc ports (1) should match num of JournalNodes (3)",
+        "MiniJournalCluster port validation failed",
+        () -> {
+          new MiniJournalCluster.Builder(conf).setHttpPorts(800, 9000, 
10000).setRpcPorts(8481)
+              .build();
+        });
+
+    LambdaTestUtils.intercept(
+        IllegalArgumentException.class,
+        "Num of http ports (4) should match num of JournalNodes (3)",
+        "MiniJournalCluster port validation failed",
+        () -> {
+          new MiniJournalCluster.Builder(conf).setHttpPorts(800, 9000, 1000, 
2000)
+              .setRpcPorts(8481, 8482, 8483).build();
+        });
+
+    final int[] httpPorts = new int[3];
+    final int[] rpcPorts = new int[3];
+    try (MiniJournalCluster miniJournalCluster = new 
MiniJournalCluster.Builder(conf).build()) {
+      miniJournalCluster.waitActive();
+
+      for (int i = 0; i < 3; i++) {
+        httpPorts[i] = 
miniJournalCluster.getJournalNode(i).getHttpAddress().getPort();
+      }
+
+      for (int i = 0; i < 3; i++) {
+        rpcPorts[i] = 
miniJournalCluster.getJournalNode(i).getRpcServer().getAddress().getPort();
+      }
+    }
+
+    LOG.info("Http ports selected: {}", httpPorts);
+    LOG.info("Rpc ports selected: {}", rpcPorts);

Review comment:
       Is this to just get the free ports?
   Like start the cluster with 0 -> get the ports -> Shutdown the cluster(Ports 
are free)-> Now use them explicitly 
   
   If that is the case, You can explore using ``NetUtils.getFreeSocketPort()``, 
that would fetch you free ports, which you can pass as arguments.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to