Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestClusterTopology extends Assert {
public class TestClusterTopology extends Assertions {

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

assertEquals("4 nodes should be available", 4,
cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes));
assertEquals(4, cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes),
"4 nodes should be available");
NodeElement deadNode = getNewNode("node5", "/d1/r2");
excludedNodes.add(deadNode);
assertEquals("4 nodes should be available with extra excluded Node", 4,
cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes));
assertEquals(4, cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes),
"4 nodes should be available with extra excluded Node");
// add one existing node to exclude list
excludedNodes.add(node4);
assertEquals("excluded nodes with ROOT scope should be considered", 3,
cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes));
assertEquals("excluded nodes without ~ scope should be considered", 2,
cluster.countNumOfAvailableNodes("~" + deadNode.getNetworkLocation(),
excludedNodes));
assertEquals("excluded nodes with rack scope should be considered", 1,
cluster.countNumOfAvailableNodes(deadNode.getNetworkLocation(),
excludedNodes));
assertEquals(3, cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes),
"excluded nodes with ROOT scope should be considered");
assertEquals(2,
cluster.countNumOfAvailableNodes("~" + deadNode.getNetworkLocation(), excludedNodes),
"excluded nodes without ~ scope should be considered");
assertEquals(1, cluster.countNumOfAvailableNodes(deadNode.getNetworkLocation(),
excludedNodes), "excluded nodes with rack scope should be considered");
// adding the node in excluded scope to excluded list
excludedNodes.add(node2);
assertEquals("excluded nodes with ~ scope should be considered", 2,
cluster.countNumOfAvailableNodes("~" + deadNode.getNetworkLocation(),
excludedNodes));
assertEquals(2,
cluster.countNumOfAvailableNodes("~" + deadNode.getNetworkLocation(), excludedNodes),
"excluded nodes with ~ scope should be considered");
// getting count with non-exist scope.
assertEquals("No nodes should be considered for non-exist scope", 0,
cluster.countNumOfAvailableNodes("/non-exist", excludedNodes));
assertEquals(0, cluster.countNumOfAvailableNodes("/non-exist", excludedNodes),
"No nodes should be considered for non-exist scope");
// remove a node from the cluster
cluster.remove(node1);
assertEquals("1 node should be available", 1,
cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes));
assertEquals(1, cluster.countNumOfAvailableNodes(NodeBase.ROOT, excludedNodes),
"1 node should be available");
}

