-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-16481. Provide support to set Http and Rpc ports in MiniJournalCluster #4028
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
Merged
Merged
Changes from 5 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -22,15 +22,23 @@ | |
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.util.Set; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| 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 +60,92 @@ 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 Set<Integer> httpAndRpcPorts = NetUtils.getFreeSocketPorts(6); | ||
| LOG.info("Free socket ports: {}", httpAndRpcPorts); | ||
|
|
||
| final int[] httpPorts = new int[3]; | ||
| final int[] rpcPorts = new int[3]; | ||
| int httpPortIdx = 0; | ||
| int rpcPortIdx = 0; | ||
| for (Integer httpAndRpcPort : httpAndRpcPorts) { | ||
| if (httpPortIdx < 3) { | ||
| httpPorts[httpPortIdx++] = httpAndRpcPort; | ||
| } else { | ||
| rpcPorts[rpcPortIdx++] = httpAndRpcPort; | ||
| } | ||
| } | ||
|
|
||
| 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]); | ||
| } | ||
|
||
|
|
||
| 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.
getFreeSocketPort()as per code can return 0 as well, we should avoid that? We can't classify 0 as a unique free port.if it returns 0, then your test would also fail. you would be expecting the port to be 0, but it would be different
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.
Yes, let me take care of this.