Skip to content

Commit 7f6734c

Browse files
authored
Merge branch 'apache:trunk' into HADOOP-19425
2 parents 0cb509f + 81146fe commit 7f6734c

File tree

172 files changed

+3091
-2893
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+3091
-2893
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestClusterTopology.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
import org.apache.commons.lang3.tuple.Pair;
2727
import org.apache.commons.math3.stat.inference.ChiSquareTest;
2828
import org.apache.hadoop.conf.Configuration;
29-
import org.junit.Assert;
30-
import org.junit.Test;
29+
import org.junit.jupiter.api.Assertions;
30+
import org.junit.jupiter.api.Test;
3131

32-
public class TestClusterTopology extends Assert {
32+
public class TestClusterTopology extends Assertions {
3333

3434
public static class NodeElement implements Node {
3535
private String location;
@@ -96,34 +96,33 @@ public void testCountNumNodes() throws Exception {
9696
// create exclude list
9797
List<Node> excludedNodes = new ArrayList<Node>();
9898

99-
assertEquals("4 nodes should be available", 4,
100-
cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes));
99+
assertEquals(4, cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes),
100+
"4 nodes should be available");
101101
NodeElement deadNode = getNewNode("node5", "/d1/r2");
102102
excludedNodes.add(deadNode);
103-
assertEquals("4 nodes should be available with extra excluded Node", 4,
104-
cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes));
103+
assertEquals(4, cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes),
104+
"4 nodes should be available with extra excluded Node");
105105
// add one existing node to exclude list
106106
excludedNodes.add(node4);
107-
assertEquals("excluded nodes with ROOT scope should be considered", 3,
108-
cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes));
109-
assertEquals("excluded nodes without ~ scope should be considered", 2,
110-
cluster.countNumOfAvailableNodes("~" + deadNode.getNetworkLocation(),
111-
excludedNodes));
112-
assertEquals("excluded nodes with rack scope should be considered", 1,
113-
cluster.countNumOfAvailableNodes(deadNode.getNetworkLocation(),
114-
excludedNodes));
107+
assertEquals(3, cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes),
108+
"excluded nodes with ROOT scope should be considered");
109+
assertEquals(2,
110+
cluster.countNumOfAvailableNodes("~" + deadNode.getNetworkLocation(), excludedNodes),
111+
"excluded nodes without ~ scope should be considered");
112+
assertEquals(1, cluster.countNumOfAvailableNodes(deadNode.getNetworkLocation(),
113+
excludedNodes), "excluded nodes with rack scope should be considered");
115114
// adding the node in excluded scope to excluded list
116115
excludedNodes.add(node2);
117-
assertEquals("excluded nodes with ~ scope should be considered", 2,
118-
cluster.countNumOfAvailableNodes("~" + deadNode.getNetworkLocation(),
119-
excludedNodes));
116+
assertEquals(2,
117+
cluster.countNumOfAvailableNodes("~" + deadNode.getNetworkLocation(), excludedNodes),
118+
"excluded nodes with ~ scope should be considered");
120119
// getting count with non-exist scope.
121-
assertEquals("No nodes should be considered for non-exist scope", 0,
122-
cluster.countNumOfAvailableNodes("/non-exist", excludedNodes));
120+
assertEquals(0, cluster.countNumOfAvailableNodes("/non-exist", excludedNodes),
121+
"No nodes should be considered for non-exist scope");
123122
// remove a node from the cluster
124123
cluster.remove(node1);
125-
assertEquals("1 node should be available", 1,
126-
cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes));
124+
assertEquals(1, cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes),
125+
"1 node should be available");
127126
}
128127