/**
Expand Down Expand Up @@ -160,7 +159,7 @@ public void testChooseRandom() {
}
histogram.put(randomNode, histogram.get(randomNode) + 1);
}
assertEquals("Random is not selecting all nodes", 4, histogram.size());
assertEquals(4, histogram.size(), "Random is not selecting all nodes");

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

// Check that they have the proper distribution
assertFalse("Random not choosing nodes with proper distribution",
chiSquareTestRejectedCounter==3);
assertFalse(chiSquareTestRejectedCounter == 3,
"Random not choosing nodes with proper distribution");

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

Node val = cluster.chooseRandom("/d1", "/d", Collections.emptyList());
assertNotNull(val);
Expand Down Expand Up @@ -268,9 +267,10 @@ public void testWeights() {
for (Pair<Integer, NodeElement> test: new Pair[]{Pair.of(0, node1),
Pair.of(2, node2), Pair.of(4, node3)}) {
int expect = test.getLeft();
assertEquals(test.toString(), expect, cluster.getWeight(node1, test.getRight()));
assertEquals(test.toString(), expect,
cluster.getWeightUsingNetworkLocation(node1, test.getRight()));
assertEquals(expect, cluster.getWeight(node1, test.getRight()),
test.toString());
assertEquals(expect, cluster.getWeightUsingNetworkLocation(node1, test.getRight()),
test.toString());
}
// Reset so that we can have 2 levels
cluster = NetworkTopology.getInstance(new Configuration());
Expand All @@ -281,9 +281,9 @@ public void testWeights() {
for (Pair<Integer, NodeElement> test: new Pair[]{Pair.of(0, node5),
Pair.of(2, node6), Pair.of(4, node7), Pair.of(6, node8)}) {
int expect = test.getLeft();
assertEquals(test.toString(), expect, cluster.getWeight(node5, test.getRight()));
assertEquals(test.toString(), expect,
cluster.getWeightUsingNetworkLocation(node5, test.getRight()));
assertEquals(expect, cluster.getWeight(node5, test.getRight()), test.toString());
assertEquals(expect, cluster.getWeightUsingNetworkLocation(node5, test.getRight()),
test.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@

import org.apache.hadoop.util.Time;

import org.assertj.core.api.Assertions;
import org.junit.Assume;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
* Test host name and IP resolution and caching.
Expand Down Expand Up @@ -77,9 +81,8 @@ public void testGetLocalHostIsFast() throws Exception {
assertEquals(hostname3, hostname2);
assertEquals(hostname2, hostname1);
long interval = t2 - t1;
assertTrue(
"Took too long to determine local host - caching is not working",
interval < 20000);
assertTrue(interval < 20000,
"Took too long to determine local host - caching is not working");
}

/**
Expand All @@ -103,7 +106,7 @@ private InetAddress getLocalIPAddr() throws UnknownHostException {
@Test
public void testNullInterface() throws Exception {
String host = DNS.getDefaultHost(null); // should work.
Assertions.assertThat(host).isEqualTo(DNS.getDefaultHost(DEFAULT));
assertThat(host).isEqualTo(DNS.getDefaultHost(DEFAULT));
try {
String ip = DNS.getDefaultIP(null);
fail("Expected a NullPointerException, got " + ip);
Expand All @@ -119,7 +122,7 @@ public void testNullInterface() throws Exception {
@Test
public void testNullDnsServer() throws Exception {
String host = DNS.getDefaultHost(getLoopbackInterface(), null);
Assertions.assertThat(host)
assertThat(host)
.isEqualTo(DNS.getDefaultHost(getLoopbackInterface()));
}

Expand All @@ -130,7 +133,7 @@ public void testNullDnsServer() throws Exception {
@Test
public void testDefaultDnsServer() throws Exception {
String host = DNS.getDefaultHost(getLoopbackInterface(), DEFAULT);
Assertions.assertThat(host)
assertThat(host)
.isEqualTo(DNS.getDefaultHost(getLoopbackInterface()));
}

Expand All @@ -154,7 +157,7 @@ public void testIPsOfUnknownInterface() throws Exception {
@Test
public void testGetIPWithDefault() throws Exception {
String[] ips = DNS.getIPs(DEFAULT);
assertEquals("Should only return 1 default IP", 1, ips.length);
assertEquals(1, ips.length, "Should only return 1 default IP");
assertEquals(getLocalIPAddr().getHostAddress(), ips[0].toString());
String ip = DNS.getDefaultIP(DEFAULT);
assertEquals(ip, ips[0].toString());
Expand All @@ -178,7 +181,7 @@ public void testRDNS() throws Exception {
+ " Loopback=" + localhost.isLoopbackAddress()
+ " Linklocal=" + localhost.isLinkLocalAddress());
}
Assume.assumeNoException(e);
assumeTrue(false, e.getMessage());
}
}

Expand All @@ -196,7 +199,8 @@ public void testRDNS() throws Exception {
*
* @throws Exception
*/
@Test (timeout=60000)
@Test
@Timeout(value = 60)
public void testLookupWithHostsFallback() throws Exception {
assumeNotWindows();
final String oldHostname = DNS.getCachedHostname();
Expand All @@ -206,7 +210,7 @@ public void testLookupWithHostsFallback() throws Exception {
getLoopbackInterface(), INVALID_DNS_SERVER, true);

// Expect to get back something other than the cached host name.
Assertions.assertThat(hostname).isNotEqualTo(DUMMY_HOSTNAME);
assertThat(hostname).isNotEqualTo(DUMMY_HOSTNAME);
} finally {
// Restore DNS#cachedHostname for subsequent tests.
DNS.setCachedHostname(oldHostname);
Expand All @@ -219,7 +223,8 @@ public void testLookupWithHostsFallback() throws Exception {
*
* @throws Exception
*/
@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testLookupWithoutHostsFallback() throws Exception {
final String oldHostname = DNS.getCachedHostname();
try {
Expand All @@ -229,7 +234,7 @@ public void testLookupWithoutHostsFallback() throws Exception {

// Expect to get back the cached host name since there was no hosts
// file lookup.
Assertions.assertThat(hostname).isEqualTo(DUMMY_HOSTNAME);
assertThat(hostname).isEqualTo(DUMMY_HOSTNAME);
} finally {
// Restore DNS#cachedHostname for subsequent tests.
DNS.setCachedHostname(oldHostname);
Expand All @@ -249,7 +254,7 @@ private String getLoopbackInterface() throws SocketException {
@Test
public void testLocalhostResolves() throws Exception {
InetAddress localhost = InetAddress.getByName("localhost");
assertNotNull("localhost is null", localhost);
assertNotNull(localhost, "localhost is null");
LOG.info("Localhost IPAddr is " + localhost.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
*/
package org.apache.hadoop.net;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assume.assumeFalse;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

public class TestDNSDomainNameResolver {

Expand All @@ -35,8 +34,8 @@ public class TestDNSDomainNameResolver {
@Test
public void testGetHostNameByIP() throws UnknownHostException {
InetAddress localhost = InetAddress.getLocalHost();
assumeFalse("IP lookup support required",
Objects.equals(localhost.getCanonicalHostName(), localhost.getHostAddress()));
assumeFalse(Objects.equals(localhost.getCanonicalHostName(), localhost.getHostAddress()),
"IP lookup support required");

// Precondition: host name and canonical host name for unresolved returns an IP address.
InetAddress unresolved = InetAddress.getByAddress(localhost.getHostAddress(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

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

private Configuration conf;

@Before
@BeforeEach
public void setup() {
conf = new Configuration();
conf.set(CommonConfigurationKeys.HADOOP_DOMAINNAME_RESOLVER_IMPL,
Expand Down
Loading