|
17 | 17 | */ |
18 | 18 | package org.apache.hadoop.hdfs.qjournal.server; |
19 | 19 |
|
| 20 | +import java.net.InetSocketAddress; |
| 21 | +import java.net.URISyntaxException; |
20 | 22 | import java.util.function.Supplier; |
21 | 23 | import org.apache.hadoop.conf.Configuration; |
22 | 24 | import org.apache.hadoop.fs.Path; |
|
34 | 36 | import static org.apache.hadoop.hdfs.server.namenode.FileJournalManager |
35 | 37 | .getLogFile; |
36 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
| 39 | +import static org.junit.Assert.assertEquals; |
37 | 40 |
|
38 | 41 | import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; |
39 | 42 | import org.apache.hadoop.test.GenericTestUtils; |
@@ -96,12 +99,45 @@ public void shutDownMiniCluster() throws IOException { |
96 | 99 | } |
97 | 100 | } |
98 | 101 |
|
| 102 | + /** |
| 103 | + * Test that the "self exclusion" works when there are multiple JournalNode instances running on |
| 104 | + * the same server, but on different ports. |
| 105 | + */ |
| 106 | + @Test |
| 107 | + public void testJournalNodeExcludesSelfMultilpePorts() throws URISyntaxException, IOException { |
| 108 | + String uri = qjmhaCluster.getJournalCluster().getQuorumJournalURI("ns1").toString(); |
| 109 | + JournalNodeSyncer syncer = jCluster.getJournalNode(0).getJournalSyncer("ns1"); |
| 110 | + |
| 111 | + // Test: Get the Journal address list for the default configuration |
| 112 | + List<InetSocketAddress> addrList = syncer.getJournalAddrList(uri); |
| 113 | + |
| 114 | + // Verify: One of the addresses should be excluded so that the node isn't syncing with itself |
| 115 | + assertEquals(2, addrList.size()); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Test that the "self exclusion" works when there a host uses a wildcard address. |
| 120 | + */ |
| 121 | + @Test |
| 122 | + public void testJournalNodeExcludesSelfWildCard() throws URISyntaxException, IOException { |
| 123 | + String uri = qjmhaCluster.getJournalCluster().getQuorumJournalURI("ns1").toString(); |
| 124 | + JournalNodeSyncer syncer = jCluster.getJournalNode(0).getJournalSyncer("ns1"); |
| 125 | + |
| 126 | + // Test: Request the same Journal address list, but using the IPv4 "0.0.0.0" which is commonly |
| 127 | + // used as a bind host. |
| 128 | + String boundHostUri = uri.replaceAll("127.0.0.1", "0.0.0.0"); |
| 129 | + List<InetSocketAddress> boundHostAddrList = syncer.getJournalAddrList(boundHostUri); |
| 130 | + |
| 131 | + // Verify: One of the address should be excluded so that the node isn't syncing with itself |
| 132 | + assertEquals(2, boundHostAddrList.size()); |
| 133 | + } |
| 134 | + |
99 | 135 | @Test(timeout=30000) |
100 | 136 | public void testJournalNodeSync() throws Exception { |
101 | 137 |
|
102 | 138 | //As by default 3 journal nodes are started; |
103 | 139 | for(int i=0; i<3; i++) { |
104 | | - Assert.assertEquals(true, |
| 140 | + assertEquals(true, |
105 | 141 | jCluster.getJournalNode(i).getJournalSyncerStatus("ns1")); |
106 | 142 | } |
107 | 143 |
|
@@ -386,13 +422,13 @@ public void testSyncDuringRollingUpgrade() throws Exception { |
386 | 422 | HdfsConstants.RollingUpgradeAction.PREPARE); |
387 | 423 |
|
388 | 424 | //query rolling upgrade |
389 | | - Assert.assertEquals(info, dfsActive.rollingUpgrade( |
| 425 | + assertEquals(info, dfsActive.rollingUpgrade( |
390 | 426 | HdfsConstants.RollingUpgradeAction.QUERY)); |
391 | 427 |
|
392 | 428 | // Restart the Standby NN with rollingUpgrade option |
393 | 429 | dfsCluster.restartNameNode(standbyNNindex, true, |
394 | 430 | "-rollingUpgrade", "started"); |
395 | | - Assert.assertEquals(info, dfsActive.rollingUpgrade( |
| 431 | + assertEquals(info, dfsActive.rollingUpgrade( |
396 | 432 | HdfsConstants.RollingUpgradeAction.QUERY)); |
397 | 433 |
|
398 | 434 | // Do some edits and delete some edit logs |
@@ -420,7 +456,7 @@ public void testSyncDuringRollingUpgrade() throws Exception { |
420 | 456 | // Restart the current standby NN (previously active) |
421 | 457 | dfsCluster.restartNameNode(standbyNNindex, true, |
422 | 458 | "-rollingUpgrade", "started"); |
423 | | - Assert.assertEquals(info, dfsActive.rollingUpgrade( |
| 459 | + assertEquals(info, dfsActive.rollingUpgrade( |
424 | 460 | HdfsConstants.RollingUpgradeAction.QUERY)); |
425 | 461 | dfsCluster.waitActive(); |
426 | 462 |
|
|
0 commit comments