129128
/**
@@ -160,7 +159,7 @@ public void testChooseRandom() {
160159
}
161160
histogram.put(randomNode, histogram.get(randomNode) + 1);
162161
}
163-
assertEquals("Random is not selecting all nodes", 4, histogram.size());
162+
assertEquals(4, histogram.size(), "Random is not selecting all nodes");
164163

165164
// Check with 99% confidence alpha=0.01 as confidence = 100 * (1 - alpha)
166165
ChiSquareTest chiSquareTest = new ChiSquareTest();
@@ -181,8 +180,8 @@ public void testChooseRandom() {
181180
}
182181

183182
// Check that they have the proper distribution
184-
assertFalse("Random not choosing nodes with proper distribution",
185-
chiSquareTestRejectedCounter==3);
183+
assertFalse(chiSquareTestRejectedCounter == 3,
184+
"Random not choosing nodes with proper distribution");
186185

187186
// Pick random nodes excluding the 2 nodes in /d1/r3
188187
HashMap<String, Integer> histogram = new HashMap<String, Integer>();
@@ -193,8 +192,8 @@ public void testChooseRandom() {
193192
}
194193
histogram.put(randomNode, histogram.get(randomNode) + 1);
195194
}
196-
assertEquals("Random is not selecting the nodes it should",
197-
2, histogram.size());
195+
assertEquals(2, histogram.size(),
196+
"Random is not selecting the nodes it should");
198197

199198
Node val = cluster.chooseRandom("/d1", "/d", Collections.emptyList());
200199
assertNotNull(val);
@@ -268,9 +267,10 @@ public void testWeights() {
268267
for (Pair<Integer, NodeElement> test: new Pair[]{Pair.of(0, node1),
269268
Pair.of(2, node2), Pair.of(4, node3)}) {
270269
int expect = test.getLeft();
271-
assertEquals(test.toString(), expect, cluster.getWeight(node1, test.getRight()));
272-
assertEquals(test.toString(), expect,
273-
cluster.getWeightUsingNetworkLocation(node1, test.getRight()));
270+
assertEquals(expect, cluster.getWeight(node1, test.getRight()),
271+
test.toString());
272+
assertEquals(expect, cluster.getWeightUsingNetworkLocation(node1, test.getRight()),
273+
test.toString());
274274
}
275275
// Reset so that we can have 2 levels
276276
cluster = NetworkTopology.getInstance(new Configuration());
@@ -281,9 +281,9 @@ public void testWeights() {
281281
for (Pair<Integer, NodeElement> test: new Pair[]{Pair.of(0, node5),
282282
Pair.of(2, node6), Pair.of(4, node7), Pair.of(6, node8)}) {
283283
int expect = test.getLeft();
284-
assertEquals(test.toString(), expect, cluster.getWeight(node5, test.getRight()));
285-
assertEquals(test.toString(), expect,
286-
cluster.getWeightUsingNetworkLocation(node5, test.getRight()));
284+
assertEquals(expect, cluster.getWeight(node5, test.getRight()), test.toString());
285+
assertEquals(expect, cluster.getWeightUsingNetworkLocation(node5, test.getRight()),
286+
test.toString());
287287
}
288288
}
289289
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNS.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@
2929

3030
import org.apache.hadoop.util.Time;
3131

32-
import org.assertj.core.api.Assertions;
33-
import org.junit.Assume;
34-
import org.junit.Test;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.Timeout;
3534
import org.slf4j.Logger;
3635
import org.slf4j.LoggerFactory;
3736

3837
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
39-
import static org.junit.Assert.*;
38+
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
import static org.junit.jupiter.api.Assertions.assertNotNull;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
42+
import static org.junit.jupiter.api.Assertions.fail;
43+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4044

4145
/**
4246
* Test host name and IP resolution and caching.
@@ -77,9 +81,8 @@ public void testGetLocalHostIsFast() throws Exception {
7781
assertEquals(hostname3, hostname2);
7882
assertEquals(hostname2, hostname1);
7983
long interval = t2 - t1;
80-
assertTrue(
81-
"Took too long to determine local host - caching is not working",
82-
interval < 20000);
84+
assertTrue(interval < 20000,
85+
"Took too long to determine local host - caching is not working");
8386
}
8487

8588
/**
@@ -103,7 +106,7 @@ private InetAddress getLocalIPAddr() throws UnknownHostException {
103106
@Test
104107
public void testNullInterface() throws Exception {
105108
String host = DNS.getDefaultHost(null); // should work.
106-
Assertions.assertThat(host).isEqualTo(DNS.getDefaultHost(DEFAULT));
109+
assertThat(host).isEqualTo(DNS.getDefaultHost(DEFAULT));
107110
try {
108111
String ip = DNS.getDefaultIP(null);
109112
fail("Expected a NullPointerException, got " + ip);
@@ -119,7 +122,7 @@ public void testNullInterface() throws Exception {
119122
@Test
120123
public void testNullDnsServer() throws Exception {
121124
String host = DNS.getDefaultHost(getLoopbackInterface(), null);
122-
Assertions.assertThat(host)
125+
assertThat(host)
123126
.isEqualTo(DNS.getDefaultHost(getLoopbackInterface()));
124127
}
125128

@@ -130,7 +133,7 @@ public void testNullDnsServer() throws Exception {
130133
@Test
131134
public void testDefaultDnsServer() throws Exception {
132135
String host = DNS.getDefaultHost(getLoopbackInterface(), DEFAULT);
133-
Assertions.assertThat(host)
136+
assertThat(host)
134137
.isEqualTo(DNS.getDefaultHost(getLoopbackInterface()));
135138
}
136139

@@ -154,7 +157,7 @@ public void testIPsOfUnknownInterface() throws Exception {
154157
@Test
155158
public void testGetIPWithDefault() throws Exception {
156159
String[] ips = DNS.getIPs(DEFAULT);
157-
assertEquals("Should only return 1 default IP", 1, ips.length);
160+
assertEquals(1, ips.length, "Should only return 1 default IP");
158161
assertEquals(getLocalIPAddr().getHostAddress(), ips[0].toString());
159162
String ip = DNS.getDefaultIP(DEFAULT);
160163
assertEquals(ip, ips[0].toString());
@@ -178,7 +181,7 @@ public void testRDNS() throws Exception {
178181
+ " Loopback=" + localhost.isLoopbackAddress()
179182
+ " Linklocal=" + localhost.isLinkLocalAddress());
180183
}
181-
Assume.assumeNoException(e);
184+
assumeTrue(false, e.getMessage());
182185
}
183186
}
184187

@@ -196,7 +199,8 @@ public void testRDNS() throws Exception {
196199
*
197200
* @throws Exception
198201
*/
199-
@Test (timeout=60000)
202+
@Test
203+
@Timeout(value = 60)
200204
public void testLookupWithHostsFallback() throws Exception {
201205
assumeNotWindows();
202206
final String oldHostname = DNS.getCachedHostname();
@@ -206,7 +210,7 @@ public void testLookupWithHostsFallback() throws Exception {
206210
getLoopbackInterface(), INVALID_DNS_SERVER, true);
207211

208212
// Expect to get back something other than the cached host name.
209-
Assertions.assertThat(hostname).isNotEqualTo(DUMMY_HOSTNAME);
213+
assertThat(hostname).isNotEqualTo(DUMMY_HOSTNAME);
210214
} finally {
211215
// Restore DNS#cachedHostname for subsequent tests.
212216
DNS.setCachedHostname(oldHostname);
@@ -219,7 +223,8 @@ public void testLookupWithHostsFallback() throws Exception {
219223
*
220224
* @throws Exception
221225
*/
222-
@Test(timeout=60000)
226+
@Test
227+
@Timeout(value = 60)
223228
public void testLookupWithoutHostsFallback() throws Exception {
224229
final String oldHostname = DNS.getCachedHostname();
225230
try {
@@ -229,7 +234,7 @@ public void testLookupWithoutHostsFallback() throws Exception {
229234

230235
// Expect to get back the cached host name since there was no hosts
231236
// file lookup.
232-
Assertions.assertThat(hostname).isEqualTo(DUMMY_HOSTNAME);
237+
assertThat(hostname).isEqualTo(DUMMY_HOSTNAME);
233238
} finally {
234239
// Restore DNS#cachedHostname for subsequent tests.
235240
DNS.setCachedHostname(oldHostname);
@@ -249,7 +254,7 @@ private String getLoopbackInterface() throws SocketException {
249254
@Test
250255
public void testLocalhostResolves() throws Exception {
251256
InetAddress localhost = InetAddress.getByName("localhost");
252-
assertNotNull("localhost is null", localhost);
257+
assertNotNull(localhost, "localhost is null");
253258
LOG.info("Localhost IPAddr is " + localhost.toString());
254259
}
255260
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNSDomainNameResolver.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
*/
1818
package org.apache.hadoop.net;
1919

20-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2121

2222
import java.net.InetAddress;
2323
import java.net.UnknownHostException;
2424
import java.util.Objects;
2525

26-
import static org.junit.Assert.assertEquals;
27-
import static org.junit.Assert.assertNotEquals;
28-
import static org.junit.Assume.assumeFalse;
29-
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
28+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
3029

3130
public class TestDNSDomainNameResolver {
3231

@@ -35,8 +34,8 @@ public class TestDNSDomainNameResolver {
3534
@Test
3635
public void testGetHostNameByIP() throws UnknownHostException {
3736
InetAddress localhost = InetAddress.getLocalHost();
38-
assumeFalse("IP lookup support required",
39-
Objects.equals(localhost.getCanonicalHostName(), localhost.getHostAddress()));
37+
assumeFalse(Objects.equals(localhost.getCanonicalHostName(), localhost.getHostAddress()),
38+
"IP lookup support required");
4039

4140
// Precondition: host name and canonical host name for unresolved returns an IP address.
4241
InetAddress unresolved = InetAddress.getByAddress(localhost.getHostAddress(),

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestMockDomainNameResolver.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
import org.apache.hadoop.conf.Configuration;
2121
import org.apache.hadoop.fs.CommonConfigurationKeys;
22-
import org.junit.Before;
23-
import org.junit.Test;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
2424

2525
import java.io.IOException;
2626
import java.net.InetAddress;
2727
import java.net.UnknownHostException;
2828

29-
import static org.junit.Assert.assertEquals;
30-
import static org.junit.Assert.assertThrows;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertThrows;
3131

3232
/**
3333
* This class mainly test the MockDomainNameResolver comes working as expected.
@@ -36,7 +36,7 @@ public class TestMockDomainNameResolver {
3636

3737
private Configuration conf;
3838

39-
@Before
39+
@BeforeEach
4040
public void setup() {
4141
conf = new Configuration();
4242
conf.set(CommonConfigurationKeys.HADOOP_DOMAINNAME_RESOLVER_IMPL,

0 commit comments

Comments
 (0)