virajjasani commented on a change in pull request #4108: URL: https://github.com/apache/hadoop/pull/4108#discussion_r839439653
########## File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java ########## @@ -319,4 +327,88 @@ public void testSetUpFederatedCluster() throws Exception { cluster.restartNameNode(1); } } + + @Test + public void testStartStopWithPorts() throws Exception { + Configuration conf = new Configuration(); + + LambdaTestUtils.intercept( + IllegalArgumentException.class, + "Num of http ports (1) should match num of DataNodes (3)", + "MiniJournalCluster port validation failed", + () -> { + new MiniDFSCluster.Builder(conf).numDataNodes(3).setDnHttpPorts(8481).build(); + }); + + LambdaTestUtils.intercept( + IllegalArgumentException.class, + "Num of ipc ports (2) should match num of DataNodes (1)", + "MiniJournalCluster port validation failed", + () -> { + new MiniDFSCluster.Builder(conf).setDnIpcPorts(8481, 8482).build(); + }); + + LambdaTestUtils.intercept( + IllegalArgumentException.class, + "Num of ipc ports (1) should match num of DataNodes (3)", + "MiniJournalCluster port validation failed", + () -> { + new MiniDFSCluster.Builder(conf).numDataNodes(3).setDnHttpPorts(800, 9000, 10000) + .setDnIpcPorts(8481).build(); + }); + + LambdaTestUtils.intercept( + IllegalArgumentException.class, + "Num of http ports (4) should match num of DataNodes (3)", + "MiniJournalCluster port validation failed", + () -> { + new MiniDFSCluster.Builder(conf).setDnHttpPorts(800, 9000, 1000, 2000) + .setDnIpcPorts(8481, 8482, 8483).numDataNodes(3).build(); + }); + + final Set<Integer> httpAndIpcPorts = NetUtils.getFreeSocketPorts(6); + LOG.info("Free socket ports: {}", httpAndIpcPorts); + + for (Integer httpAndIpcPort : httpAndIpcPorts) { + assertNotEquals("None of the acquired socket port should not be zero", 0, + httpAndIpcPort.intValue()); + } Review comment: Ok you were talking about `assertj.core` library's assertThat and not the one from `org.junit`. I think it makes sense, just used assertj.core assertThat locally to see how it is working, it seems good one and yes it does simplify entire for loop. Let me make this change. -- 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: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org