diff --git a/hadoop-common-project/hadoop-registry/pom.xml b/hadoop-common-project/hadoop-registry/pom.xml
index 8a6f47e07da15..591cb60a756f9 100644
--- a/hadoop-common-project/hadoop-registry/pom.xml
+++ b/hadoop-common-project/hadoop-registry/pom.xml
@@ -146,6 +146,32 @@
provided
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.junit.vintage
+ junit-vintage-engine
+ test
+
+
+ org.junit.platform
+ junit-platform-launcher
+ test
+
+
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/AbstractRegistryTest.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/AbstractRegistryTest.java
index 0d4a4678df3bd..28c7c9f23ab69 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/AbstractRegistryTest.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/AbstractRegistryTest.java
@@ -25,7 +25,7 @@
import org.apache.hadoop.registry.client.types.ServiceRecord;
import org.apache.hadoop.registry.server.services.RegistryAdminService;
-import org.junit.Before;
+import org.junit.jupiter.api.BeforeEach;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +39,7 @@ public class AbstractRegistryTest extends AbstractZKRegistryTest {
protected RegistryAdminService registry;
protected RegistryOperations operations;
- @Before
+ @BeforeEach
public void setupRegistry() throws IOException {
registry = new RegistryAdminService("yarnRegistry");
operations = registry;
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/AbstractZKRegistryTest.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/AbstractZKRegistryTest.java
index 3f87a395a4e60..e3362896b855e 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/AbstractZKRegistryTest.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/AbstractZKRegistryTest.java
@@ -26,18 +26,17 @@
import org.apache.hadoop.registry.server.services.AddingCompositeService;
import org.apache.hadoop.registry.server.services.MicroZookeeperService;
import org.apache.hadoop.registry.server.services.MicroZookeeperServiceKeys;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
+@Timeout(10)
public class AbstractZKRegistryTest extends RegistryTestHelper {
private static final Logger LOG =
LoggerFactory.getLogger(AbstractZKRegistryTest.class);
@@ -51,17 +50,11 @@ public class AbstractZKRegistryTest extends RegistryTestHelper {
servicesToTeardown.start();
}
- @Rule
- public final Timeout testTimeout = new Timeout(10000);
-
- @Rule
- public TestName methodName = new TestName();
-
protected static void addToTeardown(Service svc) {
servicesToTeardown.addService(svc);
}
- @AfterClass
+ @AfterAll
public static void teardownServices() throws IOException {
describe(LOG, "teardown of static services");
servicesToTeardown.close();
@@ -70,7 +63,7 @@ public static void teardownServices() throws IOException {
protected static MicroZookeeperService zookeeper;
- @BeforeClass
+ @BeforeAll
public static void createZKServer() throws Exception {
File zkDir = new File("target/zookeeper");
FileUtils.deleteDirectory(zkDir);
@@ -86,7 +79,7 @@ public static void createZKServer() throws Exception {
/**
* give our thread a name
*/
- @Before
+ @BeforeEach
public void nameThread() {
Thread.currentThread().setName("JUnit");
}
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/RegistryTestHelper.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/RegistryTestHelper.java
index a0f2ca11c0c58..c02aad68f0161 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/RegistryTestHelper.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/RegistryTestHelper.java
@@ -30,7 +30,7 @@
import org.apache.hadoop.registry.client.types.yarn.YarnRegistryAttributes;
import org.apache.hadoop.registry.secure.AbstractSecureRegistryTest;
import org.apache.zookeeper.common.PathUtils;
-import org.junit.Assert;
+import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,7 +52,7 @@
* The methods can be imported statically —or the class used as a base
* class for tests.
*/
-public class RegistryTestHelper extends Assert {
+public class RegistryTestHelper extends Assertions {
public static final String SC_HADOOP = "org-apache-hadoop";
public static final String USER = "devteam/";
public static final String NAME = "hdfs";
@@ -109,7 +109,7 @@ public static void assertNotEmpty(String check) {
*/
public static void logLoginDetails(String name,
LoginContext loginContext) {
- assertNotNull("Null login context", loginContext);
+ assertNotNull(loginContext, "Null login context");
Subject subject = loginContext.getSubject();
LOG.info("Logged in as {}:\n {}", name, subject);
}
@@ -135,7 +135,7 @@ public static void disableKerberosDebugging() {
* @param record instance to check
*/
public static void validateEntry(ServiceRecord record) {
- assertNotNull("null service record", record);
+ assertNotNull(record, "null service record");
List endpoints = record.external;
assertEquals(2, endpoints.size());
@@ -150,8 +150,8 @@ public static void validateEntry(ServiceRecord record) {
assertTrue(addr.contains(":8020"));
Endpoint nnipc = findEndpoint(record, NNIPC, false, 1,2);
- assertEquals("wrong protocol in " + nnipc, ProtocolTypes.PROTOCOL_THRIFT,
- nnipc.protocolType);
+ assertEquals(ProtocolTypes.PROTOCOL_THRIFT,
+ nnipc.protocolType, "wrong protocol in " + nnipc);
Endpoint ipc2 = findEndpoint(record, IPC2, false, 1,2);
assertNotNull(ipc2);
@@ -184,26 +184,25 @@ public static void assertMatches(Endpoint endpoint,
* @param resolved the one that resolved.
*/
public static void assertMatches(ServiceRecord source, ServiceRecord resolved) {
- assertNotNull("Null source record ", source);
- assertNotNull("Null resolved record ", resolved);
+ assertNotNull(source, "Null source record ");
+ assertNotNull(resolved, "Null resolved record ");
assertEquals(source.description, resolved.description);
Map srcAttrs = source.attributes();
Map resolvedAttrs = resolved.attributes();
String sourceAsString = source.toString();
String resolvedAsString = resolved.toString();
- assertEquals("Wrong count of attrs in \n" + sourceAsString
- + "\nfrom\n" + resolvedAsString,
- srcAttrs.size(),
- resolvedAttrs.size());
+ assertEquals(srcAttrs.size(),
+ resolvedAttrs.size(), "Wrong count of attrs in \n" + sourceAsString
+ + "\nfrom\n" + resolvedAsString);
for (Map.Entry entry : srcAttrs.entrySet()) {
String attr = entry.getKey();
- assertEquals("attribute "+ attr, entry.getValue(), resolved.get(attr));
+ assertEquals(entry.getValue(), resolved.get(attr), "attribute "+ attr);
}
- assertEquals("wrong external endpoint count",
- source.external.size(), resolved.external.size());
- assertEquals("wrong external endpoint count",
- source.internal.size(), resolved.internal.size());
+ assertEquals(source.external.size(), resolved.external.size(),
+ "wrong external endpoint count");
+ assertEquals(source.internal.size(), resolved.internal.size(),
+ "wrong external endpoint count");
}
/**
@@ -220,10 +219,10 @@ public static Endpoint findEndpoint(ServiceRecord record,
Endpoint epr = external ? record.getExternalEndpoint(api)
: record.getInternalEndpoint(api);
if (epr != null) {
- assertEquals("wrong # of addresses",
- addressElements, epr.addresses.size());
- assertEquals("wrong # of elements in an address tuple",
- addressTupleSize, epr.addresses.get(0).size());
+ assertEquals(addressElements, epr.addresses.size(),
+ "wrong # of addresses");
+ assertEquals(addressTupleSize, epr.addresses.get(0).size(),
+ "wrong # of elements in an address tuple");
return epr;
}
List endpoints = external ? record.external : record.internal;
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/cli/TestRegistryCli.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/cli/TestRegistryCli.java
index bd8a38dc64e1b..236891c6d93ed 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/cli/TestRegistryCli.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/cli/TestRegistryCli.java
@@ -22,9 +22,9 @@
import org.apache.hadoop.registry.AbstractRegistryTest;
import org.apache.hadoop.registry.operations.TestRegistryOperations;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,7 +38,7 @@ public class TestRegistryCli extends AbstractRegistryTest {
private PrintStream sysErr;
private RegistryCli cli;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
sysOutStream = new ByteArrayOutputStream();
sysOut = new PrintStream(sysOutStream);
@@ -48,7 +48,7 @@ public void setUp() throws Exception {
cli = new RegistryCli(operations, createRegistryConfiguration(), sysOut, sysErr);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
cli.close();
}
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestMarshalling.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestMarshalling.java
index f1814d30707c0..dde06b89a222c 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestMarshalling.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestMarshalling.java
@@ -23,29 +23,23 @@
import org.apache.hadoop.registry.client.exceptions.NoRecordException;
import org.apache.hadoop.registry.client.types.ServiceRecord;
import org.apache.hadoop.registry.client.types.yarn.PersistencePolicies;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestName;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test record marshalling
*/
+@Timeout(10)
public class TestMarshalling extends RegistryTestHelper {
private static final Logger
LOG = LoggerFactory.getLogger(TestMarshalling.class);
- @Rule
- public final Timeout testTimeout = new Timeout(10000);
- @Rule
- public TestName methodName = new TestName();
-
private static RegistryUtils.ServiceRecordMarshal marshal;
- @BeforeClass
+ @BeforeAll
public static void setupClass() {
marshal = new RegistryUtils.ServiceRecordMarshal();
}
@@ -65,53 +59,67 @@ public void testRoundTrip() throws Throwable {
}
- @Test(expected = NoRecordException.class)
+ @Test
public void testUnmarshallNoData() throws Throwable {
- marshal.fromBytes("src", new byte[]{});
+ assertThrows(NoRecordException.class, () -> {
+ marshal.fromBytes("src", new byte[]{});
+ });
}
- @Test(expected = NoRecordException.class)
+ @Test
public void testUnmarshallNotEnoughData() throws Throwable {
// this is nominally JSON -but without the service record header
- marshal.fromBytes("src", new byte[]{'{','}'}, ServiceRecord.RECORD_TYPE);
+ assertThrows(NoRecordException.class, () -> {
+ marshal.fromBytes("src", new byte[]{'{', '}'}, ServiceRecord.RECORD_TYPE);
+ });
}
- @Test(expected = InvalidRecordException.class)
+ @Test
public void testUnmarshallNoBody() throws Throwable {
- byte[] bytes = "this is not valid JSON at all and should fail".getBytes();
- marshal.fromBytes("src", bytes);
+ assertThrows(InvalidRecordException.class, () -> {
+ byte[] bytes = "this is not valid JSON at all and should fail".getBytes();
+ marshal.fromBytes("src", bytes);
+ });
}
- @Test(expected = InvalidRecordException.class)
+ @Test
public void testUnmarshallWrongType() throws Throwable {
- byte[] bytes = "{'type':''}".getBytes();
- ServiceRecord serviceRecord = marshal.fromBytes("marshalling", bytes);
- RegistryTypeUtils.validateServiceRecord("validating", serviceRecord);
+ assertThrows(InvalidRecordException.class, () -> {
+ byte[] bytes = "{'type':''}".getBytes();
+ ServiceRecord serviceRecord = marshal.fromBytes("marshalling", bytes);
+ RegistryTypeUtils.validateServiceRecord("validating", serviceRecord);
+ });
}
- @Test(expected = NoRecordException.class)
+ @Test
public void testUnmarshallWrongLongType() throws Throwable {
- ServiceRecord record = new ServiceRecord();
- record.type = "ThisRecordHasALongButNonMatchingType";
- byte[] bytes = marshal.toBytes(record);
- ServiceRecord serviceRecord = marshal.fromBytes("marshalling",
- bytes, ServiceRecord.RECORD_TYPE);
+ assertThrows(NoRecordException.class, () -> {
+ ServiceRecord record = new ServiceRecord();
+ record.type = "ThisRecordHasALongButNonMatchingType";
+ byte[] bytes = marshal.toBytes(record);
+ ServiceRecord serviceRecord = marshal.fromBytes("marshalling",
+ bytes, ServiceRecord.RECORD_TYPE);
+ });
}
- @Test(expected = NoRecordException.class)
+ @Test
public void testUnmarshallNoType() throws Throwable {
- ServiceRecord record = new ServiceRecord();
- record.type = "NoRecord";
- byte[] bytes = marshal.toBytes(record);
- ServiceRecord serviceRecord = marshal.fromBytes("marshalling",
- bytes, ServiceRecord.RECORD_TYPE);
+ assertThrows(NoRecordException.class, () -> {
+ ServiceRecord record = new ServiceRecord();
+ record.type = "NoRecord";
+ byte[] bytes = marshal.toBytes(record);
+ ServiceRecord serviceRecord = marshal.fromBytes("marshalling",
+ bytes, ServiceRecord.RECORD_TYPE);
+ });
}
- @Test(expected = InvalidRecordException.class)
+ @Test
public void testRecordValidationWrongType() throws Throwable {
- ServiceRecord record = new ServiceRecord();
- record.type = "NotAServiceRecordType";
- RegistryTypeUtils.validateServiceRecord("validating", record);
+ assertThrows(InvalidRecordException.class, () -> {
+ ServiceRecord record = new ServiceRecord();
+ record.type = "NotAServiceRecordType";
+ RegistryTypeUtils.validateServiceRecord("validating", record);
+ });
}
@Test
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestRegistryOperationUtils.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestRegistryOperationUtils.java
index b07d2ced64f89..5088ea0f3ce29 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestRegistryOperationUtils.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestRegistryOperationUtils.java
@@ -19,19 +19,18 @@
package org.apache.hadoop.registry.client.binding;
import org.apache.hadoop.security.UserGroupInformation;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
/**
* Tests for the {@link RegistryUtils} class
*/
-public class TestRegistryOperationUtils extends Assert {
+public class TestRegistryOperationUtils extends Assertions {
@Test
public void testUsernameExtractionEnvVarOverrride() throws Throwable {
String whoami = RegistryUtils.getCurrentUsernameUnencoded("drwho");
assertEquals("drwho", whoami);
-
}
@Test
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestRegistryPathUtils.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestRegistryPathUtils.java
index 4346c9a7874a8..b1d781d815b7d 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestRegistryPathUtils.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/binding/TestRegistryPathUtils.java
@@ -24,10 +24,10 @@
import org.apache.hadoop.fs.PathNotFoundException;
import org.apache.hadoop.registry.client.exceptions.InvalidPathnameException;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
-public class TestRegistryPathUtils extends Assert {
+public class TestRegistryPathUtils extends Assertions {
public static final String EURO = "\u20AC";
@@ -59,7 +59,7 @@ public void testFormatCyrillicSpaced() throws Throwable {
protected void assertConverted(String expected, String in) {
String out = RegistryPathUtils.encodeForRegistry(in);
- assertEquals("Conversion of " + in, expected, out);
+ assertEquals(expected, out, "Conversion of " + in);
}
@Test
@@ -103,8 +103,8 @@ public void testComplexPaths() throws Throwable {
private static void assertCreatedPathEquals(String expected, String base,
String path) throws IOException {
String fullPath = createFullPath(base, path);
- assertEquals("\"" + base + "\" + \"" + path + "\" =\"" + fullPath + "\"",
- expected, fullPath);
+ assertEquals(expected, fullPath,
+ "\"" + base + "\" + \"" + path + "\" =\"" + fullPath + "\"");
}
@Test
@@ -146,9 +146,11 @@ public void testLastPathEntry() throws Throwable {
assertEquals("c",lastPathEntry("/a/b/c/"));
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testParentOfRoot() throws Throwable {
- parentOf("/");
+ assertThrows(PathNotFoundException.class, () -> {
+ parentOf("/");
+ });
}
@Test
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestCuratorService.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestCuratorService.java
index 3c8b1d12bf46c..7131065571158 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestCuratorService.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestCuratorService.java
@@ -29,9 +29,9 @@
import org.apache.hadoop.registry.client.impl.zk.RegistrySecurity;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.data.ACL;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,12 +51,12 @@ public class TestCuratorService extends AbstractZKRegistryTest {
public static final String MISSING = "/missing";
private List rootACL;
- @Before
+ @BeforeEach
public void startCurator() throws IOException {
createCuratorService();
}
- @After
+ @AfterEach
public void stopCurator() {
ServiceOperations.stop(curatorService);
}
@@ -77,9 +77,11 @@ public void testLs() throws Throwable {
curatorService.zkList("/");
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testLsNotFound() throws Throwable {
- List ls = curatorService.zkList(MISSING);
+ assertThrows(PathNotFoundException.class, () -> {
+ List ls = curatorService.zkList(MISSING);
+ });
}
@Test
@@ -97,9 +99,11 @@ public void testVerifyExists() throws Throwable {
pathMustExist("/");
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testVerifyExistsMissing() throws Throwable {
- pathMustExist("/file-not-found");
+ assertThrows(PathNotFoundException.class, () -> {
+ pathMustExist("/file-not-found");
+ });
}
@Test
@@ -119,9 +123,11 @@ public void pathMustExist(String path) throws IOException {
curatorService.zkPathMustExist(path);
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testMkdirChild() throws Throwable {
- mkPath("/testMkdirChild/child", CreateMode.PERSISTENT);
+ assertThrows(PathNotFoundException.class, () -> {
+ mkPath("/testMkdirChild/child", CreateMode.PERSISTENT);
+ });
}
@Test
@@ -209,9 +215,11 @@ public void testCreateUpdate() throws Throwable {
curatorService.zkUpdate("/testcreateupdate", buffer);
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testUpdateMissing() throws Throwable {
- curatorService.zkUpdate("/testupdatemissing", getTestBuffer());
+ assertThrows(PathNotFoundException.class, () -> {
+ curatorService.zkUpdate("/testupdatemissing", getTestBuffer());
+ });
}
@Test
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestFSRegistryOperationsService.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestFSRegistryOperationsService.java
index dffa4a7af193b..b9a07d48bbf12 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestFSRegistryOperationsService.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestFSRegistryOperationsService.java
@@ -18,7 +18,11 @@
package org.apache.hadoop.registry.client.impl;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+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 java.io.IOException;
import java.util.List;
@@ -32,10 +36,10 @@
import org.apache.hadoop.registry.client.exceptions.InvalidPathnameException;
import org.apache.hadoop.registry.client.types.ServiceRecord;
import org.apache.hadoop.registry.client.types.yarn.YarnRegistryAttributes;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* FSRegistryOperationsService test, using the local filesystem.
@@ -45,20 +49,20 @@ public class TestFSRegistryOperationsService {
new FSRegistryOperationsService();
private static FileSystem fs;
- @BeforeClass
+ @BeforeAll
public static void initRegistry() throws IOException {
- Assert.assertNotNull(registry);
+ assertNotNull(registry);
registry.init(new Configuration());
fs = registry.getFs();
fs.delete(new Path("test"), true);
}
- @Before
+ @BeforeEach
public void createTestDir() throws IOException {
fs.mkdirs(new Path("test"));
}
- @After
+ @AfterEach
public void cleanTestDir() throws IOException {
fs.delete(new Path("test"), true);
}
@@ -69,17 +73,17 @@ public void testMkNodeNonRecursive()
boolean result = false;
System.out.println("Make node with parent already made, nonrecursive");
result = registry.mknode("test/registryTestNode", false);
- Assert.assertTrue(result);
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode")));
+ assertTrue(result);
+ assertTrue(fs.exists(new Path("test/registryTestNode")));
// Expected to fail
try {
System.out.println("Try to make node with no parent, nonrecursive");
registry.mknode("test/parent/registryTestNode", false);
- Assert.fail("Should not have created node");
+ fail("Should not have created node");
} catch (IOException e) {
}
- Assert.assertFalse(fs.exists(new Path("test/parent/registryTestNode")));
+ assertFalse(fs.exists(new Path("test/parent/registryTestNode")));
}
@Test
@@ -87,14 +91,14 @@ public void testMkNodeRecursive() throws IOException {
boolean result = false;
System.out.println("Make node with parent already made, recursive");
result = registry.mknode("test/registryTestNode", true);
- Assert.assertTrue(result);
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode")));
+ assertTrue(result);
+ assertTrue(fs.exists(new Path("test/registryTestNode")));
result = false;
System.out.println("Try to make node with no parent, recursive");
result = registry.mknode("test/parent/registryTestNode", true);
- Assert.assertTrue(result);
- Assert.assertTrue(fs.exists(new Path("test/parent/registryTestNode")));
+ assertTrue(result);
+ assertTrue(fs.exists(new Path("test/parent/registryTestNode")));
}
@@ -105,8 +109,8 @@ public void testMkNodeAlreadyExists() throws IOException {
System.out.println(
"Try to mknode existing path -- should be noop and return false");
- Assert.assertFalse(registry.mknode("test/registryTestNode", true));
- Assert.assertFalse(registry.mknode("test/registryTestNode", false));
+ assertFalse(registry.mknode("test/registryTestNode", true));
+ assertFalse(registry.mknode("test/registryTestNode", false));
}
@Test
@@ -118,12 +122,12 @@ public void testBindParentPath() throws InvalidPathnameException,
fs.mkdirs(new Path("test/parent1/registryTestNode"));
registry.bind("test/parent1/registryTestNode", record, 1);
- Assert.assertTrue(
+ assertTrue(
fs.exists(new Path("test/parent1/registryTestNode/_record")));
// Test without pre-creating path
registry.bind("test/parent2/registryTestNode", record, 1);
- Assert.assertTrue(fs.exists(new Path("test/parent2/registryTestNode")));
+ assertTrue(fs.exists(new Path("test/parent2/registryTestNode")));
}
@@ -134,43 +138,43 @@ public void testBindAlreadyExists() throws IOException {
System.out.println("Bind record1");
registry.bind("test/registryTestNode", record1, 1);
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/_record")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/_record")));
System.out.println("Bind record2, overwrite = 1");
registry.bind("test/registryTestNode", record2, 1);
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/_record")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/_record")));
// The record should have been overwritten
ServiceRecord readRecord = registry.resolve("test/registryTestNode");
- Assert.assertTrue(readRecord.equals(record2));
+ assertTrue(readRecord.equals(record2));
System.out.println("Bind record3, overwrite = 0");
try {
registry.bind("test/registryTestNode", record1, 0);
- Assert.fail("Should not overwrite record");
+ fail("Should not overwrite record");
} catch (IOException e) {
}
// The record should not be overwritten
readRecord = registry.resolve("test/registryTestNode");
- Assert.assertTrue(readRecord.equals(record2));
+ assertTrue(readRecord.equals(record2));
}
@Test
public void testResolve() throws IOException {
ServiceRecord record = createRecord("0");
registry.bind("test/registryTestNode", record, 1);
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/_record")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/_record")));
System.out.println("Read record that exists");
ServiceRecord readRecord = registry.resolve("test/registryTestNode");
- Assert.assertNotNull(readRecord);
- Assert.assertTrue(record.equals(readRecord));
+ assertNotNull(readRecord);
+ assertTrue(record.equals(readRecord));
System.out.println("Try to read record that does not exist");
try {
readRecord = registry.resolve("test/nonExistentNode");
- Assert.fail("Should throw an error, record does not exist");
+ fail("Should throw an error, record does not exist");
} catch (IOException e) {
}
}
@@ -182,11 +186,11 @@ public void testExists() throws IOException {
System.out.println("Check for existing node");
boolean exists = registry.exists("test/registryTestNode");
- Assert.assertTrue(exists);
+ assertTrue(exists);
System.out.println("Check for non-existing node");
exists = registry.exists("test/nonExistentNode");
- Assert.assertFalse(exists);
+ assertFalse(exists);
}
@Test
@@ -198,24 +202,24 @@ public void testDeleteDirsOnly() throws IOException {
try {
registry.delete("test/registryTestNode", false);
- Assert.fail("Deleted dir wich children, nonrecursive flag set");
+ fail("Deleted dir wich children, nonrecursive flag set");
} catch (IOException e) {
}
// Make sure nothing was deleted
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode")));
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/child1")));
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/child2")));
+ assertTrue(fs.exists(new Path("test/registryTestNode")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/child1")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/child2")));
System.out.println("Delete leaf path 'test/registryTestNode/child2'");
registry.delete("test/registryTestNode/child2", false);
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode")));
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/child1")));
- Assert.assertFalse(fs.exists(new Path("test/registryTestNode/child2")));
+ assertTrue(fs.exists(new Path("test/registryTestNode")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/child1")));
+ assertFalse(fs.exists(new Path("test/registryTestNode/child2")));
System.out
.println("Recursively delete non-leaf path 'test/registryTestNode'");
registry.delete("test/registryTestNode", true);
- Assert.assertFalse(fs.exists(new Path("test/registryTestNode")));
+ assertFalse(fs.exists(new Path("test/registryTestNode")));
}
@Test
@@ -233,27 +237,27 @@ public void testDeleteWithRecords() throws IOException {
System.out.println("Delete dir with child nodes and record file");
try {
registry.delete("test/registryTestNode", false);
- Assert.fail("Nonrecursive delete of non-empty dir");
+ fail("Nonrecursive delete of non-empty dir");
} catch (PathIsNotEmptyDirectoryException e) {
}
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/_record")));
- Assert.assertTrue(
+ assertTrue(fs.exists(new Path("test/registryTestNode/_record")));
+ assertTrue(
fs.exists(new Path("test/registryTestNode/child1/_record")));
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/child2")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/child2")));
System.out.println("Delete dir with record file and no child dirs");
registry.delete("test/registryTestNode/child1", false);
- Assert.assertFalse(fs.exists(new Path("test/registryTestNode/child1")));
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/child2")));
+ assertFalse(fs.exists(new Path("test/registryTestNode/child1")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/child2")));
System.out.println("Delete dir with child dir and no record file");
try {
registry.delete("test/registryTestNode", false);
- Assert.fail("Nonrecursive delete of non-empty dir");
+ fail("Nonrecursive delete of non-empty dir");
} catch (PathIsNotEmptyDirectoryException e) {
}
- Assert.assertTrue(fs.exists(new Path("test/registryTestNode/child2")));
+ assertTrue(fs.exists(new Path("test/registryTestNode/child2")));
}
@Test
@@ -271,20 +275,20 @@ public void testList() throws IOException {
List ls = null;
ls = registry.list("test/registryTestNode");
- Assert.assertNotNull(ls);
- Assert.assertEquals(2, ls.size());
+ assertNotNull(ls);
+ assertEquals(2, ls.size());
System.out.println(ls);
- Assert.assertTrue(ls.contains("child1"));
- Assert.assertTrue(ls.contains("child2"));
+ assertTrue(ls.contains("child1"));
+ assertTrue(ls.contains("child2"));
ls = null;
ls = registry.list("test/registryTestNode/child1");
- Assert.assertNotNull(ls);
- Assert.assertTrue(ls.isEmpty());
+ assertNotNull(ls);
+ assertTrue(ls.isEmpty());
ls = null;
ls = registry.list("test/registryTestNode/child2");
- Assert.assertNotNull(ls);
- Assert.assertTrue(ls.isEmpty());
+ assertNotNull(ls);
+ assertTrue(ls.isEmpty());
}
private ServiceRecord createRecord(String id) {
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestMicroZookeeperService.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestMicroZookeeperService.java
index 7cf39cd6f1c46..2bf408c390814 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestMicroZookeeperService.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/client/impl/TestMicroZookeeperService.java
@@ -22,28 +22,22 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.registry.conf.RegistryConfiguration;
import org.apache.hadoop.registry.server.services.MicroZookeeperService;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestName;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import java.io.IOException;
/**
* Simple tests to look at the micro ZK service itself
*/
-public class TestMicroZookeeperService extends Assert {
+@Timeout(10)
+public class TestMicroZookeeperService extends Assertions {
private MicroZookeeperService zookeeper;
- @Rule
- public final Timeout testTimeout = new Timeout(10000);
- @Rule
- public TestName methodName = new TestName();
-
- @After
+ @AfterEach
public void destroyZKServer() throws IOException {
ServiceOperations.stop(zookeeper);
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/integration/TestYarnPolicySelector.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/integration/TestYarnPolicySelector.java
index 441b3d7e72545..bea8921275a5b 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/integration/TestYarnPolicySelector.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/integration/TestYarnPolicySelector.java
@@ -24,7 +24,7 @@
import org.apache.hadoop.registry.client.types.ServiceRecord;
import org.apache.hadoop.registry.server.integration.SelectByYarnPersistence;
import org.apache.hadoop.registry.server.services.RegistryAdminService;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestYarnPolicySelector extends RegistryTestHelper {
@@ -37,7 +37,7 @@ public class TestYarnPolicySelector extends RegistryTestHelper {
public void assertSelected(boolean outcome,
RegistryAdminService.NodeSelector selector) {
boolean select = selector.shouldSelect("/", status, record);
- assertEquals(selector.toString(), outcome, select);
+ assertEquals(outcome, select, selector.toString());
}
@Test
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/operations/TestRegistryOperations.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/operations/TestRegistryOperations.java
index 853d7f179095f..a47fd32a623aa 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/operations/TestRegistryOperations.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/operations/TestRegistryOperations.java
@@ -31,7 +31,7 @@
import org.apache.hadoop.registry.client.types.RegistryPathStatus;
import org.apache.hadoop.registry.client.types.ServiceRecord;
import org.apache.hadoop.registry.client.types.yarn.YarnRegistryAttributes;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -108,19 +108,25 @@ public void testDeleteNonEmpty() throws Throwable {
operations.delete(PARENT_PATH, true);
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testStatEmptyPath() throws Throwable {
- operations.stat(ENTRY_PATH);
+ assertThrows(PathNotFoundException.class, () -> {
+ operations.stat(ENTRY_PATH);
+ });
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testLsEmptyPath() throws Throwable {
- operations.list(PARENT_PATH);
+ assertThrows(PathNotFoundException.class, () -> {
+ operations.list(PARENT_PATH);
+ });
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testResolveEmptyPath() throws Throwable {
- operations.resolve(ENTRY_PATH);
+ assertThrows(PathNotFoundException.class, () -> {
+ operations.resolve(ENTRY_PATH);
+ });
}
@Test
@@ -171,12 +177,14 @@ public void testPutMinimalRecord() throws Throwable {
}
- @Test(expected = PathNotFoundException.class)
+ @Test
public void testPutNoParent2() throws Throwable {
- ServiceRecord record = new ServiceRecord();
- record.set(YarnRegistryAttributes.YARN_ID, "testPutNoParent");
- String path = "/path/without/parent";
- operations.bind(path, record, 0);
+ assertThrows(PathNotFoundException.class, () -> {
+ ServiceRecord record = new ServiceRecord();
+ record.set(YarnRegistryAttributes.YARN_ID, "testPutNoParent");
+ String path = "/path/without/parent";
+ operations.bind(path, record, 0);
+ });
}
@Test
@@ -281,7 +289,7 @@ public void testListListFully() throws Throwable {
// listings now
List list = operations.list(path);
- assertEquals("Wrong no. of children", 2, list.size());
+ assertEquals(2, list.size(), "Wrong no. of children");
// there's no order here, so create one
Map names = new HashMap();
String entries = "";
@@ -289,14 +297,14 @@ public void testListListFully() throws Throwable {
names.put(child, child);
entries += child + " ";
}
- assertTrue("No 'r1' in " + entries,
- names.containsKey("r1"));
- assertTrue("No 'r2' in " + entries,
- names.containsKey("r2"));
+ assertTrue(
+ names.containsKey("r1"), "No 'r1' in " + entries);
+ assertTrue(
+ names.containsKey("r2"), "No 'r2' in " + entries);
Map stats =
RegistryUtils.statChildren(operations, path);
- assertEquals("Wrong no. of children", 2, stats.size());
+ assertEquals(2, stats.size(), "Wrong no. of children");
assertEquals(r1stat, stats.get("r1"));
assertEquals(r2stat, stats.get("r2"));
}
@@ -322,7 +330,7 @@ public void testComplexUsernames() throws Throwable {
RegistryUtils.homePathForUser("hbase/localhost@HADOOP.APACHE.ORG"),
true);
home = RegistryUtils.homePathForUser("ADMINISTRATOR/127.0.0.1");
- assertTrue("No 'administrator' in " + home, home.contains("administrator"));
+ assertTrue(home.contains("administrator"), "No 'administrator' in " + home);
operations.mknode(
home,
true);
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/AbstractSecureRegistryTest.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/AbstractSecureRegistryTest.java
index a510f84bd9458..e3da44777c204 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/AbstractSecureRegistryTest.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/AbstractSecureRegistryTest.java
@@ -31,14 +31,14 @@
import org.apache.hadoop.registry.server.services.AddingCompositeService;
import org.apache.hadoop.registry.server.services.MicroZookeeperService;
import org.apache.hadoop.registry.server.services.MicroZookeeperServiceKeys;
+import org.apache.hadoop.test.TestName;
import org.apache.hadoop.util.Shell;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,6 +59,7 @@
* Add kerberos tests. This is based on the (JUnit3) KerberosSecurityTestcase
* and its test case, TestMiniKdc
*/
+@Timeout(900)
public class AbstractSecureRegistryTest extends RegistryTestHelper {
public static final String REALM = "EXAMPLE.COM";
public static final String ZOOKEEPER = "zookeeper";
@@ -67,7 +68,7 @@ public class AbstractSecureRegistryTest extends RegistryTestHelper {
public static final String ZOOKEEPER_REALM = "zookeeper@" + REALM;
public static final String ZOOKEEPER_CLIENT_CONTEXT = ZOOKEEPER;
public static final String ZOOKEEPER_SERVER_CONTEXT = "ZOOKEEPER_SERVER";
- ;
+
public static final String ZOOKEEPER_LOCALHOST_REALM =
ZOOKEEPER_LOCALHOST + "@" + REALM;
public static final String ALICE = "alice";
@@ -113,11 +114,8 @@ public class AbstractSecureRegistryTest extends RegistryTestHelper {
protected static Properties kdcConf;
protected static RegistrySecurity registrySecurity;
- @Rule
- public final Timeout testTimeout = new Timeout(900000);
-
- @Rule
- public TestName methodName = new TestName();
+ @RegisterExtension
+ private TestName methodName = new TestName();
protected MicroZookeeperService secureZK;
protected static File jaasFile;
private LoginContext zookeeperLogin;
@@ -127,7 +125,7 @@ public class AbstractSecureRegistryTest extends RegistryTestHelper {
* All class initialization for this test class
* @throws Exception
*/
- @BeforeClass
+ @BeforeAll
public static void beforeSecureRegistryTestClass() throws Exception {
registrySecurity = new RegistrySecurity("registrySecurity");
registrySecurity.init(CONF);
@@ -137,7 +135,7 @@ public static void beforeSecureRegistryTestClass() throws Exception {
initHadoopSecurity();
}
- @AfterClass
+ @AfterAll
public static void afterSecureRegistryTestClass() throws
Exception {
describe(LOG, "teardown of class");
@@ -148,7 +146,7 @@ public static void afterSecureRegistryTestClass() throws
/**
* give our thread a name
*/
- @Before
+ @BeforeEach
public void nameThread() {
Thread.currentThread().setName("JUnit");
}
@@ -158,12 +156,12 @@ public void nameThread() {
* not being picked up. This method addresses that by setting them
* before every test case
*/
- @Before
+ @BeforeEach
public void beforeSecureRegistryTest() {
}
- @After
+ @AfterEach
public void afterSecureRegistryTest() throws IOException {
describe(LOG, "teardown of instance");
teardown.close();
@@ -303,7 +301,7 @@ public static File createKeytab(String principal,
String filename) throws Exception {
assertNotEmpty("empty principal", principal);
assertNotEmpty("empty host", filename);
- assertNotNull("Null KDC", kdc);
+ assertNotNull(kdc, "Null KDC");
File keytab = new File(kdcWorkDir, filename);
kdc.createPrincipal(keytab,
principal,
@@ -357,7 +355,7 @@ protected LoginContext login(String principal,
* @throws Exception on any failure
*/
protected synchronized void startSecureZK() throws Exception {
- assertNull("Zookeeper is already running", secureZK);
+ assertNull(secureZK, "Zookeeper is already running");
zookeeperLogin = login(zkServerPrincipal,
ZOOKEEPER_SERVER_CONTEXT,
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestRegistrySecurityHelper.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestRegistrySecurityHelper.java
index 8d0dc6a015c1e..e41390b59cfd9 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestRegistrySecurityHelper.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestRegistrySecurityHelper.java
@@ -24,9 +24,9 @@
import org.apache.hadoop.registry.client.impl.zk.RegistrySecurity;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.data.ACL;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,7 +38,7 @@
/**
* Test for registry security operations
*/
-public class TestRegistrySecurityHelper extends Assert {
+public class TestRegistrySecurityHelper extends Assertions {
private static final Logger LOG =
LoggerFactory.getLogger(TestRegistrySecurityHelper.class);
@@ -55,7 +55,7 @@ public class TestRegistrySecurityHelper extends Assert {
public static final String REALM_EXAMPLE_COM = "example.com";
private static RegistrySecurity registrySecurity;
- @BeforeClass
+ @BeforeAll
public static void setupTestRegistrySecurityHelper() throws IOException {
Configuration conf = new Configuration();
conf.setBoolean(KEY_REGISTRY_SECURE, true);
@@ -129,15 +129,16 @@ public void testACLSplitNullRealm() throws Throwable {
assertEquals(SASL_MAPRED_SHORT, pairs.get(1));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testBuildAclsNullRealm() throws Throwable {
- registrySecurity.buildACLs(
- SASL_YARN_SHORT +
- ", " +
- SASL_MAPRED_SHORT,
- "", ZooDefs.Perms.ALL);
- fail("");
-
+ assertThrows(IllegalArgumentException.class, () -> {
+ registrySecurity.buildACLs(
+ SASL_YARN_SHORT +
+ ", " +
+ SASL_MAPRED_SHORT,
+ "", ZooDefs.Perms.ALL);
+ fail("");
+ });
}
@Test
@@ -201,9 +202,8 @@ public void testSecurityImpliesKerberos() throws Throwable {
try {
security.init(conf);
} catch (Exception e) {
- assertTrue(
- "did not find "+ RegistrySecurity.E_NO_KERBEROS + " in " + e,
- e.toString().contains(RegistrySecurity.E_NO_KERBEROS));
+ assertTrue(e.toString().contains(RegistrySecurity.E_NO_KERBEROS),
+ "did not find "+ RegistrySecurity.E_NO_KERBEROS + " in " + e);
}
}
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureLogins.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureLogins.java
index 52d677e00a56c..cf77a24fa3701 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureLogins.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureLogins.java
@@ -49,7 +49,7 @@
import static org.apache.hadoop.security.authentication.util.KerberosName.MECHANISM_MIT;
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,7 +69,7 @@ public void testHasRealm() throws Throwable {
@Test
public void testJaasFileSetup() throws Throwable {
// the JVM has seemed inconsistent on setting up here
- assertNotNull("jaasFile", jaasFile);
+ assertNotNull(jaasFile, "jaasFile");
String confFilename = System.getProperty(Environment.JAAS_CONF_KEY);
assertEquals(jaasFile.getAbsolutePath(), confFilename);
}
@@ -77,7 +77,7 @@ public void testJaasFileSetup() throws Throwable {
@Test
public void testJaasFileBinding() throws Throwable {
// the JVM has seemed inconsistent on setting up here
- assertNotNull("jaasFile", jaasFile);
+ assertNotNull(jaasFile, "jaasFile");
RegistrySecurity.bindJVMtoJAASFile(jaasFile);
String confFilename = System.getProperty(Environment.JAAS_CONF_KEY);
assertEquals(jaasFile.getAbsolutePath(), confFilename);
@@ -92,7 +92,7 @@ public void testClientLogin() throws Throwable {
try {
logLoginDetails(ALICE_LOCALHOST, client);
String confFilename = System.getProperty(Environment.JAAS_CONF_KEY);
- assertNotNull("Unset: "+ Environment.JAAS_CONF_KEY, confFilename);
+ assertNotNull(confFilename, "Unset: "+ Environment.JAAS_CONF_KEY);
String config = FileUtils.readFileToString(new File(confFilename), StandardCharsets.UTF_8);
LOG.info("{}=\n{}", confFilename, config);
RegistrySecurity.setZKSaslClientProperties(ALICE, ALICE_CLIENT_CONTEXT);
@@ -175,10 +175,10 @@ public void testKerberosAuth() throws Throwable {
new HashMap(), options);
Method methodLogin = kerb5LoginObject.getClass().getMethod("login");
boolean loginOk = (Boolean) methodLogin.invoke(kerb5LoginObject);
- assertTrue("Failed to login", loginOk);
+ assertTrue(loginOk, "Failed to login");
Method methodCommit = kerb5LoginObject.getClass().getMethod("commit");
boolean commitOk = (Boolean) methodCommit.invoke(kerb5LoginObject);
- assertTrue("Failed to Commit", commitOk);
+ assertTrue(commitOk, "Failed to Commit");
}
@Test
@@ -191,8 +191,8 @@ public void testDefaultRealmValid() throws Throwable {
@Test
public void testKerberosRulesValid() throws Throwable {
- assertTrue("!KerberosName.hasRulesBeenSet()",
- KerberosName.hasRulesBeenSet());
+ assertTrue(KerberosName.hasRulesBeenSet(),
+ "!KerberosName.hasRulesBeenSet()");
String rules = KerberosName.getRules();
assertEquals(kerberosRule, rules);
LOG.info(rules);
@@ -218,10 +218,9 @@ public void testUGILogin() throws Throwable {
RegistrySecurity.UgiInfo ugiInfo =
new RegistrySecurity.UgiInfo(ugi);
LOG.info("logged in as: {}", ugiInfo);
- assertTrue("security is not enabled: " + ugiInfo,
- UserGroupInformation.isSecurityEnabled());
- assertTrue("login is keytab based: " + ugiInfo,
- ugi.isFromKeytab());
+ assertTrue(UserGroupInformation.isSecurityEnabled(),
+ "security is not enabled: " + ugiInfo);
+ assertTrue(ugi.isFromKeytab(), "login is keytab based: " + ugiInfo);
// now we are here, build a SASL ACL
ACL acl = ugi.doAs(new PrivilegedExceptionAction() {
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java
index 27d32ea9d2672..cb28b9ee09284 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/secure/TestSecureRegistry.java
@@ -24,9 +24,9 @@
import org.apache.hadoop.registry.client.impl.zk.CuratorService;
import org.apache.hadoop.registry.client.impl.zk.RegistrySecurity;
import org.apache.zookeeper.CreateMode;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,12 +43,12 @@ public class TestSecureRegistry extends AbstractSecureRegistryTest {
private static final Logger LOG =
LoggerFactory.getLogger(TestSecureRegistry.class);
- @Before
+ @BeforeEach
public void beforeTestSecureZKService() throws Throwable {
enableKerberosDebugging();
}
- @After
+ @AfterEach
public void afterTestSecureZKService() throws Throwable {
disableKerberosDebugging();
RegistrySecurity.clearZKSaslClientProperties();
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java
index 386cb3a196cad..17e9e7b96fcb7 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestRegistryDNS.java
@@ -21,10 +21,11 @@
import org.apache.hadoop.registry.client.api.RegistryConstants;
import org.apache.hadoop.registry.client.binding.RegistryUtils;
import org.apache.hadoop.registry.client.types.ServiceRecord;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import org.xbill.DNS.AAAARecord;
import org.xbill.DNS.ARecord;
import org.xbill.DNS.CNAMERecord;
@@ -61,7 +62,7 @@
/**
*
*/
-public class TestRegistryDNS extends Assert {
+public class TestRegistryDNS extends Assertions {
private RegistryDNS registryDNS;
private RegistryUtils.ServiceRecordMarshal marshal;
@@ -159,7 +160,7 @@ public class TestRegistryDNS extends Assert {
+ " \"yarn:component\" : \"httpd\""
+ "}\n";
- @Before
+ @BeforeEach
public void initialize() throws Exception {
setRegistryDNS(new RegistryDNS("TestRegistry"));
Configuration conf = createConfiguration();
@@ -182,7 +183,7 @@ protected boolean isSecure() {
return false;
}
- @After
+ @AfterEach
public void closeRegistry() throws Exception {
getRegistryDNS().stopExecutor();
}
@@ -196,36 +197,33 @@ public void testAppRegistration() throws Exception {
// start assessing whether correct records are available
List recs = assertDNSQuery("test1.root.dev.test.");
- assertEquals("wrong result", "192.168.1.5",
- ((ARecord) recs.get(0)).getAddress().getHostAddress());
+ assertEquals("192.168.1.5",
+ ((ARecord) recs.get(0)).getAddress().getHostAddress(), "wrong result");
recs = assertDNSQuery("management-api.test1.root.dev.test.", 2);
- assertEquals("wrong target name", "test1.root.dev.test.",
- ((CNAMERecord) recs.get(0)).getTarget().toString());
- assertTrue("not an ARecord",
- recs.get(isSecure() ? 2 : 1) instanceof ARecord);
+ assertEquals("test1.root.dev.test.",
+ ((CNAMERecord) recs.get(0)).getTarget().toString(), "wrong target name");
+ assertTrue(recs.get(isSecure() ? 2 : 1) instanceof ARecord, "not an ARecord");
recs = assertDNSQuery("appmaster-ipc-api.test1.root.dev.test.",
Type.SRV, 1);
- assertTrue("not an SRV record", recs.get(0) instanceof SRVRecord);
- assertEquals("wrong port", 1026, ((SRVRecord) recs.get(0)).getPort());
+ assertTrue(recs.get(0) instanceof SRVRecord, "not an SRV record");
+ assertEquals(1026, ((SRVRecord) recs.get(0)).getPort(), "wrong port");
recs = assertDNSQuery("appmaster-ipc-api.test1.root.dev.test.", 2);
- assertEquals("wrong target name", "test1.root.dev.test.",
- ((CNAMERecord) recs.get(0)).getTarget().toString());
- assertTrue("not an ARecord",
- recs.get(isSecure() ? 2 : 1) instanceof ARecord);
+ assertEquals("test1.root.dev.test.",
+ ((CNAMERecord) recs.get(0)).getTarget().toString(), "wrong target name");
+ assertTrue(recs.get(isSecure() ? 2 : 1) instanceof ARecord, "not an ARecord");
recs = assertDNSQuery("http-api.test1.root.dev.test.", 2);
- assertEquals("wrong target name", "test1.root.dev.test.",
- ((CNAMERecord) recs.get(0)).getTarget().toString());
- assertTrue("not an ARecord",
- recs.get(isSecure() ? 2 : 1) instanceof ARecord);
+ assertEquals("test1.root.dev.test.",
+ ((CNAMERecord) recs.get(0)).getTarget().toString(), "wrong target name");
+ assertTrue(recs.get(isSecure() ? 2 : 1) instanceof ARecord, "not an ARecord");
recs = assertDNSQuery("http-api.test1.root.dev.test.", Type.SRV,
1);
- assertTrue("not an SRV record", recs.get(0) instanceof SRVRecord);
- assertEquals("wrong port", 1027, ((SRVRecord) recs.get(0)).getPort());
+ assertTrue(recs.get(0) instanceof SRVRecord, "not an SRV record");
+ assertEquals(1027, ((SRVRecord) recs.get(0)).getPort(), "wrong port");
assertDNSQuery("test1.root.dev.test.", Type.TXT, 3);
assertDNSQuery("appmaster-ipc-api.test1.root.dev.test.", Type.TXT, 1);
@@ -245,11 +243,11 @@ public void testContainerRegistration() throws Exception {
// start assessing whether correct records are available
List recs =
assertDNSQuery("ctr-e50-1451931954322-0016-01-000002.dev.test.");
- assertEquals("wrong result", "172.17.0.19",
- ((ARecord) recs.get(0)).getAddress().getHostAddress());
+ assertEquals("172.17.0.19",
+ ((ARecord) recs.get(0)).getAddress().getHostAddress(), "wrong result");
recs = assertDNSQuery("httpd-1.test1.root.dev.test.", 1);
- assertTrue("not an ARecord", recs.get(0) instanceof ARecord);
+ assertTrue(recs.get(0) instanceof ARecord, "not an ARecord");
}
@Test
@@ -267,8 +265,8 @@ public void testContainerRegistrationPersistanceAbsent() throws Exception {
Message query = Message.newQuery(question);
byte[] responseBytes = registryDNS.generateReply(query, null);
Message response = new Message(responseBytes);
- assertEquals("Excepting NXDOMAIN as Record must not have regsisterd wrong",
- Rcode.NXDOMAIN, response.getRcode());
+ assertEquals(Rcode.NXDOMAIN, response.getRcode(),
+ "Excepting NXDOMAIN as Record must not have regsisterd wrong");
}
@Test
@@ -283,14 +281,14 @@ public void testRecordTTL() throws Exception {
// start assessing whether correct records are available
List recs = assertDNSQuery(
"ctr-e50-1451931954322-0016-01-000002.dev.test.");
- assertEquals("wrong result", "172.17.0.19",
- ((ARecord) recs.get(0)).getAddress().getHostAddress());
- assertEquals("wrong ttl", 30L, recs.get(0).getTTL());
+ assertEquals("172.17.0.19",
+ ((ARecord) recs.get(0)).getAddress().getHostAddress(), "wrong result");
+ assertEquals(30L, recs.get(0).getTTL(), "wrong ttl");
recs = assertDNSQuery("httpd-1.test1.root.dev.test.", 1);
- assertTrue("not an ARecord", recs.get(0) instanceof ARecord);
+ assertTrue(recs.get(0) instanceof ARecord, "not an ARecord");
- assertEquals("wrong ttl", 30L, recs.get(0).getTTL());
+ assertEquals(30L, recs.get(0).getTTL(), "wrong ttl");
}
@Test
@@ -305,9 +303,8 @@ public void testReverseLookup() throws Exception {
// start assessing whether correct records are available
List recs = assertDNSQuery(
"19.0.17.172.in-addr.arpa.", Type.PTR, 1);
- assertEquals("wrong result",
- "httpd-1.test1.root.dev.test.",
- ((PTRRecord) recs.get(0)).getTarget().toString());
+ assertEquals("httpd-1.test1.root.dev.test.",
+ ((PTRRecord) recs.get(0)).getTarget().toString(), "wrong result");
}
@Test
@@ -332,9 +329,8 @@ public void testReverseLookupInLargeNetwork() throws Exception {
// start assessing whether correct records are available
List recs = assertDNSQuery(
"19.0.17.172.in-addr.arpa.", Type.PTR, 1);
- assertEquals("wrong result",
- "httpd-1.test1.root.dev.test.",
- ((PTRRecord) recs.get(0)).getTarget().toString());
+ assertEquals("httpd-1.test1.root.dev.test.",
+ ((PTRRecord) recs.get(0)).getTarget().toString(), "wrong result");
}
@Test
@@ -354,8 +350,8 @@ public void testMissingReverseLookup() throws Exception {
query.addRecord(optRecord, Section.ADDITIONAL);
byte[] responseBytes = getRegistryDNS().generateReply(query, null);
Message response = new Message(responseBytes);
- assertEquals("Missing record should be: ", Rcode.NXDOMAIN,
- response.getRcode());
+ assertEquals(Rcode.NXDOMAIN, response.getRcode(),
+ "Missing record should be: ");
}
@Test
@@ -375,7 +371,7 @@ public void testNoContainerIP() throws Exception {
byte[] responseBytes = getRegistryDNS().generateReply(query, null);
Message response = new Message(responseBytes);
- assertEquals("wrong status", Rcode.NXDOMAIN, response.getRcode());
+ assertEquals(Rcode.NXDOMAIN, response.getRcode(), "wrong status");
}
private List assertDNSQuery(String lookup) throws IOException {
@@ -396,13 +392,13 @@ private List assertDNSQuery(String lookup, int type, int numRecs)
query.addRecord(optRecord, Section.ADDITIONAL);
byte[] responseBytes = getRegistryDNS().generateReply(query, null);
Message response = new Message(responseBytes);
- assertEquals("not successful", Rcode.NOERROR, response.getRcode());
- assertNotNull("Null response", response);
- assertEquals("Questions do not match", query.getQuestion(),
- response.getQuestion());
+ assertEquals(Rcode.NOERROR, response.getRcode(), "not successful");
+ assertNotNull(response, "Null response");
+ assertEquals(query.getQuestion(),
+ response.getQuestion(), "Questions do not match");
List recs = response.getSection(Section.ANSWER);
- assertEquals("wrong number of answer records",
- isSecure() ? numRecs * 2 : numRecs, recs.size());
+ assertEquals(isSecure() ? numRecs * 2 : numRecs, recs.size(),
+ "wrong number of answer records");
if (isSecure()) {
boolean signed = false;
for (Record record : recs) {
@@ -411,7 +407,7 @@ private List assertDNSQuery(String lookup, int type, int numRecs)
break;
}
}
- assertTrue("No signatures found", signed);
+ assertTrue(signed, "No signatures found");
}
return recs;
}
@@ -425,10 +421,10 @@ private List assertDNSQueryNotNull(
query.addRecord(optRecord, Section.ADDITIONAL);
byte[] responseBytes = getRegistryDNS().generateReply(query, null);
Message response = new Message(responseBytes);
- assertEquals("not successful", Rcode.NOERROR, response.getRcode());
- assertNotNull("Null response", response);
- assertEquals("Questions do not match", query.getQuestion(),
- response.getQuestion());
+ assertEquals(Rcode.NOERROR, response.getRcode(), "not successful");
+ assertNotNull(response, "Null response");
+ assertEquals(query.getQuestion(), response.getQuestion(),
+ "Questions do not match");
List recs = response.getSection(Section.ANSWER);
assertEquals(answerCount, recs.size());
assertEquals(type, recs.get(0).getType());
@@ -484,9 +480,9 @@ public void testIpv4toIpv6() throws Exception {
InetAddress address =
BaseServiceRecordProcessor
.getIpv6Address(InetAddress.getByName("172.17.0.19"));
- assertTrue("not an ipv6 address", address instanceof Inet6Address);
- assertEquals("wrong IP", "172.17.0.19",
- InetAddress.getByAddress(address.getAddress()).getHostAddress());
+ assertTrue(address instanceof Inet6Address, "not an ipv6 address");
+ assertEquals("172.17.0.19",
+ InetAddress.getByAddress(address.getAddress()).getHostAddress(), "wrong IP");
}
@Test
@@ -501,11 +497,11 @@ public void testAAAALookup() throws Exception {
// start assessing whether correct records are available
List recs = assertDNSQuery(
"ctr-e50-1451931954322-0016-01-000002.dev.test.", Type.AAAA, 1);
- assertEquals("wrong result", "172.17.0.19",
- ((AAAARecord) recs.get(0)).getAddress().getHostAddress());
+ assertEquals("172.17.0.19",
+ ((AAAARecord) recs.get(0)).getAddress().getHostAddress(), "wrong result");
recs = assertDNSQuery("httpd-1.test1.root.dev.test.", Type.AAAA, 1);
- assertTrue("not an ARecord", recs.get(0) instanceof AAAARecord);
+ assertTrue(recs.get(0) instanceof AAAARecord, "not an ARecord");
}
@Test
@@ -524,13 +520,13 @@ public void testNegativeLookup() throws Exception {
byte[] responseBytes = getRegistryDNS().generateReply(query, null);
Message response = new Message(responseBytes);
- assertEquals("not successful", Rcode.NXDOMAIN, response.getRcode());
- assertNotNull("Null response", response);
- assertEquals("Questions do not match", query.getQuestion(),
- response.getQuestion());
+ assertEquals(Rcode.NXDOMAIN, response.getRcode(), "not successful");
+ assertNotNull(response, "Null response");
+ assertEquals(query.getQuestion(),
+ response.getQuestion(), "Questions do not match");
List sectionArray = response.getSection(Section.AUTHORITY);
- assertEquals("Wrong number of recs in AUTHORITY", isSecure() ? 2 : 1,
- sectionArray.size());
+ assertEquals(isSecure() ? 2 : 1,
+ sectionArray.size(), "Wrong number of recs in AUTHORITY");
boolean soaFound = false;
for (Record rec : sectionArray) {
soaFound = rec.getType() == Type.SOA;
@@ -538,8 +534,7 @@ public void testNegativeLookup() throws Exception {
break;
}
}
- assertTrue("wrong record type",
- soaFound);
+ assertTrue(soaFound, "wrong record type");
}
@@ -576,17 +571,17 @@ public void testReadMasterFile() throws Exception {
// start assessing whether correct records are available
List recs =
assertDNSQuery("ctr-e50-1451931954322-0016-01-000002.dev.test.");
- assertEquals("wrong result", "172.17.0.19",
- ((ARecord) recs.get(0)).getAddress().getHostAddress());
+ assertEquals("172.17.0.19",
+ ((ARecord) recs.get(0)).getAddress().getHostAddress(), "wrong result");
recs = assertDNSQuery("httpd-1.test1.root.dev.test.", 1);
- assertTrue("not an ARecord", recs.get(0) instanceof ARecord);
+ assertTrue(recs.get(0) instanceof ARecord, "not an ARecord");
// lookup dyanmic reverse records
recs = assertDNSQuery("19.0.17.172.in-addr.arpa.", Type.PTR, 1);
- assertEquals("wrong result",
+ assertEquals(
"httpd-1.test1.root.dev.test.",
- ((PTRRecord) recs.get(0)).getTarget().toString());
+ ((PTRRecord) recs.get(0)).getTarget().toString(), "wrong result");
// now lookup static reverse records
Name name = Name.fromString("5.0.17.172.in-addr.arpa.");
@@ -597,8 +592,8 @@ public void testReadMasterFile() throws Exception {
byte[] responseBytes = getRegistryDNS().generateReply(query, null);
Message response = new Message(responseBytes);
recs = response.getSection(Section.ANSWER);
- assertEquals("wrong result", "cn005.dev.test.",
- ((PTRRecord) recs.get(0)).getTarget().toString());
+ assertEquals("cn005.dev.test.",
+ ((PTRRecord) recs.get(0)).getTarget().toString(), "wrong result");
}
@Test
@@ -608,7 +603,7 @@ public void testReverseZoneNames() throws Exception {
conf.set(KEY_DNS_ZONE_MASK, "255.255.224.0");
Name name = getRegistryDNS().getReverseZoneName(conf);
- assertEquals("wrong name", "26.172.in-addr.arpa.", name.toString());
+ assertEquals("26.172.in-addr.arpa.", name.toString(), "wrong name");
}
@Test
@@ -643,7 +638,7 @@ public void testSplitReverseZoneNames() throws Exception {
public void testExampleDotCom() throws Exception {
Name name = Name.fromString("example.com.");
Record[] records = getRegistryDNS().getRecords(name, Type.SOA);
- assertNotNull("example.com exists:", records);
+ assertNotNull(records, "example.com exists:");
}
@Test
@@ -696,15 +691,16 @@ public void testMultiARecord() throws Exception {
// start assessing whether correct records are available
List recs =
assertDNSQuery("httpd.test1.root.dev.test.", 2);
- assertTrue("not an ARecord", recs.get(0) instanceof ARecord);
- assertTrue("not an ARecord", recs.get(1) instanceof ARecord);
+ assertTrue(recs.get(0) instanceof ARecord, "not an ARecord");
+ assertTrue(recs.get(1) instanceof ARecord, "not an ARecord");
}
- @Test(timeout=5000)
+ @Test
+ @Timeout(value = 5)
public void testUpstreamFault() throws Exception {
Name name = Name.fromString("19.0.17.172.in-addr.arpa.");
Record[] recs = getRegistryDNS().getRecords(name, Type.CNAME);
- assertNull("Record is not null", recs);
+ assertNull(recs, "Record is not null");
}
public RegistryDNS getRegistryDNS() {
diff --git a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestReverseZoneUtils.java b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestReverseZoneUtils.java
index 1331f756cb8af..ce95c6bd9a28d 100644
--- a/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestReverseZoneUtils.java
+++ b/hadoop-common-project/hadoop-registry/src/test/java/org/apache/hadoop/registry/server/dns/TestReverseZoneUtils.java
@@ -17,10 +17,10 @@
package org.apache.hadoop.registry.server.dns;
import java.net.UnknownHostException;
-import static org.junit.Assert.assertEquals;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.Test;
/**
* Tests for the reverse zone utilities.
@@ -30,8 +30,6 @@ public class TestReverseZoneUtils {
private static final int RANGE = 256;
private static final int INDEX = 0;
- @Rule public ExpectedException exception = ExpectedException.none();
-
@Test
public void testGetReverseZoneNetworkAddress() throws Exception {
assertEquals("172.17.4.0",
@@ -50,22 +48,25 @@ public void testSplitIp() throws Exception {
@Test
public void testThrowIllegalArgumentExceptionIfIndexIsNegative()
throws Exception {
- exception.expect(IllegalArgumentException.class);
- ReverseZoneUtils.getReverseZoneNetworkAddress(NET, RANGE, -1);
+ assertThrows(IllegalArgumentException.class, () -> {
+ ReverseZoneUtils.getReverseZoneNetworkAddress(NET, RANGE, -1);
+ });
}
@Test
public void testThrowUnknownHostExceptionIfIpIsInvalid() throws Exception {
- exception.expect(UnknownHostException.class);
- ReverseZoneUtils
- .getReverseZoneNetworkAddress("213124.21231.14123.13", RANGE, INDEX);
+ assertThrows(UnknownHostException.class, () -> {
+ ReverseZoneUtils.getReverseZoneNetworkAddress(
+ "213124.21231.14123.13", RANGE, INDEX);
+ });
}
@Test
public void testThrowIllegalArgumentExceptionIfRangeIsNegative()
throws Exception {
- exception.expect(IllegalArgumentException.class);
- ReverseZoneUtils.getReverseZoneNetworkAddress(NET, -1, INDEX);
+ assertThrows(IllegalArgumentException.class, () -> {
+ ReverseZoneUtils.getReverseZoneNetworkAddress(NET, -1, INDEX);
+ });
}
@Test