adoroszlai commented on code in PR #5782:
URL: https://github.com/apache/ozone/pull/5782#discussion_r1427745144
##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/protocol/MockDatanodeDetails.java:
##########
@@ -118,11 +128,21 @@ public static DatanodeDetails randomLocalDatanodeDetails()
return createDatanodeDetails(UUID.randomUUID().toString(),
socket.getInetAddress().getHostName(),
socket.getInetAddress().getHostAddress(), null,
- socket.getLocalPort());
+ getFreePort());
Review Comment:
Since we get the port from other source, we can get rid of the
`ServerSocket` allocation. Replace hostname and address with `"localhost"`,
and `"127.0.0.1"`.
With that, `throws IOException` can be removed, as well as unused imports.
##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/protocol/MockDatanodeDetails.java:
##########
@@ -118,11 +128,21 @@ public static DatanodeDetails randomLocalDatanodeDetails()
return createDatanodeDetails(UUID.randomUUID().toString(),
socket.getInetAddress().getHostName(),
socket.getInetAddress().getHostAddress(), null,
- socket.getLocalPort());
+ getFreePort());
}
}
private MockDatanodeDetails() {
throw new UnsupportedOperationException("no instances");
}
+
+ static synchronized int getFreePort() {
+ LOG.info("### Getting free port ###");
+ int port = NEXT_PORT.getAndIncrement();
+ if (port > MAX_PORT) {
+ NEXT_PORT.set(MIN_PORT);
+ port = NEXT_PORT.getAndIncrement();
+ }
+ return port;
+ }
Review Comment:
Please don't duplicate code unless absolutely necessary.
Move `PortAllocator` from `MiniOzoneCluster` to a top-level class in
`hadoop-hdds/test-utils/src/main/java/org/apache/ozone/test`, so that it can be
reused.
Its methods need to be exposed as `public`. Also, please make the top-level
class `final` (also required by checkstyle for utility classes).
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/server/TestSecureContainerServer.java:
##########
@@ -340,4 +346,38 @@ private static String getToken(ContainerID containerID)
throws IOException {
containerTokenSecretManager.createIdentifier(username, containerID)
).encodeToUrlString();
}
+
+ private static void startServerWithRetry(XceiverServerSpi server,
Review Comment:
This can be removed, too.
--
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]