ayushtkn commented on a change in pull request #4028:
URL: https://github.com/apache/hadoop/pull/4028#discussion_r816970241
##########
File path:
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/TestMiniJournalCluster.java
##########
@@ -52,4 +59,82 @@ 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[] { NetUtils.getFreeSocketPort(),
NetUtils.getFreeSocketPort(),
+ NetUtils.getFreeSocketPort() };
+ final int[] rpcPorts = new int[] { NetUtils.getFreeSocketPort(),
NetUtils.getFreeSocketPort(),
+ NetUtils.getFreeSocketPort() };
Review comment:
I am not sure about it, would need a second opinion, from the javadoc of
the comment, it feels like it can return same ports.
And logically say port X is the only free port, will it not return port X,
if called again. Not sure how does this behave in different OS.
Tried something like this:
```
HashSet<Integer> hs = new LinkedHashSet();
while(true) {
int port = NetUtils.getFreeSocketPort();
if(!hs.add(port)) {
throw new IOException("Dupe Port "+ port + " ports : " + hs + " size
" + hs.size());
}
```
it threw me an exception on MacOs with higher hs.size and on Ubuntu with
lesser. not sure if there is some logic behind it or not, or just machine
specific. Let me see if I can ask some N/W expert internally
@tomscut in case you have any opinion here.
--
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]