-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HDFS-16481. Provide support to set Http and Rpc ports in MiniJournalCluster #4028
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
948305f
HDFS-16481. Provide support to set Http and Rpc ports in MiniJournalC…
virajjasani 5833956
fix checkstyle
virajjasani e70c311
addressing reviews from @ayushtkn and @tomscut
virajjasani 24fa464
addressing recent review
virajjasani bcf8a15
adding new utility to acquire free ports
virajjasani 68e7e2e
exclude 0 in the free ports
virajjasani 84e430e
assert all acquire ports
virajjasani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,17 @@ | |
import org.apache.hadoop.hdfs.DFSConfigKeys; | ||
import org.apache.hadoop.hdfs.MiniDFSCluster; | ||
import org.apache.hadoop.hdfs.qjournal.server.JournalNode; | ||
import org.junit.Test; | ||
import org.apache.hadoop.net.NetUtils; | ||
import org.apache.hadoop.test.LambdaTestUtils; | ||
|
||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TestMiniJournalCluster { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(TestMiniJournalCluster.class); | ||
|
||
@Test | ||
public void testStartStop() throws IOException { | ||
Configuration conf = new Configuration(); | ||
|
@@ -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() }; | ||
|
||
LOG.info("Http ports selected: {}", httpPorts); | ||
LOG.info("Rpc ports selected: {}", rpcPorts); | ||
|
||
for (int i = 0; i < 3; i++) { | ||
assertNotEquals(0, rpcPorts[i]); | ||
assertNotEquals(0, httpPorts[i]); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could have asserted directly on httpAndRpcPorts. :-)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, Thanks. |
||
|
||
try (MiniJournalCluster miniJournalCluster = new MiniJournalCluster.Builder(conf) | ||
.setHttpPorts(httpPorts) | ||
.setRpcPorts(rpcPorts).build()) { | ||
miniJournalCluster.waitActive(); | ||
URI uri = miniJournalCluster.getQuorumJournalURI("myjournal"); | ||
String[] addrs = uri.getAuthority().split(";"); | ||
assertEquals(3, addrs.length); | ||
|
||
assertEquals(httpPorts[0], miniJournalCluster.getJournalNode(0).getHttpAddress().getPort()); | ||
assertEquals(httpPorts[1], miniJournalCluster.getJournalNode(1).getHttpAddress().getPort()); | ||
assertEquals(httpPorts[2], miniJournalCluster.getJournalNode(2).getHttpAddress().getPort()); | ||
|
||
assertEquals(rpcPorts[0], | ||
miniJournalCluster.getJournalNode(0).getRpcServer().getAddress().getPort()); | ||
assertEquals(rpcPorts[1], | ||
miniJournalCluster.getJournalNode(1).getRpcServer().getAddress().getPort()); | ||
assertEquals(rpcPorts[2], | ||
miniJournalCluster.getJournalNode(2).getRpcServer().getAddress().getPort()); | ||
|
||
JournalNode node = miniJournalCluster.getJournalNode(0); | ||
String dir = node.getConf().get(DFSConfigKeys.DFS_JOURNALNODE_EDITS_DIR_KEY); | ||
assertEquals(new File(MiniDFSCluster.getBaseDirectory() + "journalnode-0").getAbsolutePath(), | ||
dir); | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work in all cases, the same port can be returned, say you are calling
NetUtils.getFreeSocketPort()
6 times, it is possible it won't return 6 different ports, it can have dupes.Can have a util method added in NetUtils, Something like this(Just for idea, can improve/fix)
And we can consume the output of this method.
If possible, Please extend a test in
TestNetUtils
as well. A simple test should do:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the exact increments in the ports as per the logs:
And so on..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ayushtkn for ping me and your advice.
NetUtils.getFreeSocketPort()
returns the currently freeport, which may be occupied if not immediately used.If we set the port to 0, the system will automatically assign a free port for us. Then we'll see which ports are actually being used and do assert. Is that ok? As @virajjasani mentioned here .
Please point out if I understand wrong. Thanks. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ayushtkn @tomscut There is nothing wrong with providing the utility as mentioned by Ayush above. I believe it is better to fail the test if we can not get 6 free ports for this UT and once we do get free ports, we can go ahead with the UT. I will make the change.