diff --git a/hadoop-cloud-storage-project/hadoop-huaweicloud/src/test/java/org/apache/hadoop/fs/obs/TestOBSFSMainOperations.java b/hadoop-cloud-storage-project/hadoop-huaweicloud/src/test/java/org/apache/hadoop/fs/obs/TestOBSFSMainOperations.java index 9864e5008a02f..342a0313b5cd5 100644 --- a/hadoop-cloud-storage-project/hadoop-huaweicloud/src/test/java/org/apache/hadoop/fs/obs/TestOBSFSMainOperations.java +++ b/hadoop-cloud-storage-project/hadoop-huaweicloud/src/test/java/org/apache/hadoop/fs/obs/TestOBSFSMainOperations.java @@ -72,7 +72,7 @@ public void testRenameDirectoryToItself() { @Override public void testGlobStatusThrowsExceptionForUnreadableDir() { - Assume.assumeTrue("unspport.", false); + assumeTrue(false, "unspport."); } @Override diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FCStatisticsBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FCStatisticsBaseTest.java index dc12f44fc2758..80edbeab4c8f8 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FCStatisticsBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FCStatisticsBaseTest.java @@ -19,6 +19,7 @@ package org.apache.hadoop.fs; import static org.apache.hadoop.fs.FileContextTestHelper.createFile; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.net.URI; @@ -34,8 +35,8 @@ import org.apache.hadoop.fs.FileSystem.Statistics; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.util.function.Supplier; import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.Uninterruptibles; @@ -59,17 +60,18 @@ public abstract class FCStatisticsBaseTest { //fc should be set appropriately by the deriving test. protected static FileContext fc = null; - @Test(timeout=60000) + @Test + @Timeout(value = 60) public void testStatisticsOperations() throws Exception { final Statistics stats = new Statistics("file"); - Assert.assertEquals(0L, stats.getBytesRead()); - Assert.assertEquals(0L, stats.getBytesWritten()); - Assert.assertEquals(0, stats.getWriteOps()); + assertEquals(0L, stats.getBytesRead()); + assertEquals(0L, stats.getBytesWritten()); + assertEquals(0, stats.getWriteOps()); stats.incrementBytesWritten(1000); - Assert.assertEquals(1000L, stats.getBytesWritten()); - Assert.assertEquals(0, stats.getWriteOps()); + assertEquals(1000L, stats.getBytesWritten()); + assertEquals(0, stats.getWriteOps()); stats.incrementWriteOps(123); - Assert.assertEquals(123, stats.getWriteOps()); + assertEquals(123, stats.getWriteOps()); Thread thread = new Thread() { @Override @@ -79,33 +81,33 @@ public void run() { }; thread.start(); Uninterruptibles.joinUninterruptibly(thread); - Assert.assertEquals(124, stats.getWriteOps()); + assertEquals(124, stats.getWriteOps()); // Test copy constructor and reset function Statistics stats2 = new Statistics(stats); stats.reset(); - Assert.assertEquals(0, stats.getWriteOps()); - Assert.assertEquals(0L, stats.getBytesWritten()); - Assert.assertEquals(0L, stats.getBytesRead()); - Assert.assertEquals(124, stats2.getWriteOps()); - Assert.assertEquals(1000L, stats2.getBytesWritten()); - Assert.assertEquals(0L, stats2.getBytesRead()); + assertEquals(0, stats.getWriteOps()); + assertEquals(0L, stats.getBytesWritten()); + assertEquals(0L, stats.getBytesRead()); + assertEquals(124, stats2.getWriteOps()); + assertEquals(1000L, stats2.getBytesWritten()); + assertEquals(0L, stats2.getBytesRead()); } @Test public void testStatistics() throws IOException, URISyntaxException { URI fsUri = getFsUri(); Statistics stats = FileContext.getStatistics(fsUri); - Assert.assertEquals(0, stats.getBytesRead()); + assertEquals(0, stats.getBytesRead()); Path filePath = fileContextTestHelper .getTestRootPath(fc, "file1"); createFile(fc, filePath, numBlocks, blockSize); - Assert.assertEquals(0, stats.getBytesRead()); + assertEquals(0, stats.getBytesRead()); verifyWrittenBytes(stats); FSDataInputStream fstr = fc.open(filePath); byte[] buf = new byte[blockSize]; int bytesRead = fstr.read(buf, 0, blockSize); fstr.read(0, buf, 0, blockSize); - Assert.assertEquals(blockSize, bytesRead); + assertEquals(blockSize, bytesRead); verifyReadBytes(stats); verifyWrittenBytes(stats); verifyReadBytes(FileContext.getStatistics(getFsUri())); @@ -115,7 +117,8 @@ public void testStatistics() throws IOException, URISyntaxException { fc.delete(filePath, true); } - @Test(timeout=70000) + @Test + @Timeout(value = 70) public void testStatisticsThreadLocalDataCleanUp() throws Exception { final Statistics stats = new Statistics("test"); // create a small thread pool to test the statistics @@ -136,8 +139,8 @@ public Boolean call() { // assert that the data size is exactly the number of threads final AtomicInteger allDataSize = new AtomicInteger(0); allDataSize.set(stats.getAllThreadLocalDataSize()); - Assert.assertEquals(size, allDataSize.get()); - Assert.assertEquals(size, stats.getReadOps()); + assertEquals(size, allDataSize.get()); + assertEquals(size, stats.getReadOps()); // force the GC to collect the threads by shutting down the thread pool es.shutdownNow(); es.awaitTermination(1, TimeUnit.MINUTES); @@ -160,8 +163,8 @@ public Boolean get() { return false; } }, 500, 60*1000); - Assert.assertEquals(0, allDataSize.get()); - Assert.assertEquals(size, stats.getReadOps()); + assertEquals(0, allDataSize.get()); + assertEquals(size, stats.getReadOps()); } /** diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FSMainOperationsBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FSMainOperationsBaseTest.java index 07f0e81619350..be1baa97c8810 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FSMainOperationsBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FSMainOperationsBaseTest.java @@ -18,20 +18,24 @@ package org.apache.hadoop.fs; +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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URI; - - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Options.Rename; import org.apache.hadoop.fs.permission.FsPermission; -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.BeforeEach; +import org.junit.jupiter.api.Test; import org.eclipse.jetty.util.log.Log; /** @@ -94,13 +98,13 @@ public FSMainOperationsBaseTest(String testRootDir) { super(testRootDir); } - @Before + @BeforeEach public void setUp() throws Exception { fSys = createFileSystem(); fSys.mkdirs(getTestRootPath(fSys, "test")); } - @After + @AfterEach public void tearDown() throws Exception { if (fSys != null) { fSys.delete(new Path(getAbsoluteTestRootPath(fSys), new Path("test")), true); @@ -126,11 +130,11 @@ protected IOException unwrapException(IOException e) { @Test public void testFsStatus() throws Exception { FsStatus fsStatus = fSys.getStatus(null); - Assert.assertNotNull(fsStatus); + assertNotNull(fsStatus); //used, free and capacity are non-negative longs - Assert.assertTrue(fsStatus.getUsed() >= 0); - Assert.assertTrue(fsStatus.getRemaining() >= 0); - Assert.assertTrue(fsStatus.getCapacity() >= 0); + assertTrue(fsStatus.getUsed() >= 0); + assertTrue(fsStatus.getRemaining() >= 0); + assertTrue(fsStatus.getCapacity() >= 0); } @Test @@ -139,31 +143,31 @@ public void testWorkingDirectory() throws Exception { // First we cd to our test root Path workDir = new Path(getAbsoluteTestRootPath(fSys), new Path("test")); fSys.setWorkingDirectory(workDir); - Assert.assertEquals(workDir, fSys.getWorkingDirectory()); + assertEquals(workDir, fSys.getWorkingDirectory()); fSys.setWorkingDirectory(new Path(".")); - Assert.assertEquals(workDir, fSys.getWorkingDirectory()); + assertEquals(workDir, fSys.getWorkingDirectory()); fSys.setWorkingDirectory(new Path("..")); - Assert.assertEquals(workDir.getParent(), fSys.getWorkingDirectory()); + assertEquals(workDir.getParent(), fSys.getWorkingDirectory()); // cd using a relative path // Go back to our test root workDir = new Path(getAbsoluteTestRootPath(fSys), new Path("test")); fSys.setWorkingDirectory(workDir); - Assert.assertEquals(workDir, fSys.getWorkingDirectory()); + assertEquals(workDir, fSys.getWorkingDirectory()); Path relativeDir = new Path("existingDir1"); Path absoluteDir = new Path(workDir,"existingDir1"); fSys.mkdirs(absoluteDir); fSys.setWorkingDirectory(relativeDir); - Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory()); + assertEquals(absoluteDir, fSys.getWorkingDirectory()); // cd using a absolute path absoluteDir = getTestRootPath(fSys, "test/existingDir2"); fSys.mkdirs(absoluteDir); fSys.setWorkingDirectory(absoluteDir); - Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory()); + assertEquals(absoluteDir, fSys.getWorkingDirectory()); // Now open a file relative to the wd we just set above. Path absolutePath = new Path(absoluteDir, "foo"); @@ -173,7 +177,7 @@ public void testWorkingDirectory() throws Exception { // Now mkdir relative to the dir we cd'ed to fSys.mkdirs(new Path("newDir")); - Assert.assertTrue(isDir(fSys, new Path(absoluteDir, "newDir"))); + assertTrue(isDir(fSys, new Path(absoluteDir, "newDir"))); /** * We cannot test this because FileSystem has never checked for @@ -182,7 +186,7 @@ public void testWorkingDirectory() throws Exception { absoluteDir = getTestRootPath(fSys, "nonexistingPath"); try { fSys.setWorkingDirectory(absoluteDir); - Assert.fail("cd to non existing dir should have failed"); + fail("cd to non existing dir should have failed"); } catch (Exception e) { // Exception as expected } @@ -197,61 +201,61 @@ public void testWDAbsolute() throws IOException { Path absoluteDir = getTestRootPath(fSys, "test/existingDir"); fSys.mkdirs(absoluteDir); fSys.setWorkingDirectory(absoluteDir); - Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory()); + assertEquals(absoluteDir, fSys.getWorkingDirectory()); } @Test public void testMkdirs() throws Exception { Path testDir = getTestRootPath(fSys, "test/hadoop"); - Assert.assertFalse(exists(fSys, testDir)); - Assert.assertFalse(isFile(fSys, testDir)); + assertFalse(exists(fSys, testDir)); + assertFalse(isFile(fSys, testDir)); fSys.mkdirs(testDir); - Assert.assertTrue(exists(fSys, testDir)); - Assert.assertFalse(isFile(fSys, testDir)); + assertTrue(exists(fSys, testDir)); + assertFalse(isFile(fSys, testDir)); fSys.mkdirs(testDir); - Assert.assertTrue(exists(fSys, testDir)); - Assert.assertFalse(isFile(fSys, testDir)); + assertTrue(exists(fSys, testDir)); + assertFalse(isFile(fSys, testDir)); Path parentDir = testDir.getParent(); - Assert.assertTrue(exists(fSys, parentDir)); - Assert.assertFalse(isFile(fSys, parentDir)); + assertTrue(exists(fSys, parentDir)); + assertFalse(isFile(fSys, parentDir)); Path grandparentDir = parentDir.getParent(); - Assert.assertTrue(exists(fSys, grandparentDir)); - Assert.assertFalse(isFile(fSys, grandparentDir)); + assertTrue(exists(fSys, grandparentDir)); + assertFalse(isFile(fSys, grandparentDir)); } @Test public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception { Path testDir = getTestRootPath(fSys, "test/hadoop"); - Assert.assertFalse(exists(fSys, testDir)); + assertFalse(exists(fSys, testDir)); fSys.mkdirs(testDir); - Assert.assertTrue(exists(fSys, testDir)); + assertTrue(exists(fSys, testDir)); createFile(getTestRootPath(fSys, "test/hadoop/file")); Path testSubDir = getTestRootPath(fSys, "test/hadoop/file/subdir"); try { fSys.mkdirs(testSubDir); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } - Assert.assertFalse(exists(fSys, testSubDir)); + assertFalse(exists(fSys, testSubDir)); Path testDeepSubDir = getTestRootPath(fSys, "test/hadoop/file/deep/sub/dir"); try { fSys.mkdirs(testDeepSubDir); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } - Assert.assertFalse(exists(fSys, testDeepSubDir)); + assertFalse(exists(fSys, testDeepSubDir)); } @@ -260,7 +264,7 @@ public void testGetFileStatusThrowsExceptionForNonExistentFile() throws Exception { try { fSys.getFileStatus(getTestRootPath(fSys, "test/hadoop/file")); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (FileNotFoundException e) { // expected } @@ -271,7 +275,7 @@ public void testListStatusThrowsExceptionForNonExistentFile() throws Exception { try { fSys.listStatus(getTestRootPath(fSys, "test/hadoop/file")); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (FileNotFoundException fnfe) { // expected } @@ -287,7 +291,7 @@ public void testListStatusThrowsExceptionForUnreadableDir() fSys.setPermission(obscuredDir, new FsPermission((short)0)); //no access try { fSys.listStatus(obscuredDir); - Assert.fail("Should throw IOException"); + fail("Should throw IOException"); } catch (IOException ioe) { // expected } finally { @@ -303,7 +307,7 @@ public void testListStatus() throws Exception { getTestRootPath(fSys, "test/hadoop/a"), getTestRootPath(fSys, "test/hadoop/b"), getTestRootPath(fSys, "test/hadoop/c/1"), }; - Assert.assertFalse(exists(fSys, testDirs[0])); + assertFalse(exists(fSys, testDirs[0])); for (Path path : testDirs) { fSys.mkdirs(path); @@ -311,21 +315,21 @@ public void testListStatus() throws Exception { // test listStatus that returns an array FileStatus[] paths = fSys.listStatus(getTestRootPath(fSys, "test")); - Assert.assertEquals(1, paths.length); - Assert.assertEquals(getTestRootPath(fSys, "test/hadoop"), paths[0].getPath()); + assertEquals(1, paths.length); + assertEquals(getTestRootPath(fSys, "test/hadoop"), paths[0].getPath()); paths = fSys.listStatus(getTestRootPath(fSys, "test/hadoop")); - Assert.assertEquals(3, paths.length); + assertEquals(3, paths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/a"), + assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/a"), paths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/b"), + assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/b"), paths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/c"), + assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/c"), paths)); paths = fSys.listStatus(getTestRootPath(fSys, "test/hadoop/a")); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); } @@ -346,7 +350,7 @@ public void testListStatusFilterWithNoMatches() throws Exception { // listStatus with filters returns empty correctly FileStatus[] filteredPaths = fSys.listStatus( getTestRootPath(fSys, "test"), TEST_X_FILTER); - Assert.assertEquals(0,filteredPaths.length); + assertEquals(0, filteredPaths.length); } @@ -367,10 +371,10 @@ public void testListStatusFilterWithSomeMatches() throws Exception { // should return 2 paths ("/test/hadoop/axa" and "/test/hadoop/axx") FileStatus[] filteredPaths = fSys.listStatus( getTestRootPath(fSys, "test/hadoop"), TEST_X_FILTER); - Assert.assertEquals(2,filteredPaths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertEquals(2, filteredPaths.length); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), filteredPaths)); } @@ -378,14 +382,14 @@ public void testListStatusFilterWithSomeMatches() throws Exception { public void testGlobStatusNonExistentFile() throws Exception { FileStatus[] paths = fSys.globStatus( getTestRootPath(fSys, "test/hadoopfsdf")); - Assert.assertNull(paths); + assertNull(paths); paths = fSys.globStatus( getTestRootPath(fSys, "test/hadoopfsdf/?")); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); paths = fSys.globStatus( getTestRootPath(fSys, "test/hadoopfsdf/xyz*/?")); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); } @Test @@ -405,7 +409,7 @@ public void testGlobStatusWithNoMatchesInPath() throws Exception { // should return nothing FileStatus[] paths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop/?")); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); } @Test @@ -425,10 +429,10 @@ public void testGlobStatusSomeMatchesInDirectories() throws Exception { // Should return two items ("/test/hadoop" and "/test/hadoop2") FileStatus[] paths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop*")); - Assert.assertEquals(2, paths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertEquals(2, paths.length); + assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop"), paths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop2"), paths)); } @@ -450,11 +454,11 @@ public void testGlobStatusWithMultipleWildCardMatches() throws Exception { //"/test/hadoop/axx", and "/test/hadoop2/axx") FileStatus[] paths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop*/*")); - Assert.assertEquals(4, paths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA), paths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), paths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), paths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA2), paths)); + assertEquals(4, paths.length); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA), paths)); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), paths)); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), paths)); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA2), paths)); } @Test @@ -474,10 +478,10 @@ public void testGlobStatusWithMultipleMatchesOfSingleChar() throws Exception { //Should return only 2 items ("/test/hadoop/axa", "/test/hadoop/axx") FileStatus[] paths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop/ax?")); - Assert.assertEquals(2, paths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertEquals(2, paths.length); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), paths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), paths)); } @@ -499,7 +503,7 @@ public void testGlobStatusFilterWithEmptyPathResults() throws Exception { FileStatus[] filteredPaths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop/?"), DEFAULT_FILTER); - Assert.assertEquals(0,filteredPaths.length); + assertEquals(0, filteredPaths.length); } @Test @@ -521,12 +525,12 @@ public void testGlobStatusFilterWithSomePathMatchesAndTrivialFilter() FileStatus[] filteredPaths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop/*"), DEFAULT_FILTER); - Assert.assertEquals(3, filteredPaths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertEquals(3, filteredPaths.length); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA), filteredPaths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), filteredPaths)); } @@ -549,12 +553,12 @@ public void testGlobStatusFilterWithMultipleWildCardMatchesAndTrivialFilter() FileStatus[] filteredPaths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop/a??"), DEFAULT_FILTER); - Assert.assertEquals(3, filteredPaths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA), + assertEquals(3, filteredPaths.length); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA), filteredPaths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), filteredPaths)); } @@ -577,10 +581,10 @@ public void testGlobStatusFilterWithMultiplePathMatchesAndNonTrivialFilter() FileStatus[] filteredPaths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop/*"), TEST_X_FILTER); - Assert.assertEquals(2, filteredPaths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertEquals(2, filteredPaths.length); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), filteredPaths)); } @@ -603,7 +607,7 @@ public void testGlobStatusFilterWithNoMatchingPathsAndNonTrivialFilter() FileStatus[] filteredPaths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop/?"), TEST_X_FILTER); - Assert.assertEquals(0,filteredPaths.length); + assertEquals(0, filteredPaths.length); } @Test @@ -625,10 +629,10 @@ public void testGlobStatusFilterWithMultiplePathWildcardsAndNonTrivialFilter() FileStatus[] filteredPaths = fSys.globStatus( getTestRootPath(fSys, "test/hadoop/a??"), TEST_X_FILTER); - Assert.assertEquals(2, filteredPaths.length); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), + assertEquals(2, filteredPaths.length); + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), + assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), filteredPaths)); } @@ -642,7 +646,7 @@ public void testGlobStatusThrowsExceptionForUnreadableDir() fSys.setPermission(obscuredDir, new FsPermission((short)0)); //no access try { fSys.globStatus(getTestRootPath(fSys, "test/hadoop/dir/foo/*")); - Assert.fail("Should throw IOException"); + fail("Should throw IOException"); } catch (IOException ioe) { // expected } finally { @@ -688,22 +692,22 @@ protected void writeReadAndDelete(int len) throws IOException { out.write(data, 0, len); out.close(); - Assert.assertTrue("Exists", exists(fSys, path)); - Assert.assertEquals("Length", len, fSys.getFileStatus(path).getLen()); + assertTrue(exists(fSys, path), "Exists"); + assertEquals(len, fSys.getFileStatus(path).getLen(), "Length"); FSDataInputStream in = fSys.open(path); byte[] buf = new byte[len]; in.readFully(0, buf); in.close(); - Assert.assertEquals(len, buf.length); + assertEquals(len, buf.length); for (int i = 0; i < buf.length; i++) { - Assert.assertEquals("Position " + i, data[i], buf[i]); + assertEquals(data[i], buf[i], "Position " + i); } - Assert.assertTrue("Deleted", fSys.delete(path, false)); + assertTrue(fSys.delete(path, false), "Deleted"); - Assert.assertFalse("No longer exists", exists(fSys, path)); + assertFalse(exists(fSys, path), "No longer exists"); } @@ -715,12 +719,12 @@ public void testOverwrite() throws IOException { createFile(path); - Assert.assertTrue("Exists", exists(fSys, path)); - Assert.assertEquals("Length", data.length, fSys.getFileStatus(path).getLen()); + assertTrue(exists(fSys, path), "Exists"); + assertEquals(data.length, fSys.getFileStatus(path).getLen(), "Length"); try { createFile(path); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // Expected } @@ -729,27 +733,27 @@ public void testOverwrite() throws IOException { out.write(data, 0, data.length); out.close(); - Assert.assertTrue("Exists", exists(fSys, path)); - Assert.assertEquals("Length", data.length, fSys.getFileStatus(path).getLen()); + assertTrue(exists(fSys, path), "Exists"); + assertEquals(data.length, fSys.getFileStatus(path).getLen(), "Length"); } @Test public void testWriteInNonExistentDirectory() throws IOException { Path path = getTestRootPath(fSys, "test/hadoop/file"); - Assert.assertFalse("Parent doesn't exist", exists(fSys, path.getParent())); + assertFalse(exists(fSys, path.getParent()), "Parent doesn't exist"); createFile(path); - Assert.assertTrue("Exists", exists(fSys, path)); - Assert.assertEquals("Length", data.length, fSys.getFileStatus(path).getLen()); - Assert.assertTrue("Parent exists", exists(fSys, path.getParent())); + assertTrue(exists(fSys, path), "Exists"); + assertEquals(data.length, fSys.getFileStatus(path).getLen(), "Length"); + assertTrue(exists(fSys, path.getParent()), "Parent exists"); } @Test public void testDeleteNonExistentFile() throws IOException { Path path = getTestRootPath(fSys, "test/hadoop/file"); - Assert.assertFalse("Doesn't exist", exists(fSys, path)); - Assert.assertFalse("No deletion", fSys.delete(path, true)); + assertFalse(exists(fSys, path), "Doesn't exist"); + assertFalse(fSys.delete(path, true), "No deletion"); } @Test @@ -761,33 +765,33 @@ public void testDeleteRecursively() throws IOException { createFile(file); fSys.mkdirs(subdir); - Assert.assertTrue("File exists", exists(fSys, file)); - Assert.assertTrue("Dir exists", exists(fSys, dir)); - Assert.assertTrue("Subdir exists", exists(fSys, subdir)); + assertTrue(exists(fSys, file), "File exists"); + assertTrue(exists(fSys, dir), "Dir exists"); + assertTrue(exists(fSys, subdir), "Subdir exists"); try { fSys.delete(dir, false); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } - Assert.assertTrue("File still exists", exists(fSys, file)); - Assert.assertTrue("Dir still exists", exists(fSys, dir)); - Assert.assertTrue("Subdir still exists", exists(fSys, subdir)); + assertTrue(exists(fSys, file), "File still exists"); + assertTrue(exists(fSys, dir), "Dir still exists"); + assertTrue(exists(fSys, subdir), "Subdir still exists"); - Assert.assertTrue("Deleted", fSys.delete(dir, true)); - Assert.assertFalse("File doesn't exist", exists(fSys, file)); - Assert.assertFalse("Dir doesn't exist", exists(fSys, dir)); - Assert.assertFalse("Subdir doesn't exist", exists(fSys, subdir)); + assertTrue(fSys.delete(dir, true), "Deleted"); + assertFalse(exists(fSys, file), "File doesn't exist"); + assertFalse(exists(fSys, dir), "Dir doesn't exist"); + assertFalse(exists(fSys, subdir), "Subdir doesn't exist"); } @Test public void testDeleteEmptyDirectory() throws IOException { Path dir = getTestRootPath(fSys, "test/hadoop"); fSys.mkdirs(dir); - Assert.assertTrue("Dir exists", exists(fSys, dir)); - Assert.assertTrue("Deleted", fSys.delete(dir, false)); - Assert.assertFalse("Dir doesn't exist", exists(fSys, dir)); + assertTrue(exists(fSys, dir), "Dir exists"); + assertTrue(fSys.delete(dir, false), "Deleted"); + assertFalse(exists(fSys, dir), "Dir doesn't exist"); } @Test @@ -797,17 +801,17 @@ public void testRenameNonExistentPath() throws Exception { Path dst = getTestRootPath(fSys, "test/new/newpath"); try { rename(src, dst, false, false, false, Rename.NONE); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (IOException e) { Log.getLog().info("XXX", e); - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } try { rename(src, dst, false, false, false, Rename.OVERWRITE); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } } @@ -821,16 +825,16 @@ public void testRenameFileToNonExistentDirectory() throws Exception { try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } try { rename(src, dst, false, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } } @@ -845,13 +849,13 @@ public void testRenameFileToDestinationWithParentFile() throws Exception { try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } try { rename(src, dst, false, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } } @@ -874,14 +878,14 @@ public void testRenameFileToItself() throws Exception { createFile(src); try { rename(src, src, false, true, false, Rename.NONE); - Assert.fail("Renamed file to itself"); + fail("Renamed file to itself"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Also fails with overwrite try { rename(src, src, false, true, false, Rename.OVERWRITE); - Assert.fail("Renamed file to itself"); + fail("Renamed file to itself"); } catch (IOException e) { // worked } @@ -899,9 +903,9 @@ public void testRenameFileAsExistingFile() throws Exception { // Fails without overwrite option try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Succeeds with overwrite option @@ -920,14 +924,14 @@ public void testRenameFileAsExistingDirectory() throws Exception { // Fails without overwrite option try { rename(src, dst, false, false, true, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } // File cannot be renamed as directory try { rename(src, dst, false, false, true, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } } @@ -939,14 +943,14 @@ public void testRenameDirectoryToItself() throws Exception { fSys.mkdirs(src); try { rename(src, src, false, true, false, Rename.NONE); - Assert.fail("Renamed directory to itself"); + fail("Renamed directory to itself"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Also fails with overwrite try { rename(src, src, false, true, false, Rename.OVERWRITE); - Assert.fail("Renamed directory to itself"); + fail("Renamed directory to itself"); } catch (IOException e) { // worked } @@ -962,7 +966,7 @@ public void testRenameDirectoryToNonExistentParent() throws Exception { try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { IOException ioException = unwrapException(e); if (!(ioException instanceof FileNotFoundException)) { @@ -972,7 +976,7 @@ public void testRenameDirectoryToNonExistentParent() throws Exception { try { rename(src, dst, false, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { IOException ioException = unwrapException(e); if (!(ioException instanceof FileNotFoundException)) { @@ -1001,14 +1005,14 @@ private void doTestRenameDirectoryAsNonExistentDirectory(Rename... options) fSys.mkdirs(dst.getParent()); rename(src, dst, true, false, true, options); - Assert.assertFalse("Nested file1 exists", - exists(fSys, getTestRootPath(fSys, "test/hadoop/dir/file1"))); - Assert.assertFalse("Nested file2 exists", - exists(fSys, getTestRootPath(fSys, "test/hadoop/dir/subdir/file2"))); - Assert.assertTrue("Renamed nested file1 exists", - exists(fSys, getTestRootPath(fSys, "test/new/newdir/file1"))); - Assert.assertTrue("Renamed nested exists", - exists(fSys, getTestRootPath(fSys, "test/new/newdir/subdir/file2"))); + assertFalse(exists(fSys, getTestRootPath(fSys, + "test/hadoop/dir/file1")), "Nested file1 exists"); + assertFalse(exists(fSys, getTestRootPath(fSys, "test/hadoop/dir/subdir/file2")), + "Nested file2 exists"); + assertTrue(exists(fSys, getTestRootPath(fSys, "test/new/newdir/file1")), + "Renamed nested file1 exists"); + assertTrue(exists(fSys, getTestRootPath(fSys, "test/new/newdir/subdir/file2")), + "Renamed nested exists"); } @Test @@ -1026,10 +1030,10 @@ public void testRenameDirectoryAsEmptyDirectory() throws Exception { // Fails without overwrite option try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { // Expected (cannot over-write non-empty destination) - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Succeeds with the overwrite option rename(src, dst, true, false, true, Rename.OVERWRITE); @@ -1050,15 +1054,15 @@ public void testRenameDirectoryAsNonEmptyDirectory() throws Exception { // Fails without overwrite option try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { // Expected (cannot over-write non-empty destination) - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Fails even with the overwrite option try { rename(src, dst, false, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException ex) { // Expected (cannot over-write non-empty destination) } @@ -1075,13 +1079,13 @@ public void testRenameDirectoryAsFile() throws Exception { // Fails without overwrite option try { rename(src, dst, false, true, true, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } // Directory cannot be renamed as existing file try { rename(src, dst, false, true, true, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException ex) { } } @@ -1117,7 +1121,7 @@ public void testGetWrappedInputStream() throws IOException { FSDataInputStream in = fSys.open(src); InputStream is = in.getWrappedStream(); in.close(); - Assert.assertNotNull(is); + assertNotNull(is); } @Test @@ -1130,10 +1134,9 @@ public void testCopyToLocalWithUseRawLocalFileSystemOption() throws Exception { fSys.initialize(new URI("file:///"), conf); writeFile(fSys, fileToFS); if (fSys.exists(crcFileAtLFS)) - Assert.assertTrue("CRC files not deleted", fSys - .delete(crcFileAtLFS, true)); + assertTrue(fSys.delete(crcFileAtLFS, true), "CRC files not deleted"); fSys.copyToLocalFile(false, fileToFS, fileToLFS, true); - Assert.assertFalse("CRC files are created", fSys.exists(crcFileAtLFS)); + assertFalse(fSys.exists(crcFileAtLFS), "CRC files are created"); } private void writeFile(FileSystem fs, Path name) throws IOException { @@ -1155,9 +1158,9 @@ private void rename(Path src, Path dst, boolean renameShouldSucceed, throws IOException { fSys.rename(src, dst, options); if (!renameShouldSucceed) - Assert.fail("rename should have thrown exception"); - Assert.assertEquals("Source exists", srcExists, exists(fSys, src)); - Assert.assertEquals("Destination exists", dstExists, exists(fSys, dst)); + fail("rename should have thrown exception"); + assertEquals(srcExists, exists(fSys, src), "Source exists"); + assertEquals(dstExists, exists(fSys, dst), "Destination exists"); } private boolean containsTestRootPath(Path path, FileStatus[] filteredPaths) throws IOException { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java index fcb1b6925a494..6f80b55c12a72 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextCreateMkdirBaseTest.java @@ -17,13 +17,14 @@ */ package org.apache.hadoop.fs; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; -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.BeforeEach; +import org.junit.jupiter.api.Test; import static org.apache.hadoop.fs.FileContextTestHelper.*; import static org.apache.hadoop.fs.contract.ContractTestUtils.assertIsDirectory; import static org.apache.hadoop.fs.contract.ContractTestUtils.assertIsFile; @@ -72,12 +73,12 @@ protected FileContextTestHelper createFileContextHelper() { return new FileContextTestHelper(); } - @Before + @BeforeEach public void setUp() throws Exception { fc.mkdir(getTestRootPath(fc), FileContext.DEFAULT_PERM, true); } - @After + @AfterEach public void tearDown() throws Exception { fc.delete(getTestRootPath(fc), true); } @@ -92,7 +93,7 @@ public void tearDown() throws Exception { public void testMkdirNonRecursiveWithExistingDir() throws IOException { Path f = getTestRootPath(fc, "aDir"); fc.mkdir(f, FileContext.DEFAULT_PERM, false); - Assert.assertTrue(isDir(fc, f)); + assertTrue(isDir(fc, f)); } @Test @@ -100,7 +101,7 @@ public void testMkdirNonRecursiveWithNonExistingDir() { try { fc.mkdir(getTestRootPath(fc,"NonExistant/aDir"), FileContext.DEFAULT_PERM, false); - Assert.fail("Mkdir with non existing parent dir should have failed"); + fail("Mkdir with non existing parent dir should have failed"); } catch (IOException e) { // failed As expected } @@ -111,7 +112,7 @@ public void testMkdirNonRecursiveWithNonExistingDir() { public void testMkdirRecursiveWithExistingDir() throws IOException { Path f = getTestRootPath(fc, "aDir"); fc.mkdir(f, FileContext.DEFAULT_PERM, true); - Assert.assertTrue(isDir(fc, f)); + assertTrue(isDir(fc, f)); } @@ -119,7 +120,7 @@ public void testMkdirRecursiveWithExistingDir() throws IOException { public void testMkdirRecursiveWithNonExistingDir() throws IOException { Path f = getTestRootPath(fc, "NonExistant2/aDir"); fc.mkdir(f, FileContext.DEFAULT_PERM, true); - Assert.assertTrue(isDir(fc, f)); + assertTrue(isDir(fc, f)); } @Test @@ -194,14 +195,14 @@ public void testWithRename() throws IOException, InterruptedException { public void testCreateNonRecursiveWithExistingDir() throws IOException { Path f = getTestRootPath(fc, "foo"); createFile(fc, f); - Assert.assertTrue(isFile(fc, f)); + assertTrue(isFile(fc, f)); } @Test public void testCreateNonRecursiveWithNonExistingDir() { try { createFileNonRecursive(fc, getTestRootPath(fc, "NonExisting/foo")); - Assert.fail("Create with non existing parent dir should have failed"); + fail("Create with non existing parent dir should have failed"); } catch (IOException e) { // As expected } @@ -212,7 +213,7 @@ public void testCreateNonRecursiveWithNonExistingDir() { public void testCreateRecursiveWithExistingDir() throws IOException { Path f = getTestRootPath(fc,"foo"); createFile(fc, f); - Assert.assertTrue(isFile(fc, f)); + assertTrue(isFile(fc, f)); } @@ -220,7 +221,7 @@ public void testCreateRecursiveWithExistingDir() throws IOException { public void testCreateRecursiveWithNonExistingDir() throws IOException { Path f = getTestRootPath(fc,"NonExisting/foo"); createFile(fc, f); - Assert.assertTrue(isFile(fc, f)); + assertTrue(isFile(fc, f)); } private Path getTestRootPath(FileContext fc) { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java index 6897a0d194323..d38186e59e0a4 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java @@ -18,6 +18,15 @@ package org.apache.hadoop.fs; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +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.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -33,11 +42,9 @@ import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.After; -import org.junit.Assert; -import static org.junit.Assert.*; -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; @@ -114,7 +121,7 @@ public boolean accept(Path file) { private static final byte[] data = getFileData(numBlocks, getDefaultBlockSize()); - @Before + @BeforeEach public void setUp() throws Exception { File testBuildData = GenericTestUtils.getRandomizedTestDir(); Path rootPath = new Path(testBuildData.getAbsolutePath(), @@ -123,7 +130,7 @@ public void setUp() throws Exception { fc.mkdir(getTestRootPath(fc, "test"), FileContext.DEFAULT_PERM, true); } - @After + @AfterEach public void tearDown() throws Exception { if (fc != null) { final Path testRoot = fileContextTestHelper.getAbsoluteTestRootPath(fc); @@ -161,11 +168,11 @@ protected IOException unwrapException(IOException e) { @Test public void testFsStatus() throws Exception { FsStatus fsStatus = fc.getFsStatus(null); - Assert.assertNotNull(fsStatus); + assertNotNull(fsStatus); //used, free and capacity are non-negative longs - Assert.assertTrue(fsStatus.getUsed() >= 0); - Assert.assertTrue(fsStatus.getRemaining() >= 0); - Assert.assertTrue(fsStatus.getCapacity() >= 0); + assertTrue(fsStatus.getUsed() >= 0); + assertTrue(fsStatus.getRemaining() >= 0); + assertTrue(fsStatus.getCapacity() >= 0); } @Test @@ -174,31 +181,31 @@ public void testWorkingDirectory() throws Exception { // First we cd to our test root Path workDir = new Path(fileContextTestHelper.getAbsoluteTestRootPath(fc), new Path("test")); fc.setWorkingDirectory(workDir); - Assert.assertEquals(workDir, fc.getWorkingDirectory()); + assertEquals(workDir, fc.getWorkingDirectory()); fc.setWorkingDirectory(new Path(".")); - Assert.assertEquals(workDir, fc.getWorkingDirectory()); + assertEquals(workDir, fc.getWorkingDirectory()); fc.setWorkingDirectory(new Path("..")); - Assert.assertEquals(workDir.getParent(), fc.getWorkingDirectory()); + assertEquals(workDir.getParent(), fc.getWorkingDirectory()); // cd using a relative path // Go back to our test root workDir = new Path(fileContextTestHelper.getAbsoluteTestRootPath(fc), new Path("test")); fc.setWorkingDirectory(workDir); - Assert.assertEquals(workDir, fc.getWorkingDirectory()); + assertEquals(workDir, fc.getWorkingDirectory()); Path relativeDir = new Path("existingDir1"); Path absoluteDir = new Path(workDir,"existingDir1"); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); fc.setWorkingDirectory(relativeDir); - Assert.assertEquals(absoluteDir, fc.getWorkingDirectory()); + assertEquals(absoluteDir, fc.getWorkingDirectory()); // cd using a absolute path absoluteDir = getTestRootPath(fc, "test/existingDir2"); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); fc.setWorkingDirectory(absoluteDir); - Assert.assertEquals(absoluteDir, fc.getWorkingDirectory()); + assertEquals(absoluteDir, fc.getWorkingDirectory()); // Now open a file relative to the wd we just set above. Path absolutePath = new Path(absoluteDir, "foo"); @@ -208,12 +215,12 @@ public void testWorkingDirectory() throws Exception { // Now mkdir relative to the dir we cd'ed to fc.mkdir(new Path("newDir"), FileContext.DEFAULT_PERM, true); - Assert.assertTrue(isDir(fc, new Path(absoluteDir, "newDir"))); + assertTrue(isDir(fc, new Path(absoluteDir, "newDir"))); absoluteDir = getTestRootPath(fc, "nonexistingPath"); try { fc.setWorkingDirectory(absoluteDir); - Assert.fail("cd to non existing dir should have failed"); + fail("cd to non existing dir should have failed"); } catch (Exception e) { // Exception as expected } @@ -223,7 +230,7 @@ public void testWorkingDirectory() throws Exception { absoluteDir = new Path(localFsRootPath, "existingDir"); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); fc.setWorkingDirectory(absoluteDir); - Assert.assertEquals(absoluteDir, fc.getWorkingDirectory()); + assertEquals(absoluteDir, fc.getWorkingDirectory()); Path aRegularFile = new Path("aRegularFile"); createFile(aRegularFile); @@ -238,48 +245,48 @@ public void testWorkingDirectory() throws Exception { @Test public void testMkdirs() throws Exception { Path testDir = getTestRootPath(fc, "test/hadoop"); - Assert.assertFalse(exists(fc, testDir)); - Assert.assertFalse(isFile(fc, testDir)); + assertFalse(exists(fc, testDir)); + assertFalse(isFile(fc, testDir)); fc.mkdir(testDir, FsPermission.getDefault(), true); - Assert.assertTrue(exists(fc, testDir)); - Assert.assertFalse(isFile(fc, testDir)); + assertTrue(exists(fc, testDir)); + assertFalse(isFile(fc, testDir)); fc.mkdir(testDir, FsPermission.getDefault(), true); - Assert.assertTrue(exists(fc, testDir)); - Assert.assertFalse(isFile(fc, testDir)); + assertTrue(exists(fc, testDir)); + assertFalse(isFile(fc, testDir)); Path parentDir = testDir.getParent(); - Assert.assertTrue(exists(fc, parentDir)); - Assert.assertFalse(isFile(fc, parentDir)); + assertTrue(exists(fc, parentDir)); + assertFalse(isFile(fc, parentDir)); Path grandparentDir = parentDir.getParent(); - Assert.assertTrue(exists(fc, grandparentDir)); - Assert.assertFalse(isFile(fc, grandparentDir)); + assertTrue(exists(fc, grandparentDir)); + assertFalse(isFile(fc, grandparentDir)); } @Test public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception { Path testDir = getTestRootPath(fc, "test/hadoop"); - Assert.assertFalse(exists(fc, testDir)); + assertFalse(exists(fc, testDir)); fc.mkdir(testDir, FsPermission.getDefault(), true); - Assert.assertTrue(exists(fc, testDir)); + assertTrue(exists(fc, testDir)); createFile(getTestRootPath(fc, "test/hadoop/file")); Path testSubDir = getTestRootPath(fc, "test/hadoop/file/subdir"); try { fc.mkdir(testSubDir, FsPermission.getDefault(), true); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } try { - Assert.assertFalse(exists(fc, testSubDir)); + assertFalse(exists(fc, testSubDir)); } catch (AccessControlException e) { // Expected : HDFS-11132 Checks on paths under file may be rejected by // file missing execute permission. @@ -288,13 +295,13 @@ public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception { Path testDeepSubDir = getTestRootPath(fc, "test/hadoop/file/deep/sub/dir"); try { fc.mkdir(testDeepSubDir, FsPermission.getDefault(), true); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } try { - Assert.assertFalse(exists(fc, testDeepSubDir)); + assertFalse(exists(fc, testDeepSubDir)); } catch (AccessControlException e) { // Expected : HDFS-11132 Checks on paths under file may be rejected by // file missing execute permission. @@ -307,7 +314,7 @@ public void testGetFileStatusThrowsExceptionForNonExistentFile() throws Exception { try { fc.getFileStatus(getTestRootPath(fc, "test/hadoop/file")); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (FileNotFoundException e) { // expected } @@ -318,7 +325,7 @@ public void testListStatusThrowsExceptionForNonExistentFile() throws Exception { try { fc.listStatus(getTestRootPath(fc, "test/hadoop/file")); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (FileNotFoundException fnfe) { // expected } @@ -330,7 +337,7 @@ public void testListStatus() throws Exception { getTestRootPath(fc, "test/hadoop/a"), getTestRootPath(fc, "test/hadoop/b"), getTestRootPath(fc, "test/hadoop/c/1"), }; - Assert.assertFalse(exists(fc, testDirs[0])); + assertFalse(exists(fc, testDirs[0])); for (Path path : testDirs) { fc.mkdir(path, FsPermission.getDefault(), true); @@ -338,28 +345,28 @@ public void testListStatus() throws Exception { // test listStatus that returns an array FileStatus[] paths = fc.util().listStatus(getTestRootPath(fc, "test")); - Assert.assertEquals(1, paths.length); - Assert.assertEquals(getTestRootPath(fc, "test/hadoop"), paths[0].getPath()); + assertEquals(1, paths.length); + assertEquals(getTestRootPath(fc, "test/hadoop"), paths[0].getPath()); paths = fc.util().listStatus(getTestRootPath(fc, "test/hadoop")); - Assert.assertEquals(3, paths.length); + assertEquals(3, paths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/a"), + assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/a"), paths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/b"), + assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/b"), paths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/c"), + assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/c"), paths)); paths = fc.util().listStatus(getTestRootPath(fc, "test/hadoop/a")); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); // test listStatus that returns an iterator RemoteIterator pathsIterator = fc.listStatus(getTestRootPath(fc, "test")); - Assert.assertEquals(getTestRootPath(fc, "test/hadoop"), + assertEquals(getTestRootPath(fc, "test/hadoop"), pathsIterator.next().getPath()); - Assert.assertFalse(pathsIterator.hasNext()); + assertFalse(pathsIterator.hasNext()); pathsIterator = fc.listStatus(getTestRootPath(fc, "test/hadoop")); FileStatus[] subdirs = new FileStatus[3]; @@ -367,18 +374,18 @@ public void testListStatus() throws Exception { while(i<3 && pathsIterator.hasNext()) { subdirs[i++] = pathsIterator.next(); } - Assert.assertFalse(pathsIterator.hasNext()); - Assert.assertTrue(i==3); + assertFalse(pathsIterator.hasNext()); + assertTrue(i==3); - Assert.assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/a"), + assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/a"), subdirs)); - Assert.assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/b"), + assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/b"), subdirs)); - Assert.assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/c"), + assertTrue(containsPath(getTestRootPath(fc, "test/hadoop/c"), subdirs)); pathsIterator = fc.listStatus(getTestRootPath(fc, "test/hadoop/a")); - Assert.assertFalse(pathsIterator.hasNext()); + assertFalse(pathsIterator.hasNext()); } @Test @@ -436,7 +443,7 @@ public void testListStatusFilterWithNoMatches() throws Exception { // listStatus with filters returns empty correctly FileStatus[] filteredPaths = fc.util().listStatus( getTestRootPath(fc, "test"), TEST_X_FILTER); - Assert.assertEquals(0,filteredPaths.length); + assertEquals(0, filteredPaths.length); } @@ -458,10 +465,10 @@ public void testListStatusFilterWithSomeMatches() throws Exception { FileStatus[] filteredPaths = fc.util() .listStatus(getTestRootPath(fc, "test/hadoop"), TEST_X_FILTER); - Assert.assertEquals(2,filteredPaths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertEquals(2, filteredPaths.length); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), filteredPaths)); } @@ -469,14 +476,14 @@ public void testListStatusFilterWithSomeMatches() throws Exception { public void testGlobStatusNonExistentFile() throws Exception { FileStatus[] paths = fc.util().globStatus( getTestRootPath(fc, "test/hadoopfsdf")); - Assert.assertNull(paths); + assertNull(paths); paths = fc.util().globStatus( getTestRootPath(fc, "test/hadoopfsdf/?")); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); paths = fc.util().globStatus( getTestRootPath(fc, "test/hadoopfsdf/xyz*/?")); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); } @Test @@ -496,7 +503,7 @@ public void testGlobStatusWithNoMatchesInPath() throws Exception { // should return nothing FileStatus[] paths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop/?")); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); } @Test @@ -516,10 +523,10 @@ public void testGlobStatusSomeMatchesInDirectories() throws Exception { // Should return two items ("/test/hadoop" and "/test/hadoop2") FileStatus[] paths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop*")); - Assert.assertEquals(2, paths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertEquals(2, paths.length); + assertTrue(containsPath(getTestRootPath(fc, "test/hadoop"), paths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertTrue(containsPath(getTestRootPath(fc, "test/hadoop2"), paths)); } @@ -541,11 +548,11 @@ public void testGlobStatusWithMultipleWildCardMatches() throws Exception { //"/test/hadoop/axx", and "/test/hadoop2/axx") FileStatus[] paths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop*/*")); - Assert.assertEquals(4, paths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AAA), paths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), paths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), paths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AAA2), paths)); + assertEquals(4, paths.length); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AAA), paths)); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), paths)); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), paths)); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AAA2), paths)); } @Test @@ -565,10 +572,10 @@ public void testGlobStatusWithMultipleMatchesOfSingleChar() throws Exception { //Should return only 2 items ("/test/hadoop/axa", "/test/hadoop/axx") FileStatus[] paths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop/ax?")); - Assert.assertEquals(2, paths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertEquals(2, paths.length); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), paths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), paths)); } @@ -590,7 +597,7 @@ public void testGlobStatusFilterWithEmptyPathResults() throws Exception { FileStatus[] filteredPaths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop/?"), DEFAULT_FILTER); - Assert.assertEquals(0,filteredPaths.length); + assertEquals(0, filteredPaths.length); } @Test @@ -612,12 +619,12 @@ public void testGlobStatusFilterWithSomePathMatchesAndTrivialFilter() FileStatus[] filteredPaths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop/*"), DEFAULT_FILTER); - Assert.assertEquals(3, filteredPaths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertEquals(3, filteredPaths.length); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AAA), filteredPaths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), filteredPaths)); } @@ -640,12 +647,12 @@ public void testGlobStatusFilterWithMultipleWildCardMatchesAndTrivialFilter() FileStatus[] filteredPaths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop/a??"), DEFAULT_FILTER); - Assert.assertEquals(3, filteredPaths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AAA), + assertEquals(3, filteredPaths.length); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AAA), filteredPaths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), filteredPaths)); } @@ -668,10 +675,10 @@ public void testGlobStatusFilterWithMultiplePathMatchesAndNonTrivialFilter() FileStatus[] filteredPaths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop/*"), TEST_X_FILTER); - Assert.assertEquals(2, filteredPaths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertEquals(2, filteredPaths.length); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), filteredPaths)); } @@ -694,7 +701,7 @@ public void testGlobStatusFilterWithNoMatchingPathsAndNonTrivialFilter() FileStatus[] filteredPaths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop/?"), TEST_X_FILTER); - Assert.assertEquals(0,filteredPaths.length); + assertEquals(0, filteredPaths.length); } @Test @@ -716,10 +723,10 @@ public void testGlobStatusFilterWithMultiplePathWildcardsAndNonTrivialFilter() FileStatus[] filteredPaths = fc.util().globStatus( getTestRootPath(fc, "test/hadoop/a??"), TEST_X_FILTER); - Assert.assertEquals(2, filteredPaths.length); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), + assertEquals(2, filteredPaths.length); + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXA), filteredPaths)); - Assert.assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), + assertTrue(containsPath(getTestRootPath(fc, TEST_DIR_AXX), filteredPaths)); } @@ -760,52 +767,60 @@ private void writeReadAndDelete(int len) throws IOException { out.write(data, 0, len); out.close(); - Assert.assertTrue("Exists", exists(fc, path)); - Assert.assertEquals("Length", len, fc.getFileStatus(path).getLen()); + assertTrue(exists(fc, path), "Exists"); + assertEquals(len, fc.getFileStatus(path).getLen(), "Length"); FSDataInputStream in = fc.open(path); byte[] buf = new byte[len]; in.readFully(0, buf); in.close(); - Assert.assertEquals(len, buf.length); + assertEquals(len, buf.length); for (int i = 0; i < buf.length; i++) { - Assert.assertEquals("Position " + i, data[i], buf[i]); + assertEquals(data[i], buf[i], "Position " + i); } - Assert.assertTrue("Deleted", fc.delete(path, false)); + assertTrue(fc.delete(path, false), "Deleted"); - Assert.assertFalse("No longer exists", exists(fc, path)); + assertFalse(exists(fc, path), "No longer exists"); } - @Test(expected=HadoopIllegalArgumentException.class) + @Test public void testNullCreateFlag() throws IOException { - Path p = getTestRootPath(fc, "test/file"); - fc.create(p, null); - Assert.fail("Excepted exception not thrown"); + assertThrows(HadoopIllegalArgumentException.class, () -> { + Path p = getTestRootPath(fc, "test/file"); + fc.create(p, null); + fail("Excepted exception not thrown"); + }); } - @Test(expected=HadoopIllegalArgumentException.class) + @Test public void testEmptyCreateFlag() throws IOException { - Path p = getTestRootPath(fc, "test/file"); - fc.create(p, EnumSet.noneOf(CreateFlag.class)); - Assert.fail("Excepted exception not thrown"); + assertThrows(HadoopIllegalArgumentException.class, () -> { + Path p = getTestRootPath(fc, "test/file"); + fc.create(p, EnumSet.noneOf(CreateFlag.class)); + fail("Excepted exception not thrown"); + }); } - @Test(expected=FileAlreadyExistsException.class) + @Test public void testCreateFlagCreateExistingFile() throws IOException { - Path p = getTestRootPath(fc, "test/testCreateFlagCreateExistingFile"); - createFile(p); - fc.create(p, EnumSet.of(CREATE)); - Assert.fail("Excepted exception not thrown"); + assertThrows(FileAlreadyExistsException.class, () -> { + Path p = getTestRootPath(fc, "test/testCreateFlagCreateExistingFile"); + createFile(p); + fc.create(p, EnumSet.of(CREATE)); + fail("Excepted exception not thrown"); + }); } - @Test(expected=FileNotFoundException.class) + @Test public void testCreateFlagOverwriteNonExistingFile() throws IOException { - Path p = getTestRootPath(fc, "test/testCreateFlagOverwriteNonExistingFile"); - fc.create(p, EnumSet.of(OVERWRITE)); - Assert.fail("Excepted exception not thrown"); + assertThrows(FileNotFoundException.class, () -> { + Path p = getTestRootPath(fc, "test/testCreateFlagOverwriteNonExistingFile"); + fc.create(p, EnumSet.of(OVERWRITE)); + fail("Excepted exception not thrown"); + }); } @Test @@ -816,11 +831,13 @@ public void testCreateFlagOverwriteExistingFile() throws IOException { writeData(fc, p, out, data, data.length); } - @Test(expected=FileNotFoundException.class) + @Test public void testCreateFlagAppendNonExistingFile() throws IOException { - Path p = getTestRootPath(fc, "test/testCreateFlagAppendNonExistingFile"); - fc.create(p, EnumSet.of(APPEND)); - Assert.fail("Excepted exception not thrown"); + assertThrows(FileNotFoundException.class, () -> { + Path p = getTestRootPath(fc, "test/testCreateFlagAppendNonExistingFile"); + fc.create(p, EnumSet.of(APPEND)); + fail("Excepted exception not thrown"); + }); } @Test @@ -846,18 +863,22 @@ public void testCreateFlagCreateAppendExistingFile() throws IOException { writeData(fc, p, out, data, 2*data.length); } - @Test(expected=HadoopIllegalArgumentException.class) + @Test public void testCreateFlagAppendOverwrite() throws IOException { - Path p = getTestRootPath(fc, "test/nonExistent"); - fc.create(p, EnumSet.of(APPEND, OVERWRITE)); - Assert.fail("Excepted exception not thrown"); + assertThrows(HadoopIllegalArgumentException.class, () -> { + Path p = getTestRootPath(fc, "test/nonExistent"); + fc.create(p, EnumSet.of(APPEND, OVERWRITE)); + fail("Excepted exception not thrown"); + }); } - @Test(expected=HadoopIllegalArgumentException.class) + @Test public void testCreateFlagAppendCreateOverwrite() throws IOException { - Path p = getTestRootPath(fc, "test/nonExistent"); - fc.create(p, EnumSet.of(CREATE, APPEND, OVERWRITE)); - Assert.fail("Excepted exception not thrown"); + assertThrows(HadoopIllegalArgumentException.class, () -> { + Path p = getTestRootPath(fc, "test/nonExistent"); + fc.create(p, EnumSet.of(CREATE, APPEND, OVERWRITE)); + fail("Excepted exception not thrown"); + }); } @Test @@ -906,26 +927,26 @@ private static void writeData(FileContext fc, Path p, FSDataOutputStream out, byte[] data, long expectedLen) throws IOException { out.write(data, 0, data.length); out.close(); - Assert.assertTrue("Exists", exists(fc, p)); - Assert.assertEquals("Length", expectedLen, fc.getFileStatus(p).getLen()); + assertTrue(exists(fc, p), "Exists"); + assertEquals(expectedLen, fc.getFileStatus(p).getLen(), "Length"); } @Test public void testWriteInNonExistentDirectory() throws IOException { Path path = getTestRootPath(fc, "test/hadoop/file"); - Assert.assertFalse("Parent doesn't exist", exists(fc, path.getParent())); + assertFalse(exists(fc, path.getParent()), "Parent doesn't exist"); createFile(path); - Assert.assertTrue("Exists", exists(fc, path)); - Assert.assertEquals("Length", data.length, fc.getFileStatus(path).getLen()); - Assert.assertTrue("Parent exists", exists(fc, path.getParent())); + assertTrue(exists(fc, path), "Exists"); + assertEquals(data.length, fc.getFileStatus(path).getLen(), "Length"); + assertTrue(exists(fc, path.getParent()), "Parent exists"); } @Test public void testDeleteNonExistentFile() throws IOException { Path path = getTestRootPath(fc, "test/hadoop/file"); - Assert.assertFalse("Doesn't exist", exists(fc, path)); - Assert.assertFalse("No deletion", fc.delete(path, true)); + assertFalse(exists(fc, path), "Doesn't exist"); + assertFalse(fc.delete(path, true), "No deletion"); } @Test @@ -937,33 +958,33 @@ public void testDeleteRecursively() throws IOException { createFile(file); fc.mkdir(subdir,FsPermission.getDefault(), true); - Assert.assertTrue("File exists", exists(fc, file)); - Assert.assertTrue("Dir exists", exists(fc, dir)); - Assert.assertTrue("Subdir exists", exists(fc, subdir)); + assertTrue(exists(fc, file), "File exists"); + assertTrue(exists(fc, dir), "Dir exists"); + assertTrue(exists(fc, subdir), "Subdir exists"); try { fc.delete(dir, false); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } - Assert.assertTrue("File still exists", exists(fc, file)); - Assert.assertTrue("Dir still exists", exists(fc, dir)); - Assert.assertTrue("Subdir still exists", exists(fc, subdir)); + assertTrue(exists(fc, file), "File still exists"); + assertTrue(exists(fc, dir), "Dir still exists"); + assertTrue(exists(fc, subdir), "Subdir still exists"); - Assert.assertTrue("Deleted", fc.delete(dir, true)); - Assert.assertFalse("File doesn't exist", exists(fc, file)); - Assert.assertFalse("Dir doesn't exist", exists(fc, dir)); - Assert.assertFalse("Subdir doesn't exist", exists(fc, subdir)); + assertTrue(fc.delete(dir, true), "Deleted"); + assertFalse(exists(fc, file), "File doesn't exist"); + assertFalse(exists(fc, dir), "Dir doesn't exist"); + assertFalse(exists(fc, subdir), "Subdir doesn't exist"); } @Test public void testDeleteEmptyDirectory() throws IOException { Path dir = getTestRootPath(fc, "test/hadoop"); fc.mkdir(dir, FsPermission.getDefault(), true); - Assert.assertTrue("Dir exists", exists(fc, dir)); - Assert.assertTrue("Deleted", fc.delete(dir, false)); - Assert.assertFalse("Dir doesn't exist", exists(fc, dir)); + assertTrue(exists(fc, dir), "Dir exists"); + assertTrue(fc.delete(dir, false), "Deleted"); + assertFalse(exists(fc, dir), "Dir doesn't exist"); } @Test @@ -973,16 +994,16 @@ public void testRenameNonExistentPath() throws Exception { Path dst = getTestRootPath(fc, "test/new/newpath"); try { rename(src, dst, false, false, Rename.NONE); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } try { rename(src, dst, false, false, Rename.OVERWRITE); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } } @@ -996,16 +1017,16 @@ public void testRenameFileToNonExistentDirectory() throws Exception { try { rename(src, dst, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } try { rename(src, dst, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } } @@ -1020,13 +1041,13 @@ public void testRenameFileToDestinationWithParentFile() throws Exception { try { rename(src, dst, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } try { rename(src, dst, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } } @@ -1049,16 +1070,16 @@ public void testRenameFileToItself() throws Exception { createFile(src); try { rename(src, src, true, true, Rename.NONE); - Assert.fail("Renamed file to itself"); + fail("Renamed file to itself"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Also fails with overwrite try { rename(src, src, true, true, Rename.OVERWRITE); - Assert.fail("Renamed file to itself"); + fail("Renamed file to itself"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } } @@ -1074,9 +1095,9 @@ public void testRenameFileAsExistingFile() throws Exception { // Fails without overwrite option try { rename(src, dst, true, true, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Succeeds with overwrite option @@ -1095,14 +1116,14 @@ public void testRenameFileAsExistingDirectory() throws Exception { // Fails without overwrite option try { rename(src, dst, true, true, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } // File cannot be renamed as directory try { rename(src, dst, true, true, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } } @@ -1114,16 +1135,16 @@ public void testRenameDirectoryToItself() throws Exception { fc.mkdir(src, FileContext.DEFAULT_PERM, true); try { rename(src, src, true, true, Rename.NONE); - Assert.fail("Renamed directory to itself"); + fail("Renamed directory to itself"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Also fails with overwrite try { rename(src, src, true, true, Rename.OVERWRITE); - Assert.fail("Renamed directory to itself"); + fail("Renamed directory to itself"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } } @@ -1137,16 +1158,16 @@ public void testRenameDirectoryToNonExistentParent() throws Exception { try { rename(src, dst, true, false, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } try { rename(src, dst, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { - Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); + assertTrue(unwrapException(e) instanceof FileNotFoundException); } } @@ -1169,14 +1190,14 @@ private void testRenameDirectoryAsNonExistentDirectory(Rename... options) throws fc.mkdir(dst.getParent(), FileContext.DEFAULT_PERM, true); rename(src, dst, false, true, options); - Assert.assertFalse("Nested file1 exists", - exists(fc, getTestRootPath(fc, "test/hadoop/dir/file1"))); - Assert.assertFalse("Nested file2 exists", - exists(fc, getTestRootPath(fc, "test/hadoop/dir/subdir/file2"))); - Assert.assertTrue("Renamed nested file1 exists", - exists(fc, getTestRootPath(fc, "test/new/newdir/file1"))); - Assert.assertTrue("Renamed nested exists", - exists(fc, getTestRootPath(fc, "test/new/newdir/subdir/file2"))); + assertFalse(exists(fc, getTestRootPath(fc, + "test/hadoop/dir/file1")), "Nested file1 exists"); + assertFalse(exists(fc, getTestRootPath(fc, + "test/hadoop/dir/subdir/file2")), "Nested file2 exists"); + assertTrue(exists(fc, getTestRootPath(fc, + "test/new/newdir/file1")), "Renamed nested file1 exists"); + assertTrue(exists(fc, getTestRootPath(fc, + "test/new/newdir/subdir/file2")), "Renamed nested exists"); } @Test @@ -1194,10 +1215,10 @@ public void testRenameDirectoryAsEmptyDirectory() throws Exception { // Fails without overwrite option try { rename(src, dst, true, true, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { // Expected (cannot over-write non-empty destination) - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Succeeds with the overwrite option rename(src, dst, false, true, Rename.OVERWRITE); @@ -1218,15 +1239,15 @@ public void testRenameDirectoryAsNonEmptyDirectory() throws Exception { // Fails without overwrite option try { rename(src, dst, true, true, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { // Expected (cannot over-write non-empty destination) - Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } // Fails even with the overwrite option try { rename(src, dst, true, true, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException ex) { // Expected (cannot over-write non-empty destination) } @@ -1243,13 +1264,13 @@ public void testRenameDirectoryAsFile() throws Exception { // Fails without overwrite option try { rename(src, dst, true, true, Rename.NONE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException e) { } // Directory cannot be renamed as existing file try { rename(src, dst, true, true, Rename.OVERWRITE); - Assert.fail("Expected exception was not thrown"); + fail("Expected exception was not thrown"); } catch (IOException ex) { } } @@ -1286,7 +1307,7 @@ public void testUnsupportedSymlink() throws IOException { if (!fc.getDefaultFileSystem().supportsSymlinks()) { try { fc.createSymlink(file, link, false); - Assert.fail("Created a symlink on a file system that "+ + fail("Created a symlink on a file system that "+ "does not support symlinks."); } catch (UnsupportedOperationException e) { // Expected @@ -1294,12 +1315,12 @@ public void testUnsupportedSymlink() throws IOException { createFile(file); try { fc.getLinkTarget(file); - Assert.fail("Got a link target on a file system that "+ + fail("Got a link target on a file system that "+ "does not support symlinks."); } catch (IOException e) { // Expected } - Assert.assertEquals(fc.getFileStatus(file), fc.getFileLinkStatus(file)); + assertEquals(fc.getFileStatus(file), fc.getFileLinkStatus(file)); } } @@ -1315,8 +1336,8 @@ protected void rename(Path src, Path dst, boolean srcExists, try { fc.rename(src, dst, options); } finally { - Assert.assertEquals("Source exists", srcExists, exists(fc, src)); - Assert.assertEquals("Destination exists", dstExists, exists(fc, dst)); + assertEquals(srcExists, exists(fc, src), "Source exists"); + assertEquals(dstExists, exists(fc, dst), "Destination exists"); } } @@ -1526,9 +1547,8 @@ public void testOpenFileApplyRead() throws Throwable { CompletableFuture readAllBytes = fc.openFile(path) .build() .thenApply(ContractTestUtils::readStream); - assertEquals("Wrong number of bytes read from stream", - data.length, - (long)readAllBytes.get()); + assertEquals(data.length, (long) readAllBytes.get(), + "Wrong number of bytes read from stream"); } @Test @@ -1539,8 +1559,7 @@ public void testOpenFileApplyAsyncRead() throws Throwable { CompletableFuture future = fc.openFile(path).build(); AtomicBoolean accepted = new AtomicBoolean(false); future.thenAcceptAsync(i -> accepted.set(true)).get(); - assertTrue("async accept operation not invoked", - accepted.get()); + assertTrue(accepted.get(), "async accept operation not invoked"); } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextTestHelper.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextTestHelper.java index b5307a4e27669..0a8ca784a7b44 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextTestHelper.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextTestHelper.java @@ -17,6 +17,10 @@ */ package org.apache.hadoop.fs; +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 java.io.DataInputStream; import java.io.IOException; import java.io.FileNotFoundException; @@ -26,7 +30,6 @@ import org.apache.hadoop.fs.Options.CreateOpts.BlockSize; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.Assert; /** * Helper class for unit tests. @@ -220,28 +223,28 @@ public enum fileType {isDir, isFile, isSymlink}; public static void checkFileStatus(FileContext aFc, String path, fileType expectedType) throws IOException { FileStatus s = aFc.getFileStatus(new Path(path)); - Assert.assertNotNull(s); + assertNotNull(s); if (expectedType == fileType.isDir) { - Assert.assertTrue(s.isDirectory()); + assertTrue(s.isDirectory()); } else if (expectedType == fileType.isFile) { - Assert.assertTrue(s.isFile()); + assertTrue(s.isFile()); } else if (expectedType == fileType.isSymlink) { - Assert.assertTrue(s.isSymlink()); + assertTrue(s.isSymlink()); } - Assert.assertEquals(aFc.makeQualified(new Path(path)), s.getPath()); + assertEquals(aFc.makeQualified(new Path(path)), s.getPath()); } public static void checkFileLinkStatus(FileContext aFc, String path, fileType expectedType) throws IOException { FileStatus s = aFc.getFileLinkStatus(new Path(path)); - Assert.assertNotNull(s); + assertNotNull(s); if (expectedType == fileType.isDir) { - Assert.assertTrue(s.isDirectory()); + assertTrue(s.isDirectory()); } else if (expectedType == fileType.isFile) { - Assert.assertTrue(s.isFile()); + assertTrue(s.isFile()); } else if (expectedType == fileType.isSymlink) { - Assert.assertTrue(s.isSymlink()); + assertTrue(s.isSymlink()); } - Assert.assertEquals(aFc.makeQualified(new Path(path)), s.getPath()); + assertEquals(aFc.makeQualified(new Path(path)), s.getPath()); } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextTestWrapper.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextTestWrapper.java index 0dd1e9aa3e0f7..e6efc265deb54 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextTestWrapper.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextTestWrapper.java @@ -17,6 +17,10 @@ */ package org.apache.hadoop.fs; +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 java.io.DataInputStream; import java.io.IOException; import java.io.FileNotFoundException; @@ -28,7 +32,6 @@ import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.security.AccessControlException; -import org.junit.Assert; /** * Helper class for unit tests. @@ -169,29 +172,29 @@ public FileStatus containsPath(String path, FileStatus[] dirList) public void checkFileStatus(String path, fileType expectedType) throws IOException { FileStatus s = fc.getFileStatus(new Path(path)); - Assert.assertNotNull(s); + assertNotNull(s); if (expectedType == fileType.isDir) { - Assert.assertTrue(s.isDirectory()); + assertTrue(s.isDirectory()); } else if (expectedType == fileType.isFile) { - Assert.assertTrue(s.isFile()); + assertTrue(s.isFile()); } else if (expectedType == fileType.isSymlink) { - Assert.assertTrue(s.isSymlink()); + assertTrue(s.isSymlink()); } - Assert.assertEquals(fc.makeQualified(new Path(path)), s.getPath()); + assertEquals(fc.makeQualified(new Path(path)), s.getPath()); } public void checkFileLinkStatus(String path, fileType expectedType) throws IOException { FileStatus s = fc.getFileLinkStatus(new Path(path)); - Assert.assertNotNull(s); + assertNotNull(s); if (expectedType == fileType.isDir) { - Assert.assertTrue(s.isDirectory()); + assertTrue(s.isDirectory()); } else if (expectedType == fileType.isFile) { - Assert.assertTrue(s.isFile()); + assertTrue(s.isFile()); } else if (expectedType == fileType.isSymlink) { - Assert.assertTrue(s.isSymlink()); + assertTrue(s.isSymlink()); } - Assert.assertEquals(fc.makeQualified(new Path(path)), s.getPath()); + assertEquals(fc.makeQualified(new Path(path)), s.getPath()); } // diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextURIBase.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextURIBase.java index fad1e3774ad26..aa0c9f8b742e0 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextURIBase.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextURIBase.java @@ -23,16 +23,20 @@ import java.util.regex.Pattern; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.Assert; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.test.LambdaTestUtils; import org.apache.hadoop.util.Shell; -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 static org.apache.hadoop.fs.FileContextTestHelper.*; +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; /** *

@@ -71,10 +75,10 @@ protected Path qualifiedPath(String path, FileContext fc) { return fc.makeQualified(new Path(BASE, path)); } - @Before + @BeforeEach public void setUp() throws Exception { } - @After + @AfterEach public void tearDown() throws Exception { // Clean up after test completion // No need to clean fc1 as fc1 and fc2 points same location @@ -101,12 +105,12 @@ public void testCreateFile() throws IOException { // Create a file on fc2's file system using fc1 Path testPath = qualifiedPath(f, fc2); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Now create file createFile(fc1, testPath); // Ensure fc2 has the created file - Assert.assertTrue(exists(fc2, testPath)); + assertTrue(exists(fc2, testPath)); } } @@ -118,11 +122,11 @@ public void testCreateFileWithNullName() throws IOException { Path testPath = qualifiedPath(fileName, fc2); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Create a file on fc2's file system using fc1 createFile(fc1, testPath); - Assert.fail("Create file with null name should throw IllegalArgumentException."); + fail("Create file with null name should throw IllegalArgumentException."); } catch (IllegalArgumentException e) { // expected } @@ -135,7 +139,7 @@ public void testCreateExistingFile() throws Exception { Path testPath = qualifiedPath(fileName, fc2); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Create a file on fc2's file system using fc1 createFile(fc1, testPath); @@ -155,14 +159,14 @@ public void testCreateFileInNonExistingDirectory() throws IOException { Path testPath = qualifiedPath(fileName, fc2); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Create a file on fc2's file system using fc1 createFile(fc1, testPath); // Ensure using fc2 that file is created - Assert.assertTrue(isDir(fc2, testPath.getParent())); - Assert.assertEquals("testCreateFileInNonExistingDirectory", + assertTrue(isDir(fc2, testPath.getParent())); + assertEquals("testCreateFileInNonExistingDirectory", testPath.getParent().getName()); fc2.getFileStatus(testPath); @@ -176,17 +180,17 @@ public void testCreateDirectory() throws IOException { Path subDirPath = qualifiedPath("dir0", fc2); // Ensure that testPath does not exist in fc1 - Assert.assertFalse(exists(fc1, path)); - Assert.assertFalse(isFile(fc1, path)); - Assert.assertFalse(isDir(fc1, path)); + assertFalse(exists(fc1, path)); + assertFalse(isFile(fc1, path)); + assertFalse(isDir(fc1, path)); // Create a directory on fc2's file system using fc1 fc1.mkdir(path, FsPermission.getDefault(), true); // Ensure fc2 has directory - Assert.assertTrue(isDir(fc2, path)); - Assert.assertTrue(exists(fc2, path)); - Assert.assertFalse(isFile(fc2, path)); + assertTrue(isDir(fc2, path)); + assertTrue(exists(fc2, path)); + assertFalse(isFile(fc2, path)); // Test to create same dir twice, (HDFS mkdir is similar to mkdir -p ) fc1.mkdir(subDirPath, FsPermission.getDefault(), true); @@ -198,17 +202,17 @@ public void testCreateDirectory() throws IOException { // Check parent dir Path parentDir = path.getParent(); - Assert.assertTrue(exists(fc2, parentDir)); - Assert.assertFalse(isFile(fc2, parentDir)); + assertTrue(exists(fc2, parentDir)); + assertFalse(isFile(fc2, parentDir)); // Check parent parent dir Path grandparentDir = parentDir.getParent(); - Assert.assertTrue(exists(fc2, grandparentDir)); - Assert.assertFalse(isFile(fc2, grandparentDir)); + assertTrue(exists(fc2, grandparentDir)); + assertFalse(isFile(fc2, grandparentDir)); // Negative test cases - Assert.assertFalse(exists(fc2, falsePath)); - Assert.assertFalse(isDir(fc2, falsePath)); + assertFalse(exists(fc2, falsePath)); + assertFalse(isDir(fc2, falsePath)); // TestCase - Create multiple directories String dirNames[] = { @@ -227,27 +231,27 @@ public void testCreateDirectory() throws IOException { // Create a file on fc2's file system using fc1 Path testPath = qualifiedPath(f, fc2); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Now create directory fc1.mkdir(testPath, FsPermission.getDefault(), true); // Ensure fc2 has the created directory - Assert.assertTrue(exists(fc2, testPath)); - Assert.assertTrue(isDir(fc2, testPath)); + assertTrue(exists(fc2, testPath)); + assertTrue(isDir(fc2, testPath)); } // delete the parent directory and verify that the dir no longer exists final Path parent = qualifiedPath("createTest", fc2); fc2.delete(parent, true); - Assert.assertFalse(exists(fc2, parent)); + assertFalse(exists(fc2, parent)); } @Test public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception { Path testDir = qualifiedPath("test/hadoop", fc2); - Assert.assertFalse(exists(fc2, testDir)); + assertFalse(exists(fc2, testDir)); fc2.mkdir(testDir, FsPermission.getDefault(), true); - Assert.assertTrue(exists(fc2, testDir)); + assertTrue(exists(fc2, testDir)); // Create file on fc1 using fc2 context createFile(fc1, qualifiedPath("test/hadoop/file", fc2)); @@ -255,20 +259,20 @@ public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception { Path testSubDir = qualifiedPath("test/hadoop/file/subdir", fc2); try { fc1.mkdir(testSubDir, FsPermission.getDefault(), true); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } - Assert.assertFalse(exists(fc1, testSubDir)); + assertFalse(exists(fc1, testSubDir)); Path testDeepSubDir = qualifiedPath("test/hadoop/file/deep/sub/dir", fc1); try { fc2.mkdir(testDeepSubDir, FsPermission.getDefault(), true); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } - Assert.assertFalse(exists(fc1, testDeepSubDir)); + assertFalse(exists(fc1, testDeepSubDir)); } @@ -286,11 +290,11 @@ public void testIsDirectory() throws IOException { fc1.mkdir(existingPath, FsPermission.getDefault(), true); // Ensure fc2 has directory - Assert.assertTrue(isDir(fc2, existingPath)); - Assert.assertTrue(isDir(fc2, pathToRootDir)); + assertTrue(isDir(fc2, existingPath)); + assertTrue(isDir(fc2, pathToRootDir)); // Negative test case - Assert.assertFalse(isDir(fc2, nonExistingPath)); + assertFalse(isDir(fc2, nonExistingPath)); } @@ -299,19 +303,19 @@ public void testDeleteFile() throws IOException { Path testPath = qualifiedPath("testDeleteFile", fc2); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // First create a file on file system using fc1 createFile(fc1, testPath); // Ensure file exist - Assert.assertTrue(exists(fc2, testPath)); + assertTrue(exists(fc2, testPath)); // Delete file using fc2 fc2.delete(testPath, false); // Ensure fc2 does not have deleted file - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); } @@ -322,23 +326,23 @@ public void testDeleteNonExistingFile() throws IOException { // TestCase1 : Test delete on file never existed // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Delete on non existing file should return false - Assert.assertFalse(fc2.delete(testPath, false)); + assertFalse(fc2.delete(testPath, false)); // TestCase2 : Create , Delete , Delete file // Create a file on fc2's file system using fc1 createFile(fc1, testPath); // Ensure file exist - Assert.assertTrue(exists(fc2, testPath)); + assertTrue(exists(fc2, testPath)); // Delete test file, deleting existing file should return true - Assert.assertTrue(fc2.delete(testPath, false)); + assertTrue(fc2.delete(testPath, false)); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Delete on non existing file should return false - Assert.assertFalse(fc2.delete(testPath, false)); + assertFalse(fc2.delete(testPath, false)); } @@ -349,23 +353,23 @@ public void testDeleteNonExistingFileInDir() throws IOException { // TestCase1 : Test delete on file never existed // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Delete on non existing file should return false - Assert.assertFalse(fc2.delete(testPath, false)); + assertFalse(fc2.delete(testPath, false)); // TestCase2 : Create , Delete , Delete file // Create a file on fc2's file system using fc1 createFile(fc1, testPath); // Ensure file exist - Assert.assertTrue(exists(fc2, testPath)); + assertTrue(exists(fc2, testPath)); // Delete test file, deleting existing file should return true - Assert.assertTrue(fc2.delete(testPath, false)); + assertTrue(fc2.delete(testPath, false)); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Delete on non existing file should return false - Assert.assertFalse(fc2.delete(testPath, false)); + assertFalse(fc2.delete(testPath, false)); } @@ -374,19 +378,19 @@ public void testDeleteDirectory() throws IOException { String dirName = "dirTest"; Path testDirPath = qualifiedPath(dirName, fc2); // Ensure directory does not exist - Assert.assertFalse(exists(fc2, testDirPath)); + assertFalse(exists(fc2, testDirPath)); // Create a directory on fc2's file system using fc1 fc1.mkdir(testDirPath, FsPermission.getDefault(), true); // Ensure dir is created - Assert.assertTrue(exists(fc2, testDirPath)); - Assert.assertTrue(isDir(fc2, testDirPath)); + assertTrue(exists(fc2, testDirPath)); + assertTrue(isDir(fc2, testDirPath)); fc2.delete(testDirPath, true); // Ensure that directory is deleted - Assert.assertFalse(isDir(fc2, testDirPath)); + assertFalse(isDir(fc2, testDirPath)); // TestCase - Create and delete multiple directories String dirNames[] = { @@ -406,18 +410,18 @@ public void testDeleteDirectory() throws IOException { // Create a file on fc2's file system using fc1 Path testPath = qualifiedPath(f, fc2); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Now create directory fc1.mkdir(testPath, FsPermission.getDefault(), true); // Ensure fc2 has the created directory - Assert.assertTrue(exists(fc2, testPath)); - Assert.assertTrue(isDir(fc2, testPath)); + assertTrue(exists(fc2, testPath)); + assertTrue(isDir(fc2, testPath)); // Delete dir - Assert.assertTrue(fc2.delete(testPath, true)); + assertTrue(fc2.delete(testPath, true)); // verify if directory is deleted - Assert.assertFalse(exists(fc2, testPath)); - Assert.assertFalse(isDir(fc2, testPath)); + assertFalse(exists(fc2, testPath)); + assertFalse(isDir(fc2, testPath)); } } @@ -428,24 +432,24 @@ public void testDeleteNonExistingDirectory() throws IOException { // TestCase1 : Test delete on directory never existed // Ensure directory does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Delete on non existing directory should return false - Assert.assertFalse(fc2.delete(testPath, false)); + assertFalse(fc2.delete(testPath, false)); // TestCase2 : Create dir, Delete dir, Delete dir // Create a file on fc2's file system using fc1 fc1.mkdir(testPath, FsPermission.getDefault(), true); // Ensure dir exist - Assert.assertTrue(exists(fc2, testPath)); + assertTrue(exists(fc2, testPath)); // Delete test file, deleting existing file should return true - Assert.assertTrue(fc2.delete(testPath, false)); + assertTrue(fc2.delete(testPath, false)); // Ensure file does not exist - Assert.assertFalse(exists(fc2, testPath)); + assertFalse(exists(fc2, testPath)); // Delete on non existing file should return false - Assert.assertFalse(fc2.delete(testPath, false)); + assertFalse(fc2.delete(testPath, false)); } @Test @@ -461,7 +465,7 @@ public void testModificationTime() throws IOException { fc1ModificationTime = fc1.getFileStatus(testPath).getModificationTime(); fc2ModificationTime = fc2.getFileStatus(testPath).getModificationTime(); // Ensure fc1 and fc2 reports same modification time - Assert.assertEquals(fc1ModificationTime, fc2ModificationTime); + assertEquals(fc1ModificationTime, fc2ModificationTime); } @Test @@ -474,10 +478,10 @@ public void testFileStatus() throws IOException { FsStatus fc2Status = fc2.getFsStatus(path2); // FsStatus , used, free and capacity are non-negative longs - Assert.assertNotNull(fc2Status); - Assert.assertTrue(fc2Status.getCapacity() > 0); - Assert.assertTrue(fc2Status.getRemaining() > 0); - Assert.assertTrue(fc2Status.getUsed() > 0); + assertNotNull(fc2Status); + assertTrue(fc2Status.getCapacity() > 0); + assertTrue(fc2Status.getRemaining() > 0); + assertTrue(fc2Status.getUsed() > 0); } @@ -488,7 +492,7 @@ public void testGetFileStatusThrowsExceptionForNonExistentFile() Path testPath = qualifiedPath(testFile, fc2); try { fc1.getFileStatus(testPath); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (FileNotFoundException e) { // expected } @@ -501,7 +505,7 @@ public void testListStatusThrowsExceptionForNonExistentFile() Path testPath = qualifiedPath(testFile, fc2); try { fc1.listStatus(testPath); - Assert.fail("Should throw FileNotFoundException"); + fail("Should throw FileNotFoundException"); } catch (FileNotFoundException fnfe) { // expected } @@ -527,7 +531,7 @@ public void testListStatus() throws Exception { testDirs.add(qualifiedPath(d, fc2)); } - Assert.assertFalse(exists(fc1, testDirs.get(0))); + assertFalse(exists(fc1, testDirs.get(0))); for (Path path : testDirs) { fc1.mkdir(path, FsPermission.getDefault(), true); @@ -535,11 +539,11 @@ public void testListStatus() throws Exception { // test listStatus that returns an array of FileStatus FileStatus[] paths = fc1.util().listStatus(qualifiedPath("test", fc1)); - Assert.assertEquals(1, paths.length); - Assert.assertEquals(qualifiedPath(hPrefix, fc1), paths[0].getPath()); + assertEquals(1, paths.length); + assertEquals(qualifiedPath(hPrefix, fc1), paths[0].getPath()); paths = fc1.util().listStatus(qualifiedPath(hPrefix, fc1)); - Assert.assertEquals(testDirs.size(), paths.length); + assertEquals(testDirs.size(), paths.length); for (int i = 0; i < testDirs.size(); i++) { boolean found = false; for (int j = 0; j < paths.length; j++) { @@ -549,17 +553,17 @@ public void testListStatus() throws Exception { found = true; } } - Assert.assertTrue(testDirs.get(i) + " not found", found); + assertTrue(found, testDirs.get(i) + " not found"); } paths = fc1.util().listStatus(qualifiedPath(dirs[0], fc1)); - Assert.assertEquals(0, paths.length); + assertEquals(0, paths.length); // test listStatus that returns an iterator of FileStatus RemoteIterator pathsItor = fc1.listStatus(qualifiedPath("test", fc1)); - Assert.assertEquals(qualifiedPath(hPrefix, fc1), pathsItor.next().getPath()); - Assert.assertFalse(pathsItor.hasNext()); + assertEquals(qualifiedPath(hPrefix, fc1), pathsItor.next().getPath()); + assertFalse(pathsItor.hasNext()); pathsItor = fc1.listStatus(qualifiedPath(hPrefix, fc1)); int dirLen = 0; @@ -572,12 +576,12 @@ public void testListStatus() throws Exception { break; } } - Assert.assertTrue(stat.getPath() + " not found", found); + assertTrue(found, stat.getPath() + " not found"); } - Assert.assertEquals(testDirs.size(), dirLen); + assertEquals(testDirs.size(), dirLen); pathsItor = fc1.listStatus(qualifiedPath(dirs[0], fc1)); - Assert.assertFalse(pathsItor.hasNext()); + assertFalse(pathsItor.hasNext()); } /** diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/SymlinkBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/SymlinkBaseTest.java index 90e8c90c7ba1b..f0e42a9481ced 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/SymlinkBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/SymlinkBaseTest.java @@ -26,11 +26,15 @@ import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.test.GenericTestUtils; -import static org.junit.Assert.*; -import static org.junit.Assume.assumeTrue; -import org.junit.Test; -import org.junit.Before; -import org.junit.After; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; /** * Base test for symbolic links @@ -75,25 +79,27 @@ protected static void appendToFile(Path p) throws IOException { CreateOpts.blockSize(blockSize)); } - @Before + @BeforeEach public void setUp() throws Exception { wrapper.mkdir(new Path(testBaseDir1()), FileContext.DEFAULT_PERM, true); wrapper.mkdir(new Path(testBaseDir2()), FileContext.DEFAULT_PERM, true); } - @After + @AfterEach public void tearDown() throws Exception { wrapper.delete(new Path(testBaseDir1()), true); wrapper.delete(new Path(testBaseDir2()), true); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** The root is not a symlink */ public void testStatRoot() throws IOException { assertFalse(wrapper.getFileLinkStatus(new Path("/")).isSymlink()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test setWorkingDirectory not resolves symlinks */ public void testSetWDNotResolvesLinks() throws IOException { Path dir = new Path(testBaseDir1()); @@ -103,7 +109,8 @@ public void testSetWDNotResolvesLinks() throws IOException { assertEquals(linkToDir.getName(), wrapper.getWorkingDirectory().getName()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create a dangling link */ public void testCreateDanglingLink() throws IOException { Path file = new Path("/noSuchFile"); @@ -118,7 +125,8 @@ public void testCreateDanglingLink() throws IOException { wrapper.delete(link, false); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create a link to null and empty path */ public void testCreateLinkToNullEmpty() throws IOException { Path link = new Path(testBaseDir1()+"/link"); @@ -136,7 +144,8 @@ public void testCreateLinkToNullEmpty() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Create a link with createParent set */ public void testCreateLinkCanCreateParent() throws IOException { Path file = new Path(testBaseDir1()+"/file"); @@ -154,7 +163,8 @@ public void testCreateLinkCanCreateParent() throws IOException { readFile(link); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Try to create a directory given a path that refers to a symlink */ public void testMkdirExistingLink() throws IOException { Path file = new Path(testBaseDir1() + "/targetFile"); @@ -173,7 +183,8 @@ public void testMkdirExistingLink() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Try to create a file with parent that is a dangling link */ public void testCreateFileViaDanglingLinkParent() throws IOException { Path dir = new Path(testBaseDir1()+"/dangling"); @@ -191,7 +202,8 @@ public void testCreateFileViaDanglingLinkParent() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Delete a link */ public void testDeleteLink() throws IOException { Path file = new Path(testBaseDir1()+"/file"); @@ -210,7 +222,8 @@ public void testDeleteLink() throws IOException { wrapper.createSymlink(file, link, false); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Ensure open resolves symlinks */ public void testOpenResolvesLinks() throws IOException { Path file = new Path(testBaseDir1()+"/noSuchFile"); @@ -225,7 +238,8 @@ public void testOpenResolvesLinks() throws IOException { wrapper.delete(link, false); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Stat a link to a file */ public void testStatLinkToFile() throws IOException { Path file = new Path(testBaseDir1()+"/file"); @@ -249,7 +263,8 @@ public void testStatLinkToFile() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Stat a relative link to a file */ public void testStatRelLinkToFile() throws IOException { assumeTrue(!"file".equals(getScheme())); @@ -265,7 +280,8 @@ public void testStatRelLinkToFile() throws IOException { wrapper.getFileLinkStatus(linkToFile).getPath()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Stat a link to a directory */ public void testStatLinkToDir() throws IOException { Path dir = new Path(testBaseDir1()); @@ -283,7 +299,8 @@ public void testStatLinkToDir() throws IOException { assertEquals(dir, wrapper.getLinkTarget(linkToDir)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Stat a dangling link */ public void testStatDanglingLink() throws IOException { Path file = new Path("/noSuchFile"); @@ -293,7 +310,8 @@ public void testStatDanglingLink() throws IOException { assertTrue(wrapper.getFileLinkStatus(link).isSymlink()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Stat a non-existant file */ public void testStatNonExistentFiles() throws IOException { Path fileAbs = new Path("/doesNotExist"); @@ -311,7 +329,8 @@ public void testStatNonExistentFiles() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test stat'ing a regular file and directory */ public void testStatNonLinks() throws IOException { Path dir = new Path(testBaseDir1()); @@ -331,7 +350,8 @@ public void testStatNonLinks() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test links that link to each other */ public void testRecursiveLinks() throws IOException { Path link1 = new Path(testBaseDir1()+"/link1"); @@ -420,7 +440,8 @@ else if (wrapper instanceof FileSystemTestWrapper) { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test creating a symlink using relative paths */ public void testCreateLinkUsingRelPaths() throws IOException { Path fileAbs = new Path(testBaseDir1(), "file"); @@ -446,7 +467,8 @@ public void testCreateLinkUsingRelPaths() throws IOException { readFile(linkViaDir2); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test creating a symlink using absolute paths */ public void testCreateLinkUsingAbsPaths() throws IOException { Path fileAbs = new Path(testBaseDir1()+"/file"); @@ -473,7 +495,8 @@ public void testCreateLinkUsingAbsPaths() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** * Test creating a symlink using fully and partially qualified paths. * NB: For local fs this actually tests partially qualified paths, @@ -506,7 +529,8 @@ public void testCreateLinkUsingFullyQualPaths() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** * Test creating a symlink using partially qualified paths, ie a scheme * but no authority and vice versa. We just test link targets here since @@ -549,7 +573,8 @@ public void testCreateLinkUsingPartQualPath1() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Same as above but vice versa (authority but no scheme) */ public void testCreateLinkUsingPartQualPath2() throws IOException { Path link = new Path(testBaseDir1(), "linkToFile"); @@ -577,7 +602,8 @@ public void testCreateLinkUsingPartQualPath2() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Lstat and readlink on a normal file and directory */ public void testLinkStatusAndTargetWithNonLink() throws IOException { Path schemeAuth = new Path(testURI().toString()); @@ -602,7 +628,8 @@ public void testLinkStatusAndTargetWithNonLink() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create symlink to a directory */ public void testCreateLinkToDirectory() throws IOException { Path dir1 = new Path(testBaseDir1()); @@ -616,7 +643,8 @@ public void testCreateLinkToDirectory() throws IOException { assertTrue(wrapper.getFileLinkStatus(linkToDir).isSymlink()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create and remove a file through a symlink */ public void testCreateFileViaSymlink() throws IOException { Path dir = new Path(testBaseDir1()); @@ -633,7 +661,8 @@ public void testCreateFileViaSymlink() throws IOException { assertFalse(wrapper.exists(fileViaLink)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test make and delete directory through a symlink */ public void testCreateDirViaSymlink() throws IOException { Path dir1 = new Path(testBaseDir1()); @@ -648,7 +677,8 @@ public void testCreateDirViaSymlink() throws IOException { assertFalse(wrapper.exists(subDir)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Create symlink through a symlink */ public void testCreateLinkViaLink() throws IOException { Path dir1 = new Path(testBaseDir1()); @@ -670,7 +700,8 @@ public void testCreateLinkViaLink() throws IOException { assertEquals(fileViaLink, wrapper.getLinkTarget(linkToFile)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create symlink to a directory */ public void testListStatusUsingLink() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -690,7 +721,8 @@ public void testListStatusUsingLink() throws IOException { assertTrue(dirLen == 2 || dirLen == 3); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create symlink using the same path */ public void testCreateLinkTwice() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -705,7 +737,8 @@ public void testCreateLinkTwice() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test access via a symlink to a symlink */ public void testCreateLinkToLink() throws IOException { Path dir1 = new Path(testBaseDir1()); @@ -723,7 +756,8 @@ public void testCreateLinkToLink() throws IOException { readFile(fileViaLink); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Can not create a file with path that refers to a symlink */ public void testCreateFileDirExistingLink() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -744,7 +778,8 @@ public void testCreateFileDirExistingLink() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test deleting and recreating a symlink */ public void testUseLinkAferDeleteLink() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -763,7 +798,8 @@ public void testUseLinkAferDeleteLink() throws IOException { readFile(link); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create symlink to . */ public void testCreateLinkToDot() throws IOException { Path dir = new Path(testBaseDir1()); @@ -780,7 +816,8 @@ public void testCreateLinkToDot() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create symlink to .. */ public void testCreateLinkToDotDot() throws IOException { Path file = new Path(testBaseDir1(), "test/file"); @@ -795,7 +832,8 @@ public void testCreateLinkToDotDot() throws IOException { assertEquals(fileSize, wrapper.getFileStatus(fileViaLink).getLen()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create symlink to ../file */ public void testCreateLinkToDotDotPrefix() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -809,7 +847,8 @@ public void testCreateLinkToDotDotPrefix() throws IOException { assertEquals(new Path("../file"), wrapper.getLinkTarget(link)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename file using a path that contains a symlink. The rename should * work as if the path did not contain a symlink */ public void testRenameFileViaSymlink() throws IOException { @@ -826,7 +865,8 @@ public void testRenameFileViaSymlink() throws IOException { assertTrue(wrapper.exists(fileNewViaLink)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename a file through a symlink but this time only the * destination path has an intermediate symlink. The rename should work * as if the path did not contain a symlink */ @@ -848,7 +888,8 @@ public void testRenameFileToDestViaSymlink() throws IOException { assertTrue(wrapper.exists(file)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Similar tests as the previous ones but rename a directory */ public void testRenameDirViaSymlink() throws IOException { Path baseDir = new Path(testBaseDir1()); @@ -865,7 +906,8 @@ public void testRenameDirViaSymlink() throws IOException { assertTrue(wrapper.exists(dirNewViaLink)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Similar tests as the previous ones but rename a symlink */ public void testRenameSymlinkViaSymlink() throws IOException { Path baseDir = new Path(testBaseDir1()); @@ -885,7 +927,8 @@ public void testRenameSymlinkViaSymlink() throws IOException { readFile(linkNewViaLink); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename a directory to a symlink to a directory */ public void testRenameDirToSymlinkToDir() throws IOException { Path dir1 = new Path(testBaseDir1()); @@ -904,7 +947,8 @@ public void testRenameDirToSymlinkToDir() throws IOException { assertTrue(wrapper.exists(linkToDir)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename a directory to a symlink to a file */ public void testRenameDirToSymlinkToFile() throws IOException { Path dir1 = new Path(testBaseDir1()); @@ -923,7 +967,8 @@ public void testRenameDirToSymlinkToFile() throws IOException { assertTrue(wrapper.exists(linkToFile)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename a directory to a dangling symlink */ public void testRenameDirToDanglingSymlink() throws IOException { Path dir = new Path(testBaseDir1()); @@ -940,7 +985,8 @@ public void testRenameDirToDanglingSymlink() throws IOException { assertTrue(wrapper.getFileLinkStatus(link) != null); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename a file to a symlink to a directory */ public void testRenameFileToSymlinkToDir() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -963,7 +1009,8 @@ public void testRenameFileToSymlinkToDir() throws IOException { assertFalse(wrapper.getFileLinkStatus(link).isSymlink()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename a file to a symlink to a file */ public void testRenameFileToSymlinkToFile() throws IOException { Path file1 = new Path(testBaseDir1(), "file1"); @@ -986,7 +1033,8 @@ public void testRenameFileToSymlinkToFile() throws IOException { assertFalse(wrapper.getFileLinkStatus(link).isSymlink()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename a file to a dangling symlink */ public void testRenameFileToDanglingSymlink() throws IOException { /* NB: Local file system doesn't handle dangling links correctly @@ -1010,7 +1058,8 @@ public void testRenameFileToDanglingSymlink() throws IOException { assertFalse(wrapper.getFileLinkStatus(link).isSymlink()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Rename a symlink to a new non-existant name */ public void testRenameSymlinkNonExistantDest() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -1025,7 +1074,8 @@ public void testRenameSymlinkNonExistantDest() throws IOException { assertFalse(wrapper.exists(link1)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Rename a symlink to a file that exists */ public void testRenameSymlinkToExistingFile() throws IOException { Path file1 = new Path(testBaseDir1(), "file"); @@ -1047,7 +1097,8 @@ public void testRenameSymlinkToExistingFile() throws IOException { assertEquals(file2, wrapper.getLinkTarget(file1)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Rename a symlink to a directory that exists */ public void testRenameSymlinkToExistingDir() throws IOException { Path dir1 = new Path(testBaseDir1()); @@ -1080,7 +1131,8 @@ public void testRenameSymlinkToExistingDir() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Rename a symlink to itself */ public void testRenameSymlinkToItself() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -1103,7 +1155,8 @@ public void testRenameSymlinkToItself() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Rename a symlink */ public void testRenameSymlink() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -1124,7 +1177,8 @@ public void testRenameSymlink() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Rename a symlink to the file it links to */ public void testRenameSymlinkToFileItLinksTo() throws IOException { /* NB: The rename is not atomic, so file is deleted before renaming @@ -1162,7 +1216,8 @@ public void testRenameSymlinkToFileItLinksTo() throws IOException { assertEquals(file, wrapper.getLinkTarget(link)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Rename a symlink to the directory it links to */ public void testRenameSymlinkToDirItLinksTo() throws IOException { /* NB: The rename is not atomic, so dir is deleted before renaming @@ -1200,7 +1255,8 @@ public void testRenameSymlinkToDirItLinksTo() throws IOException { assertEquals(dir, wrapper.getLinkTarget(link)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename the symlink's target */ public void testRenameLinkTarget() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -1219,7 +1275,8 @@ public void testRenameLinkTarget() throws IOException { readFile(link); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test rename a file to path with destination that has symlink parent */ public void testRenameFileWithDestParentSymlink() throws IOException { Path link = new Path(testBaseDir1(), "link"); @@ -1257,7 +1314,8 @@ public void testRenameFileWithDestParentSymlink() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** * Create, write, read, append, rename, get the block locations, * checksums, and delete a file using a path with a symlink as an @@ -1296,7 +1354,8 @@ public void testAccessFileViaInterSymlinkAbsTarget() throws IOException { assertFalse(wrapper.exists(fileNewViaLink)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** * Operate on a file using a path with an intermediate symlink where * the link target was specified as a fully qualified path. @@ -1315,7 +1374,8 @@ public void testAccessFileViaInterSymlinkQualTarget() throws IOException { readFile(fileViaLink); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** * Operate on a file using a path with an intermediate symlink where * the link target was specified as a relative path. @@ -1345,7 +1405,8 @@ public void testAccessFileViaInterSymlinkRelTarget() throws IOException { wrapper.getFileLinkStatus(file)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create, list, and delete a directory through a symlink */ public void testAccessDirViaSymlink() throws IOException { Path baseDir = new Path(testBaseDir1()); @@ -1364,7 +1425,8 @@ public void testAccessDirViaSymlink() throws IOException { assertFalse(wrapper.exists(dir)); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** setTimes affects the target file not the link */ public void testSetTimesSymlinkToFile() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -1374,13 +1436,14 @@ public void testSetTimesSymlinkToFile() throws IOException { long at = wrapper.getFileLinkStatus(link).getAccessTime(); // the local file system may not support millisecond timestamps wrapper.setTimes(link, 2000L, 3000L); - assertTrue("The atime of symlink should not be lesser after setTimes()", - wrapper.getFileLinkStatus(link).getAccessTime() >= at); + assertTrue(wrapper.getFileLinkStatus(link).getAccessTime() >= at, + "The atime of symlink should not be lesser after setTimes()"); assertEquals(2000, wrapper.getFileStatus(file).getModificationTime()); assertEquals(3000, wrapper.getFileStatus(file).getAccessTime()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** setTimes affects the target directory not the link */ public void testSetTimesSymlinkToDir() throws IOException { Path dir = new Path(testBaseDir1(), "dir"); @@ -1390,13 +1453,14 @@ public void testSetTimesSymlinkToDir() throws IOException { long at = wrapper.getFileLinkStatus(link).getAccessTime(); // the local file system may not support millisecond timestamps wrapper.setTimes(link, 2000L, 3000L); - assertTrue("The atime of symlink should not be lesser after setTimes()", - wrapper.getFileLinkStatus(link).getAccessTime() >= at); + assertTrue(wrapper.getFileLinkStatus(link).getAccessTime() >= at, + "The atime of symlink should not be lesser after setTimes()"); assertEquals(2000, wrapper.getFileStatus(dir).getModificationTime()); assertEquals(3000, wrapper.getFileStatus(dir).getAccessTime()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** setTimes does not affect the link even though target does not exist */ public void testSetTimesDanglingLink() throws IOException { Path file = new Path("/noSuchFile"); @@ -1409,7 +1473,7 @@ public void testSetTimesDanglingLink() throws IOException { } catch (IOException e) { // Expected } - assertTrue("The atime of symlink should not be lesser after setTimes()", - wrapper.getFileLinkStatus(link).getAccessTime() >= at); + assertTrue(wrapper.getFileLinkStatus(link).getAccessTime() >= at, + "The atime of symlink should not be lesser after setTimes()"); } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFSFileContextCreateMkdir.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFSFileContextCreateMkdir.java index f5decbb2b0c92..7bb66c4b23cf6 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFSFileContextCreateMkdir.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFSFileContextCreateMkdir.java @@ -18,13 +18,13 @@ package org.apache.hadoop.fs; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class TestLocalFSFileContextCreateMkdir extends FileContextCreateMkdirBaseTest { @Override - @Before + @BeforeEach public void setUp() throws Exception { fc = FileContext.getLocalFSFileContext(); super.setUp(); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFSFileContextMainOperations.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFSFileContextMainOperations.java index 493131c06a92e..2c2a6d17b1836 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFSFileContextMainOperations.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFSFileContextMainOperations.java @@ -17,20 +17,21 @@ */ package org.apache.hadoop.fs; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.apache.hadoop.fs.FileContextTestHelper; import org.apache.hadoop.fs.permission.FsPermission; public class TestLocalFSFileContextMainOperations extends FileContextMainOperationsBaseTest { @Override - @Before + @BeforeEach public void setUp() throws Exception { fc = FileContext.getLocalFSFileContext(); super.setUp(); @@ -47,7 +48,7 @@ protected Path getDefaultWorkingDirectory() throws IOException { @Test public void testFileContextNoCache() throws UnsupportedFileSystemException { FileContext fc1 = FileContext.getLocalFSFileContext(); - Assert.assertTrue(fc1 != fc); + assertTrue(fc1 != fc); } @Override @@ -61,7 +62,7 @@ public void testDefaultFilePermission() throws IOException { "testDefaultFilePermission"); FileContextTestHelper.createFile(fc, file); FsPermission expect = FileContext.FILE_DEFAULT_PERM.applyUMask(fc.getUMask()); - Assert.assertEquals(expect, fc.getFileStatus(file) + assertEquals(expect, fc.getFileStatus(file) .getPermission()); } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFsFCStatistics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFsFCStatistics.java index fe26f73a2e8d0..5c258baf4b37d 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFsFCStatistics.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFsFCStatistics.java @@ -18,12 +18,13 @@ package org.apache.hadoop.fs; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.net.URI; import org.apache.hadoop.fs.FileSystem.Statistics; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; /** *

@@ -34,13 +35,13 @@ public class TestLocalFsFCStatistics extends FCStatisticsBaseTest { static final String LOCAL_FS_ROOT_URI = "file:///tmp/test"; - @Before + @BeforeEach public void setUp() throws Exception { fc = FileContext.getLocalFSFileContext(); fc.mkdir(fileContextTestHelper.getTestRootPath(fc, "test"), FileContext.DEFAULT_PERM, true); } - @After + @AfterEach public void tearDown() throws Exception { fc.delete(fileContextTestHelper.getTestRootPath(fc, "test"), true); } @@ -48,13 +49,13 @@ public void tearDown() throws Exception { @Override protected void verifyReadBytes(Statistics stats) { // one blockSize for read, one for pread - Assert.assertEquals(2*blockSize, stats.getBytesRead()); + assertEquals(2*blockSize, stats.getBytesRead()); } @Override protected void verifyWrittenBytes(Statistics stats) { //Extra 12 bytes are written apart from the block. - Assert.assertEquals(blockSize + 12, stats.getBytesWritten()); + assertEquals(blockSize + 12, stats.getBytesWritten()); } @Override diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFS.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFS.java index 45d63b11b07f9..4435aeee2d5e3 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFS.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFS.java @@ -18,10 +18,10 @@ package org.apache.hadoop.fs; import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.Assume.assumeTrue; import java.io.File; @@ -32,7 +32,8 @@ import org.apache.hadoop.util.Shell; import org.apache.hadoop.security.UserGroupInformation; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; /** * Test symbolic links using LocalFs. @@ -105,7 +106,8 @@ public void testStatDanglingLink() throws IOException { super.testStatDanglingLink(); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** lstat a non-existant file using a partially qualified path */ public void testDanglingLinkFilePartQual() throws IOException { Path filePartQual = new Path(getScheme()+":///doesNotExist"); @@ -123,7 +125,8 @@ public void testDanglingLinkFilePartQual() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Stat and lstat a dangling link */ public void testDanglingLink() throws IOException { assumeNotWindows(); @@ -169,7 +172,8 @@ public void testDanglingLink() throws IOException { wrapper.getFileStatus(link); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** * Test getLinkTarget with a partially qualified target. * NB: Hadoop does not support fully qualified URIs for the diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFSFileContext.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFSFileContext.java index 301bf046cd257..a2a1d55ee7bed 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFSFileContext.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFSFileContext.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.fs; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import java.io.IOException; @@ -25,7 +25,7 @@ public class TestSymlinkLocalFSFileContext extends TestSymlinkLocalFS { - @BeforeClass + @BeforeAll public static void testSetup() throws Exception { FileContext context = FileContext.getLocalFSFileContext(); wrapper = new FileContextTestWrapper(context); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFSFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFSFileSystem.java index 98449493fa5e1..cec7c488d9703 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFSFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestSymlinkLocalFSFileSystem.java @@ -22,43 +22,48 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Options.Rename; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestSymlinkLocalFSFileSystem extends TestSymlinkLocalFS { - @BeforeClass + @BeforeAll public static void testSetup() throws Exception { FileSystem filesystem = FileSystem.getLocal(new Configuration()); wrapper = new FileSystemTestWrapper(filesystem); } - @Ignore("RawLocalFileSystem#mkdir does not treat existence of directory" + + @Disabled("RawLocalFileSystem#mkdir does not treat existence of directory" + " as an error") @Override - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testMkdirExistingLink() throws IOException {} - @Ignore("FileSystem#create defaults to creating parents," + + @Disabled("FileSystem#create defaults to creating parents," + " throwing an IOException instead of FileNotFoundException") @Override - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testCreateFileViaDanglingLinkParent() throws IOException {} - @Ignore("RawLocalFileSystem does not throw an exception if the path" + + @Disabled("RawLocalFileSystem does not throw an exception if the path" + " already exists") @Override - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testCreateFileDirExistingLink() throws IOException {} - @Ignore("ChecksumFileSystem does not support append") + @Disabled("ChecksumFileSystem does not support append") @Override - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testAccessFileViaInterSymlinkAbsTarget() throws IOException {} @Override @@ -68,7 +73,8 @@ public void testRenameFileWithDestParentSymlink() throws IOException { } @Override - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Rename a symlink to itself */ public void testRenameSymlinkToItself() throws IOException { Path file = new Path(testBaseDir1(), "file"); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java index fc0d74b649d0a..6d7a98a3b8148 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java @@ -17,18 +17,11 @@ */ package org.apache.hadoop.fs.viewfs; - - -import java.io.IOException; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSMainOperationsBaseTest; import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -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.BeforeEach; public class TestFSMainOperationsLocalFileSystem extends FSMainOperationsBaseTest { FileSystem fcTarget; @@ -40,7 +33,7 @@ protected FileSystem createFileSystem() throws Exception { } @Override - @Before + @BeforeEach public void setUp() throws Exception { Configuration conf = new Configuration(); fcTarget = FileSystem.getLocal(conf); @@ -48,7 +41,7 @@ public void setUp() throws Exception { } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); ViewFileSystemTestSetup.tearDown(this, fcTarget); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcCreateMkdirLocalFs.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcCreateMkdirLocalFs.java index 79217b3f42103..fac7e945c3c6d 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcCreateMkdirLocalFs.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcCreateMkdirLocalFs.java @@ -20,8 +20,8 @@ import org.apache.hadoop.fs.FileContextCreateMkdirBaseTest; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; public class TestFcCreateMkdirLocalFs extends @@ -29,14 +29,14 @@ public class TestFcCreateMkdirLocalFs extends @Override - @Before + @BeforeEach public void setUp() throws Exception { fc = ViewFsTestSetup.setupForViewFsLocalFs(fileContextTestHelper); super.setUp(); } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcMainOperationsLocalFs.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcMainOperationsLocalFs.java index 64520e1ba2633..ef55b2f434274 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcMainOperationsLocalFs.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestFcMainOperationsLocalFs.java @@ -22,8 +22,8 @@ import org.apache.hadoop.fs.FileContextMainOperationsBaseTest; import org.apache.hadoop.fs.Path; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; public class TestFcMainOperationsLocalFs extends @@ -33,14 +33,14 @@ public class TestFcMainOperationsLocalFs extends Path targetOfTests; @Override - @Before + @BeforeEach public void setUp() throws Exception { fc = ViewFsTestSetup.setupForViewFsLocalFs(fileContextTestHelper); super.setUp(); } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsLocalFs.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsLocalFs.java index 99bcf5d32b72a..464b7c54cc6af 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsLocalFs.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsLocalFs.java @@ -20,14 +20,14 @@ import org.apache.hadoop.fs.FileContext; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; public class TestViewFsLocalFs extends ViewFsBaseTest { @Override - @Before + @BeforeEach public void setUp() throws Exception { // create the test root on local_fs fcTarget = FileContext.getLocalFSFileContext(); @@ -36,7 +36,7 @@ public void setUp() throws Exception { } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsWithAuthorityLocalFs.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsWithAuthorityLocalFs.java index fd5de72ed71ad..2734629e4ee56 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsWithAuthorityLocalFs.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFsWithAuthorityLocalFs.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.fs.viewfs; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.URI; @@ -24,10 +25,9 @@ import org.apache.hadoop.fs.FsConstants; import org.apache.hadoop.fs.Path; -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.BeforeEach; +import org.junit.jupiter.api.Test; /** * @@ -42,7 +42,7 @@ public class TestViewFsWithAuthorityLocalFs extends ViewFsBaseTest { URI schemeWithAuthority; @Override - @Before + @BeforeEach public void setUp() throws Exception { // create the test root on local_fs fcTarget = FileContext.getLocalFSFileContext(); @@ -55,7 +55,7 @@ public void setUp() throws Exception { } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); } @@ -63,16 +63,15 @@ public void tearDown() throws Exception { @Override @Test public void testBasicPaths() { - Assert.assertEquals(schemeWithAuthority, - fcView.getDefaultFileSystem().getUri()); - Assert.assertEquals(fcView.makeQualified( - new Path("/user/" + System.getProperty("user.name"))), - fcView.getWorkingDirectory()); - Assert.assertEquals(fcView.makeQualified( - new Path("/user/" + System.getProperty("user.name"))), - fcView.getHomeDirectory()); - Assert.assertEquals( - new Path("/foo/bar").makeQualified(schemeWithAuthority, null), - fcView.makeQualified(new Path("/foo/bar"))); + assertEquals(schemeWithAuthority, fcView.getDefaultFileSystem().getUri()); + assertEquals(fcView.makeQualified( + new Path("/user/" + System.getProperty("user.name"))), + fcView.getWorkingDirectory()); + assertEquals(fcView.makeQualified( + new Path("/user/" + System.getProperty("user.name"))), + fcView.getHomeDirectory()); + assertEquals( + new Path("/foo/bar").makeQualified(schemeWithAuthority, null), + fcView.makeQualified(new Path("/foo/bar"))); } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java index 1d855ab442600..a664b8f1ae761 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java @@ -17,15 +17,18 @@ */ package org.apache.hadoop.fs.viewfs; -import static org.assertj.core.api.Assertions.assertThat; import static org.apache.hadoop.fs.FileContextTestHelper.checkFileLinkStatus; import static org.apache.hadoop.fs.FileContextTestHelper.checkFileStatus; import static org.apache.hadoop.fs.FileContextTestHelper.exists; import static org.apache.hadoop.fs.FileContextTestHelper.isDir; import static org.apache.hadoop.fs.FileContextTestHelper.isFile; import static org.apache.hadoop.fs.viewfs.Constants.PERMISSION_555; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; +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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; @@ -71,10 +74,9 @@ import org.apache.hadoop.security.token.Token; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.LambdaTestUtils; -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.BeforeEach; +import org.junit.jupiter.api.Test; /** @@ -111,7 +113,7 @@ protected FileContextTestHelper createFileContextHelper() { return new FileContextTestHelper(); } - @Before + @BeforeEach public void setUp() throws Exception { initializeTargetTestRoot(); @@ -163,7 +165,7 @@ void initializeTargetTestRoot() throws IOException { fcTarget.mkdir(targetTestRoot, FileContext.DEFAULT_PERM, true); } - @After + @AfterEach public void tearDown() throws Exception { fcTarget.delete(fileContextTestHelper.getTestRootPath(fcTarget), true); } @@ -172,7 +174,7 @@ public void tearDown() throws Exception { public void testGetMountPoints() { ViewFs viewfs = (ViewFs) fcView.getDefaultFileSystem(); MountPoint[] mountPoints = viewfs.getMountPoints(); - Assert.assertEquals(8, mountPoints.length); + assertEquals(8, mountPoints.length); } int getExpectedDelegationTokenCount() { @@ -188,21 +190,21 @@ int getExpectedDelegationTokenCount() { public void testGetDelegationTokens() throws IOException { List> delTokens = fcView.getDelegationTokens(new Path("/"), "sanjay"); - Assert.assertEquals(getExpectedDelegationTokenCount(), delTokens.size()); + assertEquals(getExpectedDelegationTokenCount(), delTokens.size()); } @Test public void testBasicPaths() { - Assert.assertEquals(FsConstants.VIEWFS_URI, + assertEquals(FsConstants.VIEWFS_URI, fcView.getDefaultFileSystem().getUri()); - Assert.assertEquals(fcView.makeQualified( + assertEquals(fcView.makeQualified( new Path("/user/" + System.getProperty("user.name"))), fcView.getWorkingDirectory()); - Assert.assertEquals(fcView.makeQualified( + assertEquals(fcView.makeQualified( new Path("/user/" + System.getProperty("user.name"))), fcView.getHomeDirectory()); - Assert.assertEquals( + assertEquals( new Path("/foo/bar").makeQualified(FsConstants.VIEWFS_URI, null), fcView.makeQualified(new Path("/foo/bar"))); } @@ -220,118 +222,113 @@ public void testBasicPaths() { public void testOperationsThroughMountLinks() throws IOException { // Create file fileContextTestHelper.createFileNonRecursive(fcView, "/user/foo"); - Assert.assertTrue("Create file should be file", - isFile(fcView, new Path("/user/foo"))); - Assert.assertTrue("Target of created file should be type file", - isFile(fcTarget, new Path(targetTestRoot,"user/foo"))); + assertTrue(isFile(fcView, new Path("/user/foo")), + "Create file should be file"); + assertTrue(isFile(fcTarget, new Path(targetTestRoot, "user/foo")), + "Target of created file should be type file"); // Delete the created file - Assert.assertTrue("Delete should succeed", - fcView.delete(new Path("/user/foo"), false)); - Assert.assertFalse("File should not exist after delete", - exists(fcView, new Path("/user/foo"))); - Assert.assertFalse("Target File should not exist after delete", - exists(fcTarget, new Path(targetTestRoot,"user/foo"))); + assertTrue(fcView.delete(new Path("/user/foo"), false), + "Delete should succeed"); + assertFalse(exists(fcView, new Path("/user/foo")), "File should not exist after delete"); + assertFalse(exists(fcTarget, new Path(targetTestRoot, "user/foo")), + "Target File should not exist after delete"); // Create file with a 2 component dirs fileContextTestHelper.createFileNonRecursive(fcView, "/internalDir/linkToDir2/foo"); - Assert.assertTrue("Created file should be type file", - isFile(fcView, new Path("/internalDir/linkToDir2/foo"))); - Assert.assertTrue("Target of created file should be type file", - isFile(fcTarget, new Path(targetTestRoot,"dir2/foo"))); + assertTrue(isFile(fcView, new Path("/internalDir/linkToDir2/foo")), + "Created file should be type file"); + assertTrue(isFile(fcTarget, new Path(targetTestRoot, "dir2/foo")), + "Target of created file should be type file"); // Delete the created file - Assert.assertTrue("Delete should succeed", - fcView.delete(new Path("/internalDir/linkToDir2/foo"),false)); - Assert.assertFalse("File should not exist after deletion", - exists(fcView, new Path("/internalDir/linkToDir2/foo"))); - Assert.assertFalse("Target should not exist after deletion", - exists(fcTarget, new Path(targetTestRoot,"dir2/foo"))); + assertTrue(fcView.delete(new Path("/internalDir/linkToDir2/foo"), false), + "Delete should succeed"); + assertFalse(exists(fcView, new Path("/internalDir/linkToDir2/foo")), + "File should not exist after deletion"); + assertFalse(exists(fcTarget, new Path(targetTestRoot, "dir2/foo")), + "Target should not exist after deletion"); // Create file with a 3 component dirs fileContextTestHelper.createFileNonRecursive(fcView, "/internalDir/internalDir2/linkToDir3/foo"); - Assert.assertTrue("Created file should be of type file", - isFile(fcView, new Path("/internalDir/internalDir2/linkToDir3/foo"))); - Assert.assertTrue("Target of created file should also be type file", - isFile(fcTarget, new Path(targetTestRoot,"dir3/foo"))); + assertTrue(isFile(fcView, new Path("/internalDir/internalDir2/linkToDir3/foo")), + "Created file should be of type file"); + assertTrue(isFile(fcTarget, new Path(targetTestRoot, "dir3/foo")), + "Target of created file should also be type file"); // Recursive Create file with missing dirs fileContextTestHelper.createFile(fcView, "/internalDir/linkToDir2/missingDir/miss2/foo"); - Assert.assertTrue("Created file should be of type file", - isFile(fcView, new Path("/internalDir/linkToDir2/missingDir/miss2/foo"))); - Assert.assertTrue("Target of created file should also be type file", - isFile(fcTarget, new Path(targetTestRoot,"dir2/missingDir/miss2/foo"))); + assertTrue(isFile(fcView, new Path("/internalDir/linkToDir2/missingDir/miss2/foo")), + "Created file should be of type file"); + assertTrue(isFile(fcTarget, new Path(targetTestRoot, "dir2/missingDir/miss2/foo")), + "Target of created file should also be type file"); // Delete the created file - Assert.assertTrue("Delete should succeed", fcView.delete( - new Path("/internalDir/internalDir2/linkToDir3/foo"), false)); - Assert.assertFalse("Deleted File should not exist", - exists(fcView, new Path("/internalDir/internalDir2/linkToDir3/foo"))); - Assert.assertFalse("Target of deleted file should not exist", - exists(fcTarget, new Path(targetTestRoot,"dir3/foo"))); + assertTrue(fcView.delete(new Path("/internalDir/internalDir2/linkToDir3/foo"), false), + "Delete should succeed"); + assertFalse(exists(fcView, new Path("/internalDir/internalDir2/linkToDir3/foo")), + "Deleted File should not exist"); + assertFalse(exists(fcTarget, new Path(targetTestRoot, "dir3/foo")), + "Target of deleted file should not exist"); // mkdir fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), FileContext.DEFAULT_PERM, false); - Assert.assertTrue("New dir should be type dir", - isDir(fcView, new Path("/user/dirX"))); - Assert.assertTrue("Target of new dir should be of type dir", - isDir(fcTarget, new Path(targetTestRoot,"user/dirX"))); + assertTrue(isDir(fcView, new Path("/user/dirX")), "New dir should be type dir"); + assertTrue(isDir(fcTarget, new Path(targetTestRoot, "user/dirX")), + "Target of new dir should be of type dir"); fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"), FileContext.DEFAULT_PERM, false); - Assert.assertTrue("New dir should be type dir", - isDir(fcView, new Path("/user/dirX/dirY"))); - Assert.assertTrue("Target of new dir should be of type dir", - isDir(fcTarget,new Path(targetTestRoot,"user/dirX/dirY"))); + assertTrue(isDir(fcView, new Path("/user/dirX/dirY")), + "New dir should be type dir"); + assertTrue(isDir(fcTarget, new Path(targetTestRoot, "user/dirX/dirY")), + "Target of new dir should be of type dir"); // Delete the created dir - Assert.assertTrue("Delete should succeed", - fcView.delete(new Path("/user/dirX/dirY"), false)); - Assert.assertFalse("Deleted File should not exist", - exists(fcView, new Path("/user/dirX/dirY"))); - Assert.assertFalse("Deleted Target should not exist", - exists(fcTarget, new Path(targetTestRoot,"user/dirX/dirY"))); + assertTrue(fcView.delete(new Path("/user/dirX/dirY"), false), + "Delete should succeed"); + assertFalse(exists(fcView, new Path("/user/dirX/dirY")), + "Deleted File should not exist"); + assertFalse(exists(fcTarget, new Path(targetTestRoot, "user/dirX/dirY")), + "Deleted Target should not exist"); - Assert.assertTrue("Delete should succeed", - fcView.delete(new Path("/user/dirX"), false)); - Assert.assertFalse("Deleted File should not exist", - exists(fcView, new Path("/user/dirX"))); - Assert.assertFalse("Deleted Target should not exist", - exists(fcTarget, new Path(targetTestRoot,"user/dirX"))); + assertTrue(fcView.delete(new Path("/user/dirX"), false), "Delete should succeed"); + assertFalse(exists(fcView, new Path("/user/dirX")), + "Deleted File should not exist"); + assertFalse(exists(fcTarget, new Path(targetTestRoot, "user/dirX")), + "Deleted Target should not exist"); // Rename a file fileContextTestHelper.createFile(fcView, "/user/foo"); fcView.rename(new Path("/user/foo"), new Path("/user/fooBar")); - Assert.assertFalse("Renamed src should not exist", - exists(fcView, new Path("/user/foo"))); - Assert.assertFalse(exists(fcTarget, new Path(targetTestRoot,"user/foo"))); - Assert.assertTrue(isFile(fcView, + assertFalse(exists(fcView, new Path("/user/foo")), "Renamed src should not exist"); + assertFalse(exists(fcTarget, new Path(targetTestRoot, "user/foo"))); + assertTrue(isFile(fcView, fileContextTestHelper.getTestRootPath(fcView,"/user/fooBar"))); - Assert.assertTrue(isFile(fcTarget, new Path(targetTestRoot,"user/fooBar"))); + assertTrue(isFile(fcTarget, new Path(targetTestRoot, "user/fooBar"))); fcView.mkdir(new Path("/user/dirFoo"), FileContext.DEFAULT_PERM, false); fcView.rename(new Path("/user/dirFoo"), new Path("/user/dirFooBar")); - Assert.assertFalse("Renamed src should not exist", - exists(fcView, new Path("/user/dirFoo"))); - Assert.assertFalse("Renamed src should not exist in target", - exists(fcTarget, new Path(targetTestRoot,"user/dirFoo"))); - Assert.assertTrue("Renamed dest should exist as dir", - isDir(fcView, - fileContextTestHelper.getTestRootPath(fcView,"/user/dirFooBar"))); - Assert.assertTrue("Renamed dest should exist as dir in target", - isDir(fcTarget,new Path(targetTestRoot,"user/dirFooBar"))); + assertFalse(exists(fcView, new Path("/user/dirFoo")), + "Renamed src should not exist"); + assertFalse(exists(fcTarget, new Path(targetTestRoot, "user/dirFoo")), + "Renamed src should not exist in target"); + assertTrue(isDir(fcView, fileContextTestHelper.getTestRootPath(fcView, "/user/dirFooBar")), + "Renamed dest should exist as dir"); + assertTrue(isDir(fcTarget, new Path(targetTestRoot, "user/dirFooBar")), + "Renamed dest should exist as dir in target"); // Make a directory under a directory that's mounted from the root of another FS fcView.mkdir(new Path("/targetRoot/dirFoo"), FileContext.DEFAULT_PERM, false); - Assert.assertTrue(exists(fcView, new Path("/targetRoot/dirFoo"))); + assertTrue(exists(fcView, new Path("/targetRoot/dirFoo"))); boolean dirFooPresent = false; RemoteIterator dirContents = fcView.listStatus(new Path( "/targetRoot/")); @@ -341,7 +338,7 @@ public void testOperationsThroughMountLinks() throws IOException { dirFooPresent = true; } } - Assert.assertTrue(dirFooPresent); + assertTrue(dirFooPresent); RemoteIterator dirLocatedContents = fcView.listLocatedStatus(new Path("/targetRoot/")); dirFooPresent = false; @@ -351,7 +348,7 @@ public void testOperationsThroughMountLinks() throws IOException { dirFooPresent = true; } } - Assert.assertTrue(dirFooPresent); + assertTrue(dirFooPresent); } // rename across mount points that point to same target also fail @@ -452,7 +449,7 @@ public void testGetBlockLocations() throws IOException { checkFileStatus(fcView, viewFilePath.toString(), fileType.isFile); BlockLocation[] viewBL = fcView.getFileBlockLocations(viewFilePath, 0, 10240+100); - Assert.assertEquals(SupportsBlocks ? 10 : 1, viewBL.length); + assertEquals(SupportsBlocks ? 10 : 1, viewBL.length); BlockLocation[] targetBL = fcTarget.getFileBlockLocations(targetFilePath, 0, 10240+100); compareBLs(viewBL, targetBL); @@ -464,7 +461,7 @@ public void testGetBlockLocations() throws IOException { } void compareBLs(BlockLocation[] viewBL, BlockLocation[] targetBL) { - Assert.assertEquals(targetBL.length, viewBL.length); + assertEquals(targetBL.length, viewBL.length); int i = 0; for (BlockLocation vbl : viewBL) { assertThat(vbl.toString()).isEqualTo(targetBL[i].toString()); @@ -489,52 +486,51 @@ public void testListOnInternalDirsOfMountTable() throws IOException { FileStatus[] dirPaths = fcView.util().listStatus(new Path("/")); FileStatus fs; - Assert.assertEquals(7, dirPaths.length); + assertEquals(7, dirPaths.length); fs = fileContextTestHelper.containsPath(fcView, "/user", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + assertNotNull(fs); + assertTrue(fs.isSymlink(), "A mount should appear as symlink"); fs = fileContextTestHelper.containsPath(fcView, "/data", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + assertNotNull(fs); + assertTrue(fs.isSymlink(), "A mount should appear as symlink"); fs = fileContextTestHelper.containsPath(fcView, "/internalDir", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("InternalDirs should appear as dir", fs.isDirectory()); + assertNotNull(fs); + assertTrue(fs.isDirectory(), "InternalDirs should appear as dir"); fs = fileContextTestHelper.containsPath(fcView, "/danglingLink", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + assertNotNull(fs); + assertTrue(fs.isSymlink(), "A mount should appear as symlink"); fs = fileContextTestHelper.containsPath(fcView, "/linkToAFile", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + assertNotNull(fs); + assertTrue(fs.isSymlink(), "A mount should appear as symlink"); - // list on internal dir - dirPaths = fcView.util().listStatus(new Path("/internalDir")); - Assert.assertEquals(2, dirPaths.length); + // list on internal dir + dirPaths = fcView.util().listStatus(new Path("/internalDir")); + assertEquals(2, dirPaths.length); - fs = fileContextTestHelper.containsPath(fcView, - "/internalDir/internalDir2", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("InternalDirs should appear as dir",fs.isDirectory()); - fs = fileContextTestHelper.containsPath(fcView, - "/internalDir/linkToDir2", dirPaths); - Assert.assertNotNull(fs); - Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); + fs = fileContextTestHelper.containsPath(fcView, "/internalDir/internalDir2", dirPaths); + assertNotNull(fs); + assertTrue(fs.isDirectory(), "InternalDirs should appear as dir"); + fs = fileContextTestHelper.containsPath(fcView, "/internalDir/linkToDir2", dirPaths); + assertNotNull(fs); + assertTrue(fs.isSymlink(), "A mount should appear as symlink"); } - @Test(expected = FileNotFoundException.class) + @Test public void testFileStatusOnMountLink() throws IOException { - Assert.assertTrue("Slash should appear as dir", - fcView.getFileStatus(new Path("/")).isDirectory()); - checkFileStatus(fcView, "/", fileType.isDir); - checkFileStatus(fcView, "/user", fileType.isDir); - checkFileStatus(fcView, "/data", fileType.isDir); - checkFileStatus(fcView, "/internalDir", fileType.isDir); - checkFileStatus(fcView, "/internalDir/linkToDir2", fileType.isDir); - checkFileStatus(fcView, "/internalDir/internalDir2/linkToDir3", fileType.isDir); - checkFileStatus(fcView, "/linkToAFile", fileType.isFile); - - fcView.getFileStatus(new Path("/danglingLink")); + assertThrows(FileNotFoundException.class, () -> { + assertTrue(fcView.getFileStatus(new Path("/")).isDirectory(), + "Slash should appear as dir"); + checkFileStatus(fcView, "/", fileType.isDir); + checkFileStatus(fcView, "/user", fileType.isDir); + checkFileStatus(fcView, "/data", fileType.isDir); + checkFileStatus(fcView, "/internalDir", fileType.isDir); + checkFileStatus(fcView, "/internalDir/linkToDir2", fileType.isDir); + checkFileStatus(fcView, "/internalDir/internalDir2/linkToDir3", fileType.isDir); + checkFileStatus(fcView, "/linkToAFile", fileType.isFile); + fcView.getFileStatus(new Path("/danglingLink")); + }); } @Test @@ -554,15 +550,19 @@ public void testGetFileChecksum() throws AccessControlException, verify(mockAFS).getFileChecksum(new Path("someFile")); } - @Test(expected=FileNotFoundException.class) + @Test public void testgetFSonDanglingLink() throws IOException { - fcView.getFileStatus(new Path("/danglingLink")); + assertThrows(FileNotFoundException.class, () -> { + fcView.getFileStatus(new Path("/danglingLink")); + }); } - @Test(expected=FileNotFoundException.class) + @Test public void testgetFSonNonExistingInternalDir() throws IOException { - fcView.getFileStatus(new Path("/internalDir/nonExisting")); + assertThrows(FileNotFoundException.class, () -> { + fcView.getFileStatus(new Path("/internalDir/nonExisting")); + }); } @Test @@ -577,33 +577,37 @@ public void testgetFileLinkStatus() throws IOException { checkFileLinkStatus(fcView, "/internalDir/internalDir2", fileType.isDir); } - @Test(expected=FileNotFoundException.class) + @Test public void testgetFileLinkStatusonNonExistingInternalDir() throws IOException { - fcView.getFileLinkStatus(new Path("/internalDir/nonExisting")); + assertThrows(FileNotFoundException.class, () -> { + fcView.getFileLinkStatus(new Path("/internalDir/nonExisting")); + }); } @Test public void testSymlinkTarget() throws IOException { // get link target` - Assert.assertEquals(fcView.getLinkTarget(new Path("/user")), + assertEquals(fcView.getLinkTarget(new Path("/user")), (new Path(targetTestRoot,"user"))); - Assert.assertEquals(fcView.getLinkTarget(new Path("/data")), + assertEquals(fcView.getLinkTarget(new Path("/data")), (new Path(targetTestRoot,"data"))); - Assert.assertEquals( + assertEquals( fcView.getLinkTarget(new Path("/internalDir/linkToDir2")), (new Path(targetTestRoot,"dir2"))); - Assert.assertEquals( + assertEquals( fcView.getLinkTarget(new Path("/internalDir/internalDir2/linkToDir3")), (new Path(targetTestRoot,"dir3"))); - Assert.assertEquals(fcView.getLinkTarget(new Path("/linkToAFile")), + assertEquals(fcView.getLinkTarget(new Path("/linkToAFile")), (new Path(targetTestRoot,"aFile"))); } - @Test(expected=IOException.class) + @Test public void testgetLinkTargetOnNonLink() throws IOException { - fcView.getLinkTarget(new Path("/internalDir/internalDir2")); + assertThrows(IOException.class, () -> { + fcView.getLinkTarget(new Path("/internalDir/internalDir2")); + }); } /* @@ -614,19 +618,19 @@ public void testgetLinkTargetOnNonLink() throws IOException { @Test public void testResolvePathInternalPaths() throws IOException { - Assert.assertEquals(new Path("/"), fcView.resolvePath(new Path("/"))); - Assert.assertEquals(new Path("/internalDir"), + assertEquals(new Path("/"), fcView.resolvePath(new Path("/"))); + assertEquals(new Path("/internalDir"), fcView.resolvePath(new Path("/internalDir"))); } @Test public void testResolvePathMountPoints() throws IOException { - Assert.assertEquals(new Path(targetTestRoot,"user"), - fcView.resolvePath(new Path("/user"))); - Assert.assertEquals(new Path(targetTestRoot,"data"), + assertEquals(new Path(targetTestRoot, "user"), + fcView.resolvePath(new Path("/user"))); + assertEquals(new Path(targetTestRoot, "data"), fcView.resolvePath(new Path("/data"))); - Assert.assertEquals(new Path(targetTestRoot,"dir2"), + assertEquals(new Path(targetTestRoot, "dir2"), fcView.resolvePath(new Path("/internalDir/linkToDir2"))); - Assert.assertEquals(new Path(targetTestRoot,"dir3"), + assertEquals(new Path(targetTestRoot, "dir3"), fcView.resolvePath(new Path("/internalDir/internalDir2/linkToDir3"))); } @@ -634,40 +638,45 @@ public void testResolvePathMountPoints() throws IOException { @Test public void testResolvePathThroughMountPoints() throws IOException { fileContextTestHelper.createFile(fcView, "/user/foo"); - Assert.assertEquals(new Path(targetTestRoot,"user/foo"), - fcView.resolvePath(new Path("/user/foo"))); + assertEquals(new Path(targetTestRoot, "user/foo"), + fcView.resolvePath(new Path("/user/foo"))); fcView.mkdir( fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), - FileContext.DEFAULT_PERM, false); - Assert.assertEquals(new Path(targetTestRoot,"user/dirX"), + FileContext.DEFAULT_PERM, false); + assertEquals(new Path(targetTestRoot, "user/dirX"), fcView.resolvePath(new Path("/user/dirX"))); fcView.mkdir( fileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"), - FileContext.DEFAULT_PERM, false); - Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"), + FileContext.DEFAULT_PERM, false); + assertEquals(new Path(targetTestRoot, "user/dirX/dirY"), fcView.resolvePath(new Path("/user/dirX/dirY"))); } - @Test(expected=FileNotFoundException.class) + @Test public void testResolvePathDanglingLink() throws IOException { + assertThrows(FileNotFoundException.class, () -> { fcView.resolvePath(new Path("/danglingLink")); + }); } - @Test(expected=FileNotFoundException.class) + @Test public void testResolvePathMissingThroughMountPoints() throws IOException { - fcView.resolvePath(new Path("/user/nonExisting")); + assertThrows(FileNotFoundException.class, () -> { + fcView.resolvePath(new Path("/user/nonExisting")); + }); } - @Test(expected=FileNotFoundException.class) + @Test public void testResolvePathMissingThroughMountPoints2() throws IOException { - fcView.mkdir( - fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), - FileContext.DEFAULT_PERM, false); - fcView.resolvePath(new Path("/user/dirX/nonExisting")); + assertThrows(FileNotFoundException.class, () -> { + fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), + FileContext.DEFAULT_PERM, false); + fcView.resolvePath(new Path("/user/dirX/nonExisting")); + }); } @@ -681,113 +690,152 @@ public void testResolvePathMissingThroughMountPoints2() throws IOException { // Mkdir on internal mount table should fail - @Test(expected=AccessControlException.class) + @Test public void testInternalMkdirSlash() throws IOException { - fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/"), - FileContext.DEFAULT_PERM, false); + assertThrows(AccessControlException.class, () -> { + fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/"), + FileContext.DEFAULT_PERM, false); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalMkdirExisting1() throws IOException { - fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/internalDir"), - FileContext.DEFAULT_PERM, false); + assertThrows(AccessControlException.class, () -> { + fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/internalDir"), + FileContext.DEFAULT_PERM, false); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalMkdirExisting2() throws IOException { - fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, - "/internalDir/linkToDir2"), - FileContext.DEFAULT_PERM, false); + assertThrows(AccessControlException.class, () -> { + fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, + "/internalDir/linkToDir2"), + FileContext.DEFAULT_PERM, false); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalMkdirNew() throws IOException { - fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/dirNew"), - FileContext.DEFAULT_PERM, false); + assertThrows(AccessControlException.class, () -> { + fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/dirNew"), + FileContext.DEFAULT_PERM, false); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalMkdirNew2() throws IOException { - fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/internalDir/dirNew"), - FileContext.DEFAULT_PERM, false); + assertThrows(AccessControlException.class, () -> { + fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/internalDir/dirNew"), + FileContext.DEFAULT_PERM, false); + }); } // Create on internal mount table should fail - @Test(expected=AccessControlException.class) + @Test public void testInternalCreate1() throws IOException { - fileContextTestHelper.createFileNonRecursive(fcView, "/foo"); // 1 component + assertThrows(AccessControlException.class, () -> { + fileContextTestHelper.createFileNonRecursive(fcView, "/foo"); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalCreate2() throws IOException { // 2 component - fileContextTestHelper.createFileNonRecursive(fcView, "/internalDir/foo"); + assertThrows(AccessControlException.class, () -> { + fileContextTestHelper.createFileNonRecursive(fcView, "/internalDir/foo"); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalCreateMissingDir() throws IOException { - fileContextTestHelper.createFile(fcView, "/missingDir/foo"); + assertThrows(AccessControlException.class, () -> { + fileContextTestHelper.createFile(fcView, "/missingDir/foo"); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalCreateMissingDir2() throws IOException { - fileContextTestHelper.createFile(fcView, "/missingDir/miss2/foo"); + assertThrows(AccessControlException.class, () -> { + fileContextTestHelper.createFile(fcView, "/missingDir/miss2/foo"); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalCreateMissingDir3() throws IOException { - fileContextTestHelper.createFile(fcView, "/internalDir/miss2/foo"); + assertThrows(AccessControlException.class, () -> { + fileContextTestHelper.createFile(fcView, "/internalDir/miss2/foo"); + }); } // Delete on internal mount table should fail - @Test(expected=FileNotFoundException.class) + @Test public void testInternalDeleteNonExisting() throws IOException { + assertThrows(FileNotFoundException.class, () -> { fcView.delete(new Path("/NonExisting"), false); + }); } - @Test(expected=FileNotFoundException.class) + @Test public void testInternalDeleteNonExisting2() throws IOException { + assertThrows(FileNotFoundException.class, () -> { fcView.delete(new Path("/internalDir/NonExisting"), false); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalDeleteExisting() throws IOException { + assertThrows(AccessControlException.class, () -> { fcView.delete(new Path("/internalDir"), false); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalDeleteExisting2() throws IOException { - Assert.assertTrue("Delete of link to dir should succeed", - fcView.getFileStatus(new Path("/internalDir/linkToDir2")).isDirectory()); - fcView.delete(new Path("/internalDir/linkToDir2"), false); + assertThrows(AccessControlException.class, () -> { + assertTrue(fcView.getFileStatus(new Path("/internalDir/linkToDir2")).isDirectory(), + "Delete of link to dir should succeed"); + fcView.delete(new Path("/internalDir/linkToDir2"), false); + }); } // Rename on internal mount table should fail - @Test(expected=AccessControlException.class) + @Test public void testInternalRename1() throws IOException { - fcView.rename(new Path("/internalDir"), new Path("/newDir")); + assertThrows(AccessControlException.class, () -> { + fcView.rename(new Path("/internalDir"), new Path("/newDir")); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalRename2() throws IOException { - Assert.assertTrue("linkTODir2 should be a dir", - fcView.getFileStatus(new Path("/internalDir/linkToDir2")).isDirectory()); - fcView.rename(new Path("/internalDir/linkToDir2"), - new Path("/internalDir/dir1")); + assertThrows(AccessControlException.class, () -> { + assertTrue(fcView.getFileStatus(new Path("/internalDir/linkToDir2")).isDirectory(), + "linkTODir2 should be a dir"); + fcView.rename(new Path("/internalDir/linkToDir2"), new Path("/internalDir/dir1")); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalRename3() throws IOException { - fcView.rename(new Path("/user"), new Path("/internalDir/linkToDir2")); + assertThrows(AccessControlException.class, () -> { + fcView.rename(new Path("/user"), new Path("/internalDir/linkToDir2")); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalRenameToSlash() throws IOException { - fcView.rename(new Path("/internalDir/linkToDir2/foo"), new Path("/")); + assertThrows(AccessControlException.class, () -> { + fcView.rename(new Path("/internalDir/linkToDir2/foo"), new Path("/")); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalRenameFromSlash() throws IOException { - fcView.rename(new Path("/"), new Path("/bar")); + assertThrows(AccessControlException.class, () -> { + fcView.rename(new Path("/"), new Path("/bar")); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalSetOwner() throws IOException { - fcView.setOwner(new Path("/internalDir"), "foo", "bar"); + assertThrows(AccessControlException.class, () -> { + fcView.setOwner(new Path("/internalDir"), "foo", "bar"); + }); } /** @@ -795,31 +843,39 @@ public void testInternalSetOwner() throws IOException { * any mount table entry. */ - @Test(expected=AccessControlException.class) + @Test public void testInternalModifyAclEntries() throws IOException { - fcView.modifyAclEntries(new Path("/internalDir"), - new ArrayList()); + assertThrows(AccessControlException.class, () -> { + fcView.modifyAclEntries(new Path("/internalDir"), new ArrayList()); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalRemoveAclEntries() throws IOException { - fcView.removeAclEntries(new Path("/internalDir"), - new ArrayList()); + assertThrows(AccessControlException.class, () -> { + fcView.removeAclEntries(new Path("/internalDir"), new ArrayList()); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalRemoveDefaultAcl() throws IOException { - fcView.removeDefaultAcl(new Path("/internalDir")); + assertThrows(AccessControlException.class, () -> { + fcView.removeDefaultAcl(new Path("/internalDir")); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalRemoveAcl() throws IOException { - fcView.removeAcl(new Path("/internalDir")); + assertThrows(AccessControlException.class, () -> { + fcView.removeAcl(new Path("/internalDir")); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalSetAcl() throws IOException { - fcView.setAcl(new Path("/internalDir"), new ArrayList()); + assertThrows(AccessControlException.class, () -> { + fcView.setAcl(new Path("/internalDir"), new ArrayList()); + }); } @Test @@ -834,55 +890,75 @@ public void testInternalGetAclStatus() throws IOException { assertFalse(aclStatus.isStickyBit()); } - @Test(expected=AccessControlException.class) + @Test public void testInternalSetXAttr() throws IOException { - fcView.setXAttr(new Path("/internalDir"), "xattrName", null); + assertThrows(AccessControlException.class, () -> { + fcView.setXAttr(new Path("/internalDir"), "xattrName", null); + }); } - @Test(expected=NotInMountpointException.class) + @Test public void testInternalGetXAttr() throws IOException { - fcView.getXAttr(new Path("/internalDir"), "xattrName"); + assertThrows(NotInMountpointException.class, () -> { + fcView.getXAttr(new Path("/internalDir"), "xattrName"); + }); } - @Test(expected=NotInMountpointException.class) + @Test public void testInternalGetXAttrs() throws IOException { - fcView.getXAttrs(new Path("/internalDir")); + assertThrows(NotInMountpointException.class, () -> { + fcView.getXAttrs(new Path("/internalDir")); + }); } - @Test(expected=NotInMountpointException.class) + @Test public void testInternalGetXAttrsWithNames() throws IOException { - fcView.getXAttrs(new Path("/internalDir"), new ArrayList()); + assertThrows(NotInMountpointException.class, () -> { + fcView.getXAttrs(new Path("/internalDir"), new ArrayList()); + }); } - @Test(expected=NotInMountpointException.class) + @Test public void testInternalListXAttr() throws IOException { - fcView.listXAttrs(new Path("/internalDir")); + assertThrows(NotInMountpointException.class, () -> { + fcView.listXAttrs(new Path("/internalDir")); + }); } - @Test(expected=AccessControlException.class) + @Test public void testInternalRemoveXAttr() throws IOException { - fcView.removeXAttr(new Path("/internalDir"), "xattrName"); + assertThrows(AccessControlException.class, () -> { + fcView.removeXAttr(new Path("/internalDir"), "xattrName"); + }); } - @Test(expected = AccessControlException.class) + @Test public void testInternalCreateSnapshot1() throws IOException { - fcView.createSnapshot(new Path("/internalDir")); + assertThrows(AccessControlException.class, () -> { + fcView.createSnapshot(new Path("/internalDir")); + }); } - @Test(expected = AccessControlException.class) + @Test public void testInternalCreateSnapshot2() throws IOException { - fcView.createSnapshot(new Path("/internalDir"), "snap1"); + assertThrows(AccessControlException.class, () -> { + fcView.createSnapshot(new Path("/internalDir"), "snap1"); + }); } - @Test(expected = AccessControlException.class) + @Test public void testInternalRenameSnapshot() throws IOException { - fcView.renameSnapshot(new Path("/internalDir"), "snapOldName", - "snapNewName"); + assertThrows(AccessControlException.class, () -> { + fcView.renameSnapshot(new Path("/internalDir"), "snapOldName", + "snapNewName"); + }); } - @Test(expected = AccessControlException.class) + @Test public void testInternalDeleteSnapshot() throws IOException { - fcView.deleteSnapshot(new Path("/internalDir"), "snap1"); + assertThrows(AccessControlException.class, () -> { + fcView.deleteSnapshot(new Path("/internalDir"), "snap1"); + }); } @Test diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfs.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfs.java index 12930d01acf49..e2c5f69ab9a9c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfs.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfs.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.fs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.net.URI; @@ -39,9 +39,10 @@ import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +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; import org.slf4j.event.Level; @@ -90,7 +91,7 @@ protected IOException unwrapException(IOException e) { return e; } - @BeforeClass + @BeforeAll public static void beforeClassSetup() throws Exception { Configuration conf = new HdfsConfiguration(); conf.set(FsPermission.UMASK_LABEL, "000"); @@ -100,7 +101,7 @@ public static void beforeClassSetup() throws Exception { dfs = cluster.getFileSystem(); } - @AfterClass + @AfterAll public static void afterClassTeardown() throws Exception { if (cluster != null) { cluster.shutdown(); @@ -108,7 +109,8 @@ public static void afterClassTeardown() throws Exception { IOUtils.cleanupWithLogger(LOG, webhdfs); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Access a file using a link that spans Hdfs to LocalFs */ public void testLinkAcrossFileSystems() throws IOException { Path localDir = new Path("file://" + wrapper.getAbsoluteTestRootDir() @@ -127,7 +129,8 @@ public void testLinkAcrossFileSystems() throws IOException { assertEquals(fileSize, wrapper.getFileStatus(link).getLen()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test renaming a file across two file systems using a link */ public void testRenameAcrossFileSystemsViaLink() throws IOException { Path localDir = new Path("file://" + wrapper.getAbsoluteTestRootDir() @@ -169,7 +172,8 @@ public void testRenameAcrossFileSystemsViaLink() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create symlink to / */ public void testCreateLinkToSlash() throws IOException { Path dir = new Path(testBaseDir1()); @@ -192,7 +196,8 @@ public void testCreateLinkToSlash() throws IOException { } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** setPermission affects the target not the link */ public void testSetPermissionAffectsTarget() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -232,7 +237,8 @@ public void testSetPermissionAffectsTarget() throws IOException { wrapper.getFileStatus(linkToDir).getPermission()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Create a symlink using a path with scheme but no authority */ public void testCreateWithPartQualPathFails() throws IOException { Path fileWoAuth = new Path("hdfs:///test/file"); @@ -251,7 +257,8 @@ public void testCreateWithPartQualPathFails() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** setReplication affects the target not the link */ public void testSetReplication() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -264,7 +271,8 @@ public void testSetReplication() throws IOException { assertEquals(2, wrapper.getFileStatus(file).getReplication()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test create symlink with a max len name */ public void testCreateLinkMaxPathLink() throws IOException { Path dir = new Path(testBaseDir1()); @@ -300,7 +308,8 @@ public void testCreateLinkMaxPathLink() throws IOException { } } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test symlink owner */ public void testLinkOwner() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -312,7 +321,8 @@ public void testLinkOwner() throws IOException { assertEquals(statLink.getOwner(), statFile.getOwner()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test WebHdfsFileSystem.createSymlink(..). */ public void testWebHDFS() throws IOException { Path file = new Path(testBaseDir1(), "file"); @@ -325,7 +335,8 @@ public void testWebHDFS() throws IOException { assertEquals(2, wrapper.getFileStatus(file).getReplication()); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test craeteSymlink(..) with quota. */ public void testQuota() throws IOException { final Path dir = new Path(testBaseDir1()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfsFileContext.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfsFileContext.java index 2a3e4c363719d..031fd5ed97be4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfsFileContext.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfsFileContext.java @@ -17,24 +17,26 @@ */ package org.apache.hadoop.fs; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; public class TestSymlinkHdfsFileContext extends TestSymlinkHdfs { private static FileContext fc; - @BeforeClass + @BeforeAll public static void testSetup() throws Exception { fc = FileContext.getFileContext(cluster.getURI(0)); wrapper = new FileContextTestWrapper(fc, "/tmp/TestSymlinkHdfsFileContext"); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) /** Test access a symlink using AbstractFileSystem */ public void testAccessLinkFromAbstractFileSystem() throws IOException { Path file = new Path(testBaseDir1(), "file"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfsFileSystem.java index cd0155389c001..9e1495366e8db 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSymlinkHdfsFileSystem.java @@ -17,35 +17,39 @@ */ package org.apache.hadoop.fs; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; public class TestSymlinkHdfsFileSystem extends TestSymlinkHdfs { - @BeforeClass + @BeforeAll public static void testSetup() throws Exception { wrapper = new FileSystemTestWrapper(dfs, "/tmp/TestSymlinkHdfsFileSystem"); } @Override - @Ignore("FileSystem adds missing authority in absolute URIs") - @Test(timeout=10000) + @Disabled("FileSystem adds missing authority in absolute URIs") + @Test + @Timeout(value = 10) public void testCreateWithPartQualPathFails() throws IOException {} - @Ignore("FileSystem#create creates parent directories," + + @Disabled("FileSystem#create creates parent directories," + " so dangling links to directories are created") @Override - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testCreateFileViaDanglingLinkParent() throws IOException {} // Additional tests for DFS-only methods - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testRecoverLease() throws IOException { Path dir = new Path(testBaseDir1()); Path file = new Path(testBaseDir1(), "file"); @@ -55,10 +59,11 @@ public void testRecoverLease() throws IOException { wrapper.createSymlink(file, link, false); // Attempt recoverLease through a symlink boolean closed = dfs.recoverLease(link); - assertTrue("Expected recoverLease to return true", closed); + assertTrue(closed, "Expected recoverLease to return true"); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testIsFileClosed() throws IOException { Path dir = new Path(testBaseDir1()); Path file = new Path(testBaseDir1(), "file"); @@ -68,10 +73,11 @@ public void testIsFileClosed() throws IOException { wrapper.createSymlink(file, link, false); // Attempt recoverLease through a symlink boolean closed = dfs.isFileClosed(link); - assertTrue("Expected isFileClosed to return true", closed); + assertTrue(closed, "Expected isFileClosed to return true"); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testConcat() throws Exception { Path dir = new Path(testBaseDir1()); Path link = new Path(testBaseDir1(), "link"); @@ -89,7 +95,8 @@ public void testConcat() throws Exception { dfs.concat(target, srcs); } - @Test(timeout=10000) + @Test + @Timeout(value = 10) public void testSnapshot() throws Exception { Path dir = new Path(testBaseDir1()); Path link = new Path(testBaseDir1(), "link"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java index 40aa43dd9e457..a85eb594cb609 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java @@ -104,22 +104,32 @@ import org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.CryptoExtension; import org.apache.hadoop.io.Text; import org.apache.hadoop.util.XMLUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.Timeout; -import org.mockito.Mockito; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import static org.apache.hadoop.fs.CommonConfigurationKeys.DFS_CLIENT_IGNORE_NAMENODE_DEFAULT_KMS_URI; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyShort; import static org.mockito.Mockito.withSettings; +import static org.mockito.Mockito.anyBoolean; +import static org.mockito.Mockito.anyLong; import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_DEFAULT; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_DEFAULT; @@ -138,12 +148,6 @@ import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains; import static org.apache.hadoop.test.MetricsAsserts.assertGauge; import static org.apache.hadoop.test.MetricsAsserts.getMetrics; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -153,6 +157,7 @@ import javax.xml.parsers.SAXParser; +@Timeout(120) public class TestEncryptionZones { static final Logger LOG = LoggerFactory.getLogger(TestEncryptionZones.class); @@ -180,10 +185,7 @@ protected String getKeyProviderURI() { new Path(testRootDir.toString(), "test.jks").toUri(); } - @Rule - public Timeout globalTimeout = new Timeout(120 * 1000); - - @Before + @BeforeEach public void setup() throws Exception { conf = new HdfsConfiguration(); fsHelper = new FileSystemTestHelper(); @@ -217,7 +219,7 @@ protected void setProvider() { .getProvider()); } - @After + @AfterEach public void teardown() { if (cluster != null) { cluster.shutdown(); @@ -233,7 +235,7 @@ public void assertNumZones(final int numZones) throws IOException { count++; it.next(); } - assertEquals("Unexpected number of encryption zones!", numZones, count); + assertEquals(numZones, count, "Unexpected number of encryption zones!"); } /** @@ -260,8 +262,8 @@ public void assertZonePresent(String keyName, String path) throws IOException { break; } } - assertTrue("Did not find expected encryption zone with keyName " + keyName + - " path " + path, match + assertTrue(match, "Did not find expected encryption zone with keyName " + keyName + + " path " + path ); } @@ -297,7 +299,7 @@ public void testTrashStickyBit() throws Exception { final FsShell shell = new FsShell(clientConf); String[] argv = new String[]{"-rm", ezfile1.toString()}; int res = ToolRunner.run(shell, argv); - assertEquals("Can't remove a file in EZ as superuser", 0, res); + assertEquals(0, res, "Can't remove a file in EZ as superuser"); final Path trashDir = new Path(zone1, FileSystem.TRASH_PREFIX); assertTrue(fsWrapper.exists(trashDir)); @@ -322,7 +324,7 @@ public Object run() throws Exception { // /zones/zone1/.Trash/user/Current/zones/zone1/file2 String[] argv = new String[]{"-rm", ezfile2.toString()}; int res = ToolRunner.run(shell, argv); - assertEquals("Can't remove a file in EZ as user:mygroup", 0, res); + assertEquals(0, res, "Can't remove a file in EZ as user:mygroup"); return null; } }); @@ -351,7 +353,7 @@ public void testProvisionTrash() throws Exception { final Path trashDir = new Path(zone1, FileSystem.TRASH_PREFIX); String[] argv = new String[]{"-rmdir", trashDir.toUri().getPath()}; int res = ToolRunner.run(shell, argv); - assertEquals("Unable to delete trash directory.", 0, res); + assertEquals(0, res, "Unable to delete trash directory."); assertFalse(fsWrapper.exists(trashDir)); // execute -provisionTrash command option and make sure the trash @@ -369,11 +371,12 @@ public void testProvisionTrash() throws Exception { @Test public void testBasicOperations() throws Exception { - assertNotNull("key provider is not present", dfsAdmin.getKeyProvider()); + assertNotNull(dfsAdmin.getKeyProvider(), "key provider is not present"); int numZones = 0; /* Number of EZs should be 0 if no EZ is created */ - assertEquals("Unexpected number of encryption zones!", numZones, - cluster.getNamesystem().getNumEncryptionZones()); + assertEquals(numZones, + cluster.getNamesystem().getNumEncryptionZones(), + "Unexpected number of encryption zones!"); /* Test failure of create EZ on a directory that doesn't exist. */ final Path zoneParent = new Path("/zones"); final Path zone1 = new Path(zoneParent, "zone1"); @@ -510,8 +513,8 @@ public Object run() throws Exception { fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); assertNumZones(numZones); - assertEquals("Unexpected number of encryption zones!", numZones, cluster - .getNamesystem().getNumEncryptionZones()); + assertEquals(numZones, cluster.getNamesystem().getNumEncryptionZones(), + "Unexpected number of encryption zones!"); assertGauge("NumEncryptionZones", numZones, getMetrics(NS_METRICS)); assertZonePresent(null, zone1.toString()); @@ -568,14 +571,14 @@ public void testEZwithFullyQualifiedPath() throws Exception { assertZonePresent(TEST_KEY, zone1.toString()); // Check that zone1 contains a .Trash directory final Path zone1Trash = new Path(zone1, fs.TRASH_PREFIX); - assertTrue("CreateEncryptionZone with trash enabled should create a " + - ".Trash directory in the EZ", fs.exists(zone1Trash)); + assertTrue(fs.exists(zone1Trash), "CreateEncryptionZone with trash enabled should create a " + + ".Trash directory in the EZ"); // getEncryptionZoneForPath for FQP should return the path component EncryptionZone ezForZone1 = dfsAdmin.getEncryptionZoneForPath(zone1FQP); - assertTrue("getEncryptionZoneForPath for fully qualified path should " + - "return the path component", - ezForZone1.getPath().equals(zone1.toString())); + assertTrue(ezForZone1.getPath().equals(zone1.toString()), + "getEncryptionZoneForPath for fully qualified path should " + + "return the path component"); // Create EZ without Trash fsWrapper.mkdir(zone2FQP, FsPermission.getDirDefault(), true); @@ -588,8 +591,9 @@ public void testEZwithFullyQualifiedPath() throws Exception { EncryptionZone ezForZone2 = dfsAdmin.getEncryptionZoneForPath(zone2FQP); Path ezTrashForZone2 = new Path(ezForZone2.getPath(), FileSystem.TRASH_PREFIX); - assertTrue("provisionEZTrash with fully qualified path should create " + - "trash directory ", fsWrapper.exists(ezTrashForZone2)); + assertTrue(fsWrapper.exists(ezTrashForZone2), + "provisionEZTrash with fully qualified path should create " + + "trash directory "); } /** @@ -675,12 +679,12 @@ public Object run() throws Exception { } // Check operation with accessible paths - assertEquals("expected ez path", allPath.toString(), - userAdmin.getEncryptionZoneForPath(allPath).getPath(). - toString()); - assertEquals("expected ez path", allPath.toString(), - userAdmin.getEncryptionZoneForPath(allPathFile).getPath(). - toString()); + assertEquals(allPath.toString(), + userAdmin.getEncryptionZoneForPath(allPath).getPath().toString(), + "expected ez path"); + assertEquals(allPath.toString(), + userAdmin.getEncryptionZoneForPath(allPathFile).getPath().toString(), + "expected ez path"); // Check operation with inaccessible (lack of permissions) path try { @@ -690,39 +694,39 @@ public Object run() throws Exception { assertExceptionContains("Permission denied:", e); } - assertNull("expected null for nonexistent path", - userAdmin.getEncryptionZoneForPath(nonexistent)); + assertNull(userAdmin.getEncryptionZoneForPath(nonexistent), + "expected null for nonexistent path"); // Check operation with non-ez paths - assertNull("expected null for non-ez path", - userAdmin.getEncryptionZoneForPath(nonEZDir)); - assertNull("expected null for non-ez path", - userAdmin.getEncryptionZoneForPath(nonEZFile)); + assertNull(userAdmin.getEncryptionZoneForPath(nonEZDir), + "expected null for non-ez path"); + assertNull(userAdmin.getEncryptionZoneForPath(nonEZFile), + "expected null for non-ez path"); // Check operation with snapshots String snapshottedAllPath = newSnap.toString() + allPath.toString(); - assertEquals("expected ez path", allPath.toString(), - userAdmin.getEncryptionZoneForPath( - new Path(snapshottedAllPath)).getPath().toString()); + assertEquals(allPath.toString(), + userAdmin.getEncryptionZoneForPath(new Path(snapshottedAllPath)).getPath().toString(), + "expected ez path"); /* * Delete the file from the non-snapshot and test that it is still ok * in the ez. */ fs.delete(allPathFile, false); - assertEquals("expected ez path", allPath.toString(), - userAdmin.getEncryptionZoneForPath( - new Path(snapshottedAllPath)).getPath().toString()); + assertEquals(allPath.toString(), userAdmin.getEncryptionZoneForPath( + new Path(snapshottedAllPath)).getPath().toString(), + "expected ez path"); // Delete the ez and make sure ss's ez is still ok. fs.delete(allPath, true); - assertEquals("expected ez path", allPath.toString(), - userAdmin.getEncryptionZoneForPath( - new Path(snapshottedAllPath)).getPath().toString()); - assertNull("expected null for deleted file path", - userAdmin.getEncryptionZoneForPath(allPathFile)); - assertNull("expected null for deleted directory path", - userAdmin.getEncryptionZoneForPath(allPath)); + assertEquals(allPath.toString(), + userAdmin.getEncryptionZoneForPath(new Path(snapshottedAllPath)).getPath().toString(), + "expected ez path"); + assertNull(userAdmin.getEncryptionZoneForPath(allPathFile), + "expected null for deleted file path"); + assertNull(userAdmin.getEncryptionZoneForPath(allPath), + "expected null for deleted directory path"); return null; } }); @@ -754,16 +758,16 @@ private void doRenameEncryptionZone(FSTestWrapper wrapper) throws Exception { // Verify that we can rename dir and files within an encryption zone. assertTrue(fs.rename(pathFooBaz, pathFooBar)); - assertTrue("Rename of dir and file within ez failed", - !wrapper.exists(pathFooBaz) && wrapper.exists(pathFooBar)); - assertEquals("Renamed file contents not the same", - contents, DFSTestUtil.readFile(fs, pathFooBarFile)); + assertTrue(!wrapper.exists(pathFooBaz) && wrapper.exists(pathFooBar), + "Rename of dir and file within ez failed"); + assertEquals(contents, DFSTestUtil.readFile(fs, pathFooBarFile), + "Renamed file contents not the same"); // Verify that we can rename an EZ root final Path newFoo = new Path(testRoot, "newfoo"); - assertTrue("Rename of EZ root", fs.rename(pathFoo, newFoo)); - assertTrue("Rename of EZ root failed", - !wrapper.exists(pathFoo) && wrapper.exists(newFoo)); + assertTrue(fs.rename(pathFoo, newFoo), "Rename of EZ root"); + assertTrue(!wrapper.exists(pathFoo) && wrapper.exists(newFoo), + "Rename of EZ root failed"); // Verify that we can't rename an EZ root onto itself try { @@ -817,11 +821,11 @@ public void testReadWrite() throws Exception { // FEInfos should be different FileEncryptionInfo feInfo1 = getFileEncryptionInfo(encFile1); FileEncryptionInfo feInfo2 = getFileEncryptionInfo(encFile2); - assertFalse("EDEKs should be different", Arrays + assertFalse(Arrays .equals(feInfo1.getEncryptedDataEncryptionKey(), - feInfo2.getEncryptedDataEncryptionKey())); - assertNotEquals("Key was rolled, versions should be different", - feInfo1.getEzKeyVersionName(), feInfo2.getEzKeyVersionName()); + feInfo2.getEncryptedDataEncryptionKey()), "EDEKs should be different"); + assertNotEquals(feInfo1.getEzKeyVersionName(), feInfo2.getEzKeyVersionName(), + "Key was rolled, versions should be different"); // Contents still equal verifyFilesEqual(fs, encFile1, encFile2, len); } @@ -924,13 +928,13 @@ public void testVersionAndSuiteNegotiation() throws Exception { CommonConfigurationKeysPublic.HADOOP_SECURITY_KEY_PROVIDER_PATH)), conf); List keys = provider.getKeys(); - assertEquals("Expected NN to have created one key per zone", 1, - keys.size()); + assertEquals(1, keys.size(), + "Expected NN to have created one key per zone"); List allVersions = Lists.newArrayList(); for (String key : keys) { List versions = provider.getKeyVersions(key); - assertEquals("Should only have one key version per key", 1, - versions.size()); + assertEquals(1, versions.size(), + "Should only have one key version per key"); allVersions.addAll(versions); } // Check that the specified CipherSuite was correctly saved on the NN @@ -952,7 +956,7 @@ public void testVersionAndSuiteNegotiation() throws Exception { @SuppressWarnings("unchecked") private static void mockCreate(ClientProtocol mcp, CipherSuite suite, CryptoProtocolVersion version) throws Exception { - Mockito.doReturn(new HdfsFileStatus.Builder() + doReturn(new HdfsFileStatus.Builder() .replication(1) .blocksize(1024) .perm(new FsPermission((short) 777)) @@ -976,7 +980,7 @@ private static void mockCreate(ClientProtocol mcp, private static void testCipherSuiteNegotiation(DistributedFileSystem fs, Configuration conf) throws Exception { // Set up mock ClientProtocol to test client-side CipherSuite negotiation - final ClientProtocol mcp = Mockito.mock(ClientProtocol.class); + final ClientProtocol mcp = mock(ClientProtocol.class); // Try with an empty conf final Configuration noCodecConf = new Configuration(conf); @@ -987,7 +991,7 @@ private static void testCipherSuiteNegotiation(DistributedFileSystem fs, noCodecConf.set(confKey, ""); fs.dfs = new DFSClient(null, mcp, noCodecConf, null); mockCreate(mcp, suite, CryptoProtocolVersion.ENCRYPTION_ZONES); - Mockito.when(mcp.complete(anyString(), anyString(), any(), anyLong())) + when(mcp.complete(anyString(), anyString(), any(), anyLong())) .thenReturn(true); try { fs.create(new Path("/mock")); @@ -1056,8 +1060,8 @@ private void dTIEM(Path prefix) throws Exception { final Path baseFile = new Path(prefix, "base"); fsWrapper.createFile(baseFile); FileStatus stat = fsWrapper.getFileStatus(baseFile); - assertFalse("Expected isEncrypted to return false for " + baseFile, - stat.isEncrypted()); + assertFalse(stat.isEncrypted(), + "Expected isEncrypted to return false for " + baseFile); // Create an encrypted file to check isEncrypted returns true final Path zone = new Path(prefix, "zone"); @@ -1066,57 +1070,52 @@ private void dTIEM(Path prefix) throws Exception { final Path encFile = new Path(zone, "encfile"); fsWrapper.createFile(encFile); stat = fsWrapper.getFileStatus(encFile); - assertTrue("Expected isEncrypted to return true for enc file" + encFile, - stat.isEncrypted()); + assertTrue(stat.isEncrypted(), + "Expected isEncrypted to return true for enc file" + encFile); // check that it returns true for an ez root stat = fsWrapper.getFileStatus(zone); - assertTrue("Expected isEncrypted to return true for ezroot", - stat.isEncrypted()); + assertTrue(stat.isEncrypted(), + "Expected isEncrypted to return true for ezroot"); // check that it returns true for a dir in the ez final Path zoneSubdir = new Path(zone, "subdir"); fsWrapper.mkdir(zoneSubdir, FsPermission.getDirDefault(), true); stat = fsWrapper.getFileStatus(zoneSubdir); - assertTrue( - "Expected isEncrypted to return true for ez subdir " + zoneSubdir, - stat.isEncrypted()); + assertTrue(stat.isEncrypted(), + "Expected isEncrypted to return true for ez subdir " + zoneSubdir); // check that it returns false for a non ez dir final Path nonEzDirPath = new Path(prefix, "nonzone"); fsWrapper.mkdir(nonEzDirPath, FsPermission.getDirDefault(), true); stat = fsWrapper.getFileStatus(nonEzDirPath); - assertFalse( - "Expected isEncrypted to return false for directory " + nonEzDirPath, - stat.isEncrypted()); + assertFalse(stat.isEncrypted(), + "Expected isEncrypted to return false for directory " + nonEzDirPath); // check that it returns true for listings within an ez FileStatus[] statuses = fsWrapper.listStatus(zone); for (FileStatus s : statuses) { - assertTrue("Expected isEncrypted to return true for ez stat " + zone, - s.isEncrypted()); + assertTrue(s.isEncrypted(), + "Expected isEncrypted to return true for ez stat " + zone); } statuses = fsWrapper.listStatus(encFile); for (FileStatus s : statuses) { - assertTrue( - "Expected isEncrypted to return true for ez file stat " + encFile, - s.isEncrypted()); + assertTrue(s.isEncrypted(), + "Expected isEncrypted to return true for ez file stat " + encFile); } // check that it returns false for listings outside an ez statuses = fsWrapper.listStatus(nonEzDirPath); for (FileStatus s : statuses) { - assertFalse( - "Expected isEncrypted to return false for nonez stat " + nonEzDirPath, - s.isEncrypted()); + assertFalse(s.isEncrypted(), + "Expected isEncrypted to return false for nonez stat " + nonEzDirPath); } statuses = fsWrapper.listStatus(baseFile); for (FileStatus s : statuses) { - assertFalse( - "Expected isEncrypted to return false for non ez stat " + baseFile, - s.isEncrypted()); + assertFalse(s.isEncrypted(), + "Expected isEncrypted to return false for non ez stat " + baseFile); } } @@ -1130,18 +1129,18 @@ public void testEncryptionZonesWithSnapshots() throws Exception { fs.createSnapshot(snapshottable, "snap1"); SnapshotDiffReport report = fs.getSnapshotDiffReport(snapshottable, "snap1", ""); - Assert.assertEquals(0, report.getDiffList().size()); + assertEquals(0, report.getDiffList().size()); report = fs.getSnapshotDiffReport(snapshottable, "snap1", ""); System.out.println(report); - Assert.assertEquals(0, report.getDiffList().size()); + assertEquals(0, report.getDiffList().size()); fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); report = fs.getSnapshotDiffReport(snapshottable, "snap1", ""); - Assert.assertEquals(0, report.getDiffList().size()); + assertEquals(0, report.getDiffList().size()); } private class AuthorizationExceptionInjector extends EncryptionFaultInjector { @@ -1271,8 +1270,8 @@ public void testStartFileRetry() throws Exception { executor.submit(new InjectFaultTask() { @Override public void doCleanup() throws Exception { - assertEquals("Expected no startFile key generation", - -1, injector.generateCount); + assertEquals(-1, injector.generateCount, + "Expected no startFile key generation"); fsWrapper.delete(file, false); } }).get(); @@ -1288,7 +1287,7 @@ public void doFault() throws Exception { } @Override public void doCleanup() throws Exception { - assertEquals("Expected no startFile retries", 1, injector.generateCount); + assertEquals(1, injector.generateCount, "Expected no startFile retries"); fsWrapper.delete(file, false); } }).get(); @@ -1310,7 +1309,7 @@ public void doFault() throws Exception { } @Override public void doCleanup() throws Exception { - assertEquals("Expected a startFile retry", 2, injector.generateCount); + assertEquals(2, injector.generateCount, "Expected a startFile retry"); fsWrapper.delete(zone1, true); } }).get(); @@ -1358,19 +1357,19 @@ public void doCleanup() throws Exception { public void testDelegationToken() throws Exception { UserGroupInformation.createRemoteUser("JobTracker"); DistributedFileSystem dfs = cluster.getFileSystem(); - KeyProvider keyProvider = Mockito.mock(KeyProvider.class, + KeyProvider keyProvider = mock(KeyProvider.class, withSettings().extraInterfaces( DelegationTokenExtension.class, CryptoExtension.class)); - Mockito.when(keyProvider.getConf()).thenReturn(conf); + when(keyProvider.getConf()).thenReturn(conf); byte[] testIdentifier = "Test identifier for delegation token".getBytes(); @SuppressWarnings("rawtypes") Token testToken = new Token(testIdentifier, new byte[0], new Text(), new Text()); - Mockito.when(((DelegationTokenIssuer)keyProvider). + when(((DelegationTokenIssuer)keyProvider). getCanonicalServiceName()).thenReturn("service"); - Mockito.when(((DelegationTokenIssuer)keyProvider). + when(((DelegationTokenIssuer)keyProvider). getDelegationToken(anyString())). thenReturn(testToken); @@ -1379,9 +1378,9 @@ public void testDelegationToken() throws Exception { Credentials creds = new Credentials(); final Token tokens[] = dfs.addDelegationTokens("JobTracker", creds); LOG.debug("Delegation tokens: " + Arrays.asList(tokens)); - Assert.assertEquals(2, tokens.length); - Assert.assertEquals(tokens[1], testToken); - Assert.assertEquals(2, creds.numberOfTokens()); + assertEquals(2, tokens.length); + assertEquals(tokens[1], testToken); + assertEquals(2, creds.numberOfTokens()); } /** @@ -1400,18 +1399,18 @@ public void testFsckOnEncryptionZones() throws Exception { PrintStream out = new PrintStream(bStream, true); int errCode = ToolRunner.run(new DFSck(conf, out), new String[]{ "/" }); - assertEquals("Fsck ran with non-zero error code", 0, errCode); + assertEquals(0, errCode, "Fsck ran with non-zero error code"); String result = bStream.toString(); - assertTrue("Fsck did not return HEALTHY status", - result.contains(NamenodeFsck.HEALTHY_STATUS)); + assertTrue(result.contains(NamenodeFsck.HEALTHY_STATUS), + "Fsck did not return HEALTHY status"); // Run fsck directly on the encryption zone instead of root errCode = ToolRunner.run(new DFSck(conf, out), new String[]{ zoneParent.toString() }); - assertEquals("Fsck ran with non-zero error code", 0, errCode); + assertEquals(0, errCode, "Fsck ran with non-zero error code"); result = bStream.toString(); - assertTrue("Fsck did not return HEALTHY status", - result.contains(NamenodeFsck.HEALTHY_STATUS)); + assertTrue(result.contains(NamenodeFsck.HEALTHY_STATUS), + "Fsck did not return HEALTHY status"); } /** @@ -1434,8 +1433,9 @@ public void testSnapshotsOnEncryptionZones() throws Exception { String contents = DFSTestUtil.readFile(fs, zoneFile); final Path snap1 = fs.createSnapshot(zoneParent, "snap1"); final Path snap1Zone = new Path(snap1, zone.getName()); - assertEquals("Got unexpected ez path", zone.toString(), - dfsAdmin.getEncryptionZoneForPath(snap1Zone).getPath().toString()); + assertEquals(zone.toString(), + dfsAdmin.getEncryptionZoneForPath(snap1Zone).getPath().toString(), + "Got unexpected ez path"); // Now delete the encryption zone, recreate the dir, and take another // snapshot @@ -1443,34 +1443,35 @@ public void testSnapshotsOnEncryptionZones() throws Exception { fsWrapper.mkdir(zone, FsPermission.getDirDefault(), true); final Path snap2 = fs.createSnapshot(zoneParent, "snap2"); final Path snap2Zone = new Path(snap2, zone.getName()); - assertEquals("Got unexpected ez path", zone.toString(), - dfsAdmin.getEncryptionZoneForPath(snap1Zone).getPath().toString()); - assertNull("Expected null ez path", - dfsAdmin.getEncryptionZoneForPath(snap2Zone)); + assertEquals(zone.toString(), + dfsAdmin.getEncryptionZoneForPath(snap1Zone).getPath().toString(), + "Got unexpected ez path"); + assertNull(dfsAdmin.getEncryptionZoneForPath(snap2Zone), + "Expected null ez path"); // Create the encryption zone again, and that shouldn't affect old snapshot dfsAdmin.createEncryptionZone(zone, TEST_KEY2, NO_TRASH); EncryptionZone ezSnap1 = dfsAdmin.getEncryptionZoneForPath(snap1Zone); - assertEquals("Got unexpected ez path", zone.toString(), - ezSnap1.getPath().toString()); - assertEquals("Unexpected ez key", TEST_KEY, ezSnap1.getKeyName()); - assertNull("Expected null ez path", - dfsAdmin.getEncryptionZoneForPath(snap2Zone)); + assertEquals(zone.toString(), ezSnap1.getPath().toString(), + "Got unexpected ez path"); + assertEquals(TEST_KEY, ezSnap1.getKeyName(), "Unexpected ez key"); + assertNull(dfsAdmin.getEncryptionZoneForPath(snap2Zone), + "Expected null ez path"); final Path snap3 = fs.createSnapshot(zoneParent, "snap3"); final Path snap3Zone = new Path(snap3, zone.getName()); // Check that snap3's EZ has the correct settings EncryptionZone ezSnap3 = dfsAdmin.getEncryptionZoneForPath(snap3Zone); - assertEquals("Got unexpected ez path", zone.toString(), - ezSnap3.getPath().toString()); - assertEquals("Unexpected ez key", TEST_KEY2, ezSnap3.getKeyName()); + assertEquals(zone.toString(), ezSnap3.getPath().toString(), + "Got unexpected ez path"); + assertEquals(TEST_KEY2, ezSnap3.getKeyName(), "Unexpected ez key"); // Check that older snapshots still have the old EZ settings ezSnap1 = dfsAdmin.getEncryptionZoneForPath(snap1Zone); - assertEquals("Got unexpected ez path", zone.toString(), - ezSnap1.getPath().toString()); - assertEquals("Unexpected ez key", TEST_KEY, ezSnap1.getKeyName()); - assertNull("Expected null ez path", - dfsAdmin.getEncryptionZoneForPath(snap2Zone)); + assertEquals(zone.toString(), ezSnap1.getPath().toString(), + "Got unexpected ez path"); + assertEquals(TEST_KEY, ezSnap1.getKeyName(), "Unexpected ez key"); + assertNull(dfsAdmin.getEncryptionZoneForPath(snap2Zone), + "Expected null ez path"); // Check that listEZs only shows the current filesystem state ArrayList listZones = Lists.newArrayList(); @@ -1481,29 +1482,32 @@ public void testSnapshotsOnEncryptionZones() throws Exception { for (EncryptionZone z: listZones) { System.out.println(z); } - assertEquals("Did not expect additional encryption zones!", 1, - listZones.size()); + assertEquals(1, listZones.size(), + "Did not expect additional encryption zones!"); EncryptionZone listZone = listZones.get(0); - assertEquals("Got unexpected ez path", zone.toString(), - listZone.getPath().toString()); - assertEquals("Unexpected ez key", TEST_KEY2, listZone.getKeyName()); + assertEquals(zone.toString(), listZone.getPath().toString(), + "Got unexpected ez path"); + assertEquals(TEST_KEY2, listZone.getKeyName(), "Unexpected ez key"); // Verify contents of the snapshotted file final Path snapshottedZoneFile = new Path( snap1.toString() + "/" + zone.getName() + "/" + zoneFile.getName()); - assertEquals("Contents of snapshotted file have changed unexpectedly", - contents, DFSTestUtil.readFile(fs, snapshottedZoneFile)); + assertEquals(contents, DFSTestUtil.readFile(fs, snapshottedZoneFile), + "Contents of snapshotted file have changed unexpectedly"); // Now delete the snapshots out of order and verify the zones are still // correct fs.deleteSnapshot(zoneParent, snap2.getName()); - assertEquals("Got unexpected ez path", zone.toString(), - dfsAdmin.getEncryptionZoneForPath(snap1Zone).getPath().toString()); - assertEquals("Got unexpected ez path", zone.toString(), - dfsAdmin.getEncryptionZoneForPath(snap3Zone).getPath().toString()); + assertEquals(zone.toString(), + dfsAdmin.getEncryptionZoneForPath(snap1Zone).getPath().toString(), + "Got unexpected ez path"); + assertEquals(zone.toString(), + dfsAdmin.getEncryptionZoneForPath(snap3Zone).getPath().toString(), + "Got unexpected ez path"); fs.deleteSnapshot(zoneParent, snap1.getName()); - assertEquals("Got unexpected ez path", zone.toString(), - dfsAdmin.getEncryptionZoneForPath(snap3Zone).getPath().toString()); + assertEquals(zone.toString(), + dfsAdmin.getEncryptionZoneForPath(snap3Zone).getPath().toString(), + "Got unexpected ez path"); } /** @@ -1527,16 +1531,16 @@ public void testSnapshotWithFile() throws Exception { // Now delete the file and create encryption zone fsWrapper.delete(zoneFile, false); dfsAdmin.createEncryptionZone(zone, TEST_KEY, NO_TRASH); - assertEquals("Got unexpected ez path", zone.toString(), - dfsAdmin.getEncryptionZoneForPath(zone).getPath()); + assertEquals(zone.toString(), dfsAdmin.getEncryptionZoneForPath(zone).getPath(), + "Got unexpected ez path"); // The file in snapshot shouldn't have any encryption info final Path snapshottedZoneFile = new Path( snap1 + "/" + zone.getName() + "/" + zoneFile.getName()); FileEncryptionInfo feInfo = getFileEncryptionInfo(snapshottedZoneFile); - assertNull("Expected null ez info", feInfo); - assertEquals("Contents of snapshotted file have changed unexpectedly", - contents, DFSTestUtil.readFile(fs, snapshottedZoneFile)); + assertNull(feInfo, "Expected null ez info"); + assertEquals(contents, DFSTestUtil.readFile(fs, snapshottedZoneFile), + "Contents of snapshotted file have changed unexpectedly"); } /** @@ -1598,8 +1602,8 @@ public void testEncryptionZonesWithSymlinks() throws Exception { DFSTestUtil.createFile(fs, target, len, (short)1, 0xFEED); String content = DFSTestUtil.readFile(fs, target); fs.createSymlink(target, link, false); - assertEquals("Contents read from link are not the same as target", - content, DFSTestUtil.readFile(fs, link)); + assertEquals(content, DFSTestUtil.readFile(fs, link), + "Contents read from link are not the same as target"); fs.delete(parent, true); // Now let's test when the symlink and target are in different @@ -1611,8 +1615,8 @@ public void testEncryptionZonesWithSymlinks() throws Exception { DFSTestUtil.createFile(fs, target, len, (short)1, 0xFEED); content = DFSTestUtil.readFile(fs, target); fs.createSymlink(target, link, false); - assertEquals("Contents read from link are not the same as target", - content, DFSTestUtil.readFile(fs, link)); + assertEquals(content, DFSTestUtil.readFile(fs, link), + "Contents read from link are not the same as target"); fs.delete(link, true); fs.delete(target, true); } @@ -1682,13 +1686,11 @@ public void testEncryptionZonesOnRootPath() throws Exception { dfsAdmin.createEncryptionZone(rootDir, TEST_KEY, NO_TRASH); DFSTestUtil.createFile(fs, zoneFile, len, (short) 1, 0xFEED); - assertEquals("File can be created on the root encryption zone " + - "with correct length", - len, fs.getFileStatus(zoneFile).getLen()); - assertEquals("Root dir is encrypted", - true, fs.getFileStatus(rootDir).isEncrypted()); - assertEquals("File is encrypted", - true, fs.getFileStatus(zoneFile).isEncrypted()); + assertEquals(len, fs.getFileStatus(zoneFile).getLen(), + "File can be created on the root encryption zone " + + "with correct length"); + assertEquals(true, fs.getFileStatus(rootDir).isEncrypted(), "Root dir is encrypted"); + assertEquals(true, fs.getFileStatus(zoneFile).isEncrypted(), "File is encrypted"); } @Test @@ -1705,8 +1707,9 @@ public void testEncryptionZonesOnRelativePath() throws Exception { assertNumZones(1); assertZonePresent(TEST_KEY, "/somewhere/base/zone"); - assertEquals("Got unexpected ez path", "/somewhere/base/zone", dfsAdmin - .getEncryptionZoneForPath(zoneDir).getPath().toString()); + assertEquals("/somewhere/base/zone", dfsAdmin + .getEncryptionZoneForPath(zoneDir).getPath().toString(), + "Got unexpected ez path"); } @Test @@ -1716,12 +1719,12 @@ public void testGetEncryptionZoneOnANonExistentPaths() throws Exception { dfsAdmin.createEncryptionZone(ezPath, TEST_KEY, NO_TRASH); Path zoneFile = new Path(ezPath, "file"); EncryptionZone ez = fs.getEZForPath(zoneFile); - assertNotNull("Expected EZ for non-existent path in EZ", ez); + assertNotNull(ez, "Expected EZ for non-existent path in EZ"); ez = dfsAdmin.getEncryptionZoneForPath(zoneFile); - assertNotNull("Expected EZ for non-existent path in EZ", ez); + assertNotNull(ez, "Expected EZ for non-existent path in EZ"); ez = dfsAdmin.getEncryptionZoneForPath( new Path("/does/not/exist")); - assertNull("Expected null for non-existent path not in EZ", ez); + assertNull(ez, "Expected null for non-existent path not in EZ"); } @Test @@ -1807,8 +1810,8 @@ public void testRootDirEZTrash() throws Exception { // if root path is an encryption zone Path encFileCurrentTrash = shell.getCurrentTrashDir(encFile); Path rootDirCurrentTrash = shell.getCurrentTrashDir(rootDir); - assertEquals("Root trash should be equal with ezFile trash", - encFileCurrentTrash, rootDirCurrentTrash); + assertEquals(encFileCurrentTrash, rootDirCurrentTrash, + "Root trash should be equal with ezFile trash"); // Use webHDFS client to test trash root path final WebHdfsFileSystem webFS = WebHdfsTestUtil.getWebHdfsFileSystem( @@ -1838,7 +1841,7 @@ public void testGetTrashRoots() throws Exception { fs.mkdirs(ezRoot3); dfsAdmin.createEncryptionZone(ezRoot3, TEST_KEY, NO_TRASH); Collection trashRootsBegin = fs.getTrashRoots(true); - assertEquals("Unexpected getTrashRoots result", 0, trashRootsBegin.size()); + assertEquals(0, trashRootsBegin.size(), "Unexpected getTrashRoots result"); final Path encFile = new Path(ezRoot2, "encFile"); final int len = 8192; @@ -1849,16 +1852,14 @@ public void testGetTrashRoots() throws Exception { verifyShellDeleteWithTrash(shell, encFile); Collection trashRootsDelete1 = fs.getTrashRoots(true); - assertEquals("Unexpected getTrashRoots result", 1, - trashRootsDelete1.size()); + assertEquals(1, trashRootsDelete1.size(), "Unexpected getTrashRoots result"); final Path nonEncFile = new Path("/nonEncFile"); DFSTestUtil.createFile(fs, nonEncFile, len, (short) 1, 0xFEED); verifyShellDeleteWithTrash(shell, nonEncFile); Collection trashRootsDelete2 = fs.getTrashRoots(true); - assertEquals("Unexpected getTrashRoots result", 2, - trashRootsDelete2.size()); + assertEquals(2, trashRootsDelete2.size(), "Unexpected getTrashRoots result"); } private void verifyShellDeleteWithTrash(FsShell shell, Path path) @@ -1870,14 +1871,14 @@ private void verifyShellDeleteWithTrash(FsShell shell, Path path) while (!checkTrash.isRoot() && !checkTrash.getName().equals(".Trash")) { checkTrash = checkTrash.getParent(); } - assertEquals("No .Trash component found in trash dir " + trashDir, - ".Trash", checkTrash.getName()); + assertEquals(".Trash", checkTrash.getName(), + "No .Trash component found in trash dir " + trashDir); final Path trashFile = new Path(shell.getCurrentTrashDir(path) + "/" + path); String[] argv = new String[]{"-rm", "-r", path.toString()}; int res = ToolRunner.run(shell, argv); - assertEquals("rm failed", 0, res); - assertTrue("File not in trash : " + trashFile, fs.exists(trashFile)); + assertEquals(0, res, "rm failed"); + assertTrue(fs.exists(trashFile), "File not in trash : " + trashFile); } catch (IOException ioe) { fail(ioe.getMessage()); } finally { @@ -1904,9 +1905,10 @@ public void testProviderUriInCredentials() throws Exception { credentials.addSecretKey(lookUpKey, DFSUtilClient.string2Bytes(dummyKeyProvider)); client.ugi.addCredentials(credentials); - Assert.assertEquals("Client Key provider is different from provider in " - + "credentials map", dummyKeyProvider, - client.getKeyProviderUri().toString()); + assertEquals(dummyKeyProvider, + client.getKeyProviderUri().toString(), + "Client Key provider is different from provider in " + + "credentials map"); } @@ -1924,27 +1926,25 @@ public void testKeyProviderFallBackBehavior() throws IOException { clusterConf.set( CommonConfigurationKeysPublic.HADOOP_SECURITY_KEY_PROVIDER_PATH, dummyKeyProviderUri1); - DFSClient mockClient = Mockito.spy(cluster.getFileSystem().getClient()); + DFSClient mockClient = spy(cluster.getFileSystem().getClient()); // Namenode returning null as keyProviderUri in FSServerDefaults. FsServerDefaults serverDefaultsWithKeyProviderNull = getTestServerDefaults(null); - Mockito.doReturn(serverDefaultsWithKeyProviderNull) + doReturn(serverDefaultsWithKeyProviderNull) .when(mockClient).getServerDefaults(); - Assert.assertEquals( - "Key provider uri from client doesn't match with uri from conf", - dummyKeyProviderUri1, mockClient.getKeyProviderUri().toString()); - Mockito.verify(mockClient, Mockito.times(1)).getServerDefaults(); + assertEquals(dummyKeyProviderUri1, mockClient.getKeyProviderUri().toString(), + "Key provider uri from client doesn't match with uri from conf"); + verify(mockClient, times(1)).getServerDefaults(); String dummyKeyProviderUri2 = "dummy://foo:bar@test_provider2"; FsServerDefaults serverDefaultsWithDummyKeyProvider = getTestServerDefaults(dummyKeyProviderUri2); // Namenode returning dummyKeyProvider2 in serverDefaults. - Mockito.doReturn(serverDefaultsWithDummyKeyProvider) + doReturn(serverDefaultsWithDummyKeyProvider) .when(mockClient).getServerDefaults(); - Assert.assertEquals( - "Key provider uri from client doesn't match with uri from namenode", - dummyKeyProviderUri2, mockClient.getKeyProviderUri().toString()); - Mockito.verify(mockClient, Mockito.times(2)).getServerDefaults(); + assertEquals(dummyKeyProviderUri2, mockClient.getKeyProviderUri().toString(), + "Key provider uri from client doesn't match with uri from namenode"); + verify(mockClient, times(2)).getServerDefaults(); } /** @@ -1957,18 +1957,18 @@ public void testKeyProviderFallBackBehavior() throws IOException { public void testDifferentKMSProviderOnUpgradedNamenode() throws Exception { Configuration clusterConf = cluster.getConfiguration(0); URI namenodeKeyProviderUri = URI.create(getKeyProviderURI()); - Assert.assertEquals("Key Provider for client and namenode are different", - namenodeKeyProviderUri, cluster.getFileSystem().getClient() - .getKeyProviderUri()); + assertEquals(namenodeKeyProviderUri, + cluster.getFileSystem().getClient() + .getKeyProviderUri(), "Key Provider for client and namenode are different"); // Unset the provider path in conf clusterConf.unset( CommonConfigurationKeysPublic.HADOOP_SECURITY_KEY_PROVIDER_PATH); // Even after unsetting the local conf, the client key provider should be // the same as namenode's provider. - Assert.assertEquals("Key Provider for client and namenode are different", - namenodeKeyProviderUri, cluster.getFileSystem().getClient() - .getKeyProviderUri()); + assertEquals(namenodeKeyProviderUri, + cluster.getFileSystem().getClient() + .getKeyProviderUri(), "Key Provider for client and namenode are different"); // Set the provider path to some dummy scheme. clusterConf.set( @@ -1976,19 +1976,19 @@ public void testDifferentKMSProviderOnUpgradedNamenode() throws Exception { "dummy://foo:bar@test_provider1"); // Even after pointing the conf to some dummy provider, the client key // provider should be the same as namenode's provider. - Assert.assertEquals("Key Provider for client and namenode are different", - namenodeKeyProviderUri, cluster.getFileSystem().getClient() - .getKeyProviderUri()); + assertEquals(namenodeKeyProviderUri, + cluster.getFileSystem().getClient() + .getKeyProviderUri(), "Key Provider for client and namenode are different"); // Ignore the key provider from NN. clusterConf.setBoolean( DFS_CLIENT_IGNORE_NAMENODE_DEFAULT_KMS_URI, true); - Assert.assertEquals("Expecting Key Provider for client config", - "dummy://foo:bar@test_provider1", cluster.getFileSystem().getClient() - .getKeyProviderUri().toString()); - Assert.assertNotEquals("Key Provider for client and namenode is different", - namenodeKeyProviderUri, cluster.getFileSystem().getClient() - .getKeyProviderUri().toString()); + assertEquals("dummy://foo:bar@test_provider1", + cluster.getFileSystem().getClient().getKeyProviderUri().toString(), + "Expecting Key Provider for client config"); + assertNotEquals(namenodeKeyProviderUri, + cluster.getFileSystem().getClient().getKeyProviderUri().toString(), + "Key Provider for client and namenode is different"); } /** @@ -2003,11 +2003,11 @@ public void testDifferentKMSProviderOnUnUpgradedNamenode() URI namenodeKeyProviderUri = URI.create(getKeyProviderURI()); URI clientKeyProviderUri = cluster.getFileSystem().getClient().getKeyProviderUri(); - Assert.assertNotNull(clientKeyProviderUri); + assertNotNull(clientKeyProviderUri); // Since the client and the namenode share the same conf, they will have // identical key provider. - Assert.assertEquals("Key Provider for client and namenode are different", - namenodeKeyProviderUri, clientKeyProviderUri); + assertEquals(namenodeKeyProviderUri, clientKeyProviderUri, + "Key Provider for client and namenode are different"); String dummyKeyProviderUri = "dummy://foo:bar@test_provider"; // Unset the provider path in conf. @@ -2017,15 +2017,15 @@ public void testDifferentKMSProviderOnUnUpgradedNamenode() FsServerDefaults spyServerDefaults = getTestServerDefaults(null); // Creating a fake serverdefaults so that we can simulate namenode not // being upgraded. - DFSClient spyClient = Mockito.spy(cluster.getFileSystem().getClient()); - Mockito.doReturn(spyServerDefaults).when(spyClient).getServerDefaults(); + DFSClient spyClient = spy(cluster.getFileSystem().getClient()); + doReturn(spyServerDefaults).when(spyClient).getServerDefaults(); // Since FsServerDefaults#keyProviderUri is null, the client // will fallback to local conf which is null. clientKeyProviderUri = spyClient.getKeyProviderUri(); - Assert.assertEquals("Client keyProvider should be " + dummyKeyProviderUri, - dummyKeyProviderUri, clientKeyProviderUri.toString()); - Mockito.verify(spyClient, Mockito.times(1)).getServerDefaults(); + assertEquals(dummyKeyProviderUri, clientKeyProviderUri.toString(), + "Client keyProvider should be " + dummyKeyProviderUri); + verify(spyClient, times(1)).getServerDefaults(); } // Given a provider uri return serverdefaults. @@ -2121,9 +2121,9 @@ public void testListEncryptionZonesWithSnapshots() throws Exception { verifyShellDeleteWithTrash(shell, zoneDirectChild); //permanently remove zone direct child of snapshottable directory fsWrapper.delete(shell.getCurrentTrashDir(zoneDirectChild), true); - assertFalse("listEncryptionZones should not return anything, " + - "since both EZs were deleted.", - dfsAdmin.listEncryptionZones().hasNext()); + assertFalse(dfsAdmin.listEncryptionZones().hasNext(), + "listEncryptionZones should not return anything, " + + "since both EZs were deleted."); } /** @@ -2137,17 +2137,17 @@ public void addMockKmsToken() throws Exception { UserGroupInformation.createRemoteUser("JobTracker"); WebHdfsFileSystem webfs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsConstants.WEBHDFS_SCHEME); - KeyProvider keyProvider = Mockito.mock(KeyProvider.class, withSettings() + KeyProvider keyProvider = mock(KeyProvider.class, withSettings() .extraInterfaces(DelegationTokenExtension.class, CryptoExtension.class)); - Mockito.when(keyProvider.getConf()).thenReturn(conf); + when(keyProvider.getConf()).thenReturn(conf); byte[] testIdentifier = "Test identifier for delegation token".getBytes(); Token testToken = new Token(testIdentifier, new byte[0], new Text("kms-dt"), new Text()); - Mockito.when(((DelegationTokenIssuer)keyProvider). + when(((DelegationTokenIssuer)keyProvider). getCanonicalServiceName()).thenReturn("service"); - Mockito.when(((DelegationTokenIssuer)keyProvider). + when(((DelegationTokenIssuer)keyProvider). getDelegationToken(anyString())). thenReturn(testToken); @@ -2156,9 +2156,9 @@ public void addMockKmsToken() throws Exception { final Token[] tokens = webfs.addDelegationTokens("JobTracker", creds); - Assert.assertEquals(2, tokens.length); - Assert.assertEquals(tokens[1], testToken); - Assert.assertEquals(2, creds.numberOfTokens()); + assertEquals(2, tokens.length); + assertEquals(tokens[1], testToken); + assertEquals(2, creds.numberOfTokens()); } /** @@ -2193,8 +2193,9 @@ public void testWebhdfsRead() throws Exception { // raw encrypted bytes. InputStream cryptoStream = webhdfs.open(encryptedFilePath).getWrappedStream(); - Assert.assertTrue("cryptoStream should be an instance of " - + "CryptoInputStream", (cryptoStream instanceof CryptoInputStream)); + assertTrue((cryptoStream instanceof CryptoInputStream), + "cryptoStream should be an instance of " + + "CryptoInputStream"); InputStream encryptedStream = ((CryptoInputStream)cryptoStream).getWrappedStream(); // Verify that the data read from the raw input stream is different @@ -2210,7 +2211,7 @@ private void verifyStreamsSame(String content, InputStream is) IOUtils.copyBytes(is, os, 1024, true); streamBytes = os.toByteArray(); } - Assert.assertArrayEquals(content.getBytes(), streamBytes); + assertArrayEquals(content.getBytes(), streamBytes); } private void verifyRaw(String content, InputStream is, InputStream rawIs) @@ -2220,14 +2221,14 @@ private void verifyRaw(String content, InputStream is, InputStream rawIs) IOUtils.copyBytes(is, os, 1024, true); streamBytes = os.toByteArray(); } - Assert.assertFalse(Arrays.equals(content.getBytes(), streamBytes)); + assertFalse(Arrays.equals(content.getBytes(), streamBytes)); // webhdfs raw bytes should match the raw bytes from dfs. try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { IOUtils.copyBytes(rawIs, os, 1024, true); rawBytes = os.toByteArray(); } - Assert.assertArrayEquals(rawBytes, streamBytes); + assertArrayEquals(rawBytes, streamBytes); } /* Tests that if client is old and namenode is new then the @@ -2253,7 +2254,7 @@ public void testWebhdfsReadOldBehavior() throws Exception { String location = namenodeConnection.getHeaderField("Location"); URL datanodeURL = new URL(location); String path = datanodeURL.getPath(); - Assert.assertEquals( + assertEquals( WebHdfsFileSystem.PATH_PREFIX + encryptedFilePath.toString(), path); HttpURLConnection datanodeConnection = returnConnection(datanodeURL, "GET", false); @@ -2286,11 +2287,11 @@ public void testWebhfsEZRedirectLocation() // Return a connection with client not supporting EZ. HttpURLConnection namenodeConnection = returnConnection(url, "GET", false); - Assert.assertNotNull(namenodeConnection.getHeaderField("Location")); + assertNotNull(namenodeConnection.getHeaderField("Location")); URL datanodeUrl = new URL(namenodeConnection.getHeaderField("Location")); - Assert.assertNotNull(datanodeUrl); + assertNotNull(datanodeUrl); String path = datanodeUrl.getPath(); - Assert.assertEquals( + assertEquals( WebHdfsFileSystem.PATH_PREFIX + encryptedFilePath.toString(), path); url = new URL("http", addr.getHostString(), addr.getPort(), @@ -2298,11 +2299,11 @@ public void testWebhfsEZRedirectLocation() + "?op=OPEN"); // Return a connection with client supporting EZ. namenodeConnection = returnConnection(url, "GET", true); - Assert.assertNotNull(namenodeConnection.getHeaderField("Location")); + assertNotNull(namenodeConnection.getHeaderField("Location")); datanodeUrl = new URL(namenodeConnection.getHeaderField("Location")); - Assert.assertNotNull(datanodeUrl); + assertNotNull(datanodeUrl); path = datanodeUrl.getPath(); - Assert.assertEquals(WebHdfsFileSystem.PATH_PREFIX + assertEquals(WebHdfsFileSystem.PATH_PREFIX + "/.reserved/raw" + encryptedFilePath.toString(), path); } @@ -2338,7 +2339,7 @@ public void testPread() throws Exception { FSDataInputStream in = webfs.open(encryptedFilePath); for (int i = 0; i < 1024; i++) { in.seek(i); - Assert.assertEquals((data[i] & 0XFF), in.read()); + assertEquals((data[i] & 0XFF), in.read()); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZonesWithKMS.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZonesWithKMS.java index d29db2bffc3c4..d741fcc748a59 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZonesWithKMS.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZonesWithKMS.java @@ -17,7 +17,8 @@ */ package org.apache.hadoop.hdfs; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.function.Supplier; import org.apache.hadoop.crypto.key.kms.KMSClientProvider; @@ -34,10 +35,10 @@ import org.apache.hadoop.hdfs.web.WebHdfsTestUtil; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.Whitebox; -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.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import java.io.File; import java.util.Arrays; @@ -53,18 +54,18 @@ protected String getKeyProviderURI() { miniKMS.getKMSUrl().toExternalForm().replace("://", "@"); } - @Before + @BeforeEach public void setup() throws Exception { File kmsDir = new File("target/test-classes/" + UUID.randomUUID().toString()); - Assert.assertTrue(kmsDir.mkdirs()); + assertTrue(kmsDir.mkdirs()); MiniKMS.Builder miniKMSBuilder = new MiniKMS.Builder(); miniKMS = miniKMSBuilder.setKmsConfDir(kmsDir).build(); miniKMS.start(); super.setup(); } - @After + @AfterEach public void teardown() { super.teardown(); miniKMS.stop(); @@ -82,7 +83,8 @@ private KMSClientProvider getKMSClientProvider() { return lbkmscp.getProviders()[0]; } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testCreateEZPopulatesEDEKCache() throws Exception { final Path zonePath = new Path("/TestEncryptionZone"); fsWrapper.mkdir(zonePath, FsPermission.getDirDefault(), false); @@ -92,7 +94,8 @@ public void testCreateEZPopulatesEDEKCache() throws Exception { assertTrue(kcp.getEncKeyQueueSize(TEST_KEY) > 0); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testDelegationToken() throws Exception { final String renewer = "JobTracker"; UserGroupInformation.createRemoteUser(renewer); @@ -100,16 +103,17 @@ public void testDelegationToken() throws Exception { Credentials creds = new Credentials(); Token tokens[] = fs.addDelegationTokens(renewer, creds); LOG.debug("Delegation tokens: " + Arrays.asList(tokens)); - Assert.assertEquals(2, tokens.length); - Assert.assertEquals(2, creds.numberOfTokens()); + assertEquals(2, tokens.length); + assertEquals(2, creds.numberOfTokens()); // If the dt exists, will not get again tokens = fs.addDelegationTokens(renewer, creds); - Assert.assertEquals(0, tokens.length); - Assert.assertEquals(2, creds.numberOfTokens()); + assertEquals(0, tokens.length); + assertEquals(2, creds.numberOfTokens()); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testWarmupEDEKCacheOnStartup() throws Exception { Path zonePath = new Path("/TestEncryptionZone"); fsWrapper.mkdir(zonePath, FsPermission.getDirDefault(), false); @@ -122,8 +126,8 @@ public void testWarmupEDEKCacheOnStartup() throws Exception { @SuppressWarnings("unchecked") KMSClientProvider spy = getKMSClientProvider(); - assertTrue("key queue is empty after creating encryption zone", - spy.getEncKeyQueueSize(TEST_KEY) > 0); + assertTrue(spy.getEncKeyQueueSize(TEST_KEY) > 0, + "key queue is empty after creating encryption zone"); conf.setInt( DFSConfigKeys.DFS_NAMENODE_EDEKCACHELOADER_INITIAL_DELAY_MS_KEY, 0); @@ -151,9 +155,9 @@ public void addDelegationTokenFromWebhdfsFileSystem() throws Exception { Credentials creds = new Credentials(); final Token[] tokens = webfs.addDelegationTokens("JobTracker", creds); - Assert.assertEquals(2, tokens.length); - Assert.assertEquals(KMSDelegationToken.TOKEN_KIND_STR, + assertEquals(2, tokens.length); + assertEquals(KMSDelegationToken.TOKEN_KIND_STR, tokens[1].getKind().toString()); - Assert.assertEquals(2, creds.numberOfTokens()); + assertEquals(2, creds.numberOfTokens()); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReservedRawPaths.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReservedRawPaths.java index 0eb06056db9fe..d7065d52f7d6c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReservedRawPaths.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReservedRawPaths.java @@ -42,9 +42,10 @@ import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.test.GenericTestUtils; -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.junit.jupiter.api.Timeout; import org.slf4j.LoggerFactory; import org.slf4j.event.Level; @@ -52,10 +53,10 @@ import static org.apache.hadoop.hdfs.DFSTestUtil.verifyFilesNotEqual; import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains; import static org.apache.hadoop.test.GenericTestUtils.assertMatches; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestReservedRawPaths { @@ -72,7 +73,7 @@ public class TestReservedRawPaths { protected static final EnumSet< CreateEncryptionZoneFlag > NO_TRASH = EnumSet.of(CreateEncryptionZoneFlag.NO_TRASH); - @Before + @BeforeEach public void setup() throws Exception { conf = new HdfsConfiguration(); fsHelper = new FileSystemTestHelper(); @@ -98,7 +99,7 @@ public void setup() throws Exception { DFSTestUtil.createKey(TEST_KEY, cluster, conf); } - @After + @AfterEach public void teardown() { if (cluster != null) { cluster.shutdown(); @@ -110,7 +111,8 @@ public void teardown() { * Verify resolving path will return an iip that tracks if the original * path was a raw path. */ - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testINodesInPath() throws IOException { FSDirectory fsd = cluster.getNamesystem().getFSDirectory(); final String path = "/path"; @@ -134,7 +136,8 @@ public void testINodesInPath() throws IOException { * Compare the raw and non-raw versions of the non-encrypted file to ensure * they're the same. */ - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testReadWriteRaw() throws Exception { // Create a base file for comparison final Path baseFile = new Path("/base"); @@ -164,21 +167,22 @@ private void assertPathEquals(Path p1, Path p2) throws IOException { * Use accessTime and modificationTime as substitutes for INode to check * for resolution to the same underlying file. */ - assertEquals("Access times not equal", p1Stat.getAccessTime(), - p2Stat.getAccessTime()); - assertEquals("Modification times not equal", p1Stat.getModificationTime(), - p2Stat.getModificationTime()); - assertEquals("pathname1 not equal", p1, - Path.getPathWithoutSchemeAndAuthority(p1Stat.getPath())); - assertEquals("pathname1 not equal", p2, - Path.getPathWithoutSchemeAndAuthority(p2Stat.getPath())); + assertEquals(p1Stat.getAccessTime(), + p2Stat.getAccessTime(), "Access times not equal"); + assertEquals(p1Stat.getModificationTime(), + p2Stat.getModificationTime(), "Modification times not equal"); + assertEquals(p1, Path.getPathWithoutSchemeAndAuthority(p1Stat.getPath()), + "pathname1 not equal"); + assertEquals(p2, Path.getPathWithoutSchemeAndAuthority(p2Stat.getPath()), + "pathname1 not equal"); } /** * Tests that getFileStatus on raw and non raw resolve to the same * file. */ - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testGetFileStatus() throws Exception { final Path zone = new Path("zone"); final Path slashZone = new Path("/", zone); @@ -200,7 +204,8 @@ public void testGetFileStatus() throws Exception { assertPathEquals(ezEncFile, ezRawEncFile); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testReservedRoot() throws Exception { final Path root = new Path("/"); final Path rawRoot = new Path("/.reserved/raw"); @@ -210,7 +215,8 @@ public void testReservedRoot() throws Exception { } /* Verify mkdir works ok in .reserved/raw directory. */ - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testReservedRawMkdir() throws Exception { final Path zone = new Path("zone"); final Path slashZone = new Path("/", zone); @@ -229,7 +235,8 @@ public void testReservedRawMkdir() throws Exception { fs.delete(rawDir1EZ, true); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testRelativePathnames() throws Exception { final Path baseFileRaw = new Path("/.reserved/raw/base"); final int len = 8192; @@ -248,7 +255,8 @@ public void testRelativePathnames() throws Exception { "/.reserved/../.reserved/raw/../raw/base")); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testUserReadAccessOnly() throws Exception { final Path zone = new Path("zone"); final Path slashZone = new Path("/", zone); @@ -319,7 +327,8 @@ public Object run() throws Exception { }); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testListDotReserved() throws Exception { // Create a base file for comparison final Path baseFileRaw = new Path("/.reserved/raw/base"); @@ -343,11 +352,12 @@ public void testListDotReserved() throws Exception { } final FileStatus[] fileStatuses = fs.listStatus(new Path("/.reserved/raw")); - assertEquals("expected 1 entry", fileStatuses.length, 1); + assertEquals(fileStatuses.length, 1, "expected 1 entry"); assertMatches(fileStatuses[0].getPath().toString(), "/.reserved/raw/base"); } - @Test(timeout = 120000) + @Test + @Timeout(value = 120) public void testListRecursive() throws Exception { Path rootPath = new Path("/"); Path p = rootPath; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryption.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryption.java index a17cce55429e1..6ad3b5d692e0c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryption.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryption.java @@ -60,25 +60,25 @@ import org.apache.hadoop.ipc.RetriableException; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.Whitebox; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import org.junit.rules.Timeout; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.slf4j.LoggerFactory; import org.slf4j.event.Level; /** * Test class for re-encryption. */ +@Timeout(180) public class TestReencryption { protected static final org.slf4j.Logger LOG = @@ -105,10 +105,7 @@ protected String getKeyProviderURI() { testRootDir.toString(), "test.jks").toUri(); } - @Rule - public Timeout globalTimeout = new Timeout(180 * 1000); - - @Before + @BeforeEach public void setup() throws Exception { conf = new HdfsConfiguration(); fsHelper = new FileSystemTestHelper(); @@ -151,7 +148,7 @@ protected void setProvider() { .setKeyProvider(cluster.getNameNode().getNamesystem().getProvider()); } - @After + @AfterEach public void teardown() { if (cluster != null) { cluster.shutdown(); @@ -414,8 +411,8 @@ public void testRestartAfterReencrypt() throws Exception { assertKeyVersionEquals(encFile0, fei0new); assertKeyVersionEquals(encFile9, fei9new); - assertNull("Re-encrypt queue should be empty after restart", - getReencryptionStatus().getNextUnprocessedZone()); + assertNull(getReencryptionStatus().getNextUnprocessedZone(), + "Re-encrypt queue should be empty after restart"); } @Test @@ -494,18 +491,18 @@ public void testRestartDuringReencrypt() throws Exception { restartClusterDisableReencrypt(); final Long zoneId = fsn.getFSDirectory().getINode(zone.toString()).getId(); - assertEquals("Re-encrypt should restore to the last checkpoint zone", - zoneId, getReencryptionStatus().getNextUnprocessedZone()); - assertEquals("Re-encrypt should restore to the last checkpoint file", - new Path(subdir, "4").toString(), - getEzManager().getZoneStatus(zone.toString()).getLastCheckpointFile()); + assertEquals(zoneId, getReencryptionStatus().getNextUnprocessedZone(), + "Re-encrypt should restore to the last checkpoint zone"); + assertEquals(new Path(subdir, "4").toString(), + getEzManager().getZoneStatus(zone.toString()).getLastCheckpointFile(), + "Re-encrypt should restore to the last checkpoint file"); getEzManager().resumeReencryptForTesting(); waitForReencryptedZones(1); assertKeyVersionChanged(encFile0, fei0); assertKeyVersionChanged(encFile9, fei9); - assertNull("Re-encrypt queue should be empty after restart", - getReencryptionStatus().getNextUnprocessedZone()); + assertNull(getReencryptionStatus().getNextUnprocessedZone(), + "Re-encrypt queue should be empty after restart"); assertEquals(11, getZoneStatus(zone.toString()).getFilesReencrypted()); } @@ -545,8 +542,8 @@ public void testRestartAfterReencryptAndCheckpoint() throws Exception { assertKeyVersionEquals(encFile0, fei0new); assertKeyVersionEquals(encFile9, fei9new); - assertNull("Re-encrypt queue should be empty after restart", - getReencryptionStatus().getNextUnprocessedZone()); + assertNull(getReencryptionStatus().getNextUnprocessedZone(), + "Re-encrypt queue should be empty after restart"); } @Test @@ -613,12 +610,12 @@ private void verifyZoneStatus(final Path zone, final FileEncryptionInfo fei, */ private void verifyZoneCompletionTime(final ZoneReencryptionStatus zs) { assertNotNull(zs); - assertTrue("Completion time should be positive. " + zs.getCompletionTime(), - zs.getCompletionTime() > 0); - assertTrue("Completion time " + zs.getCompletionTime() - + " should be no less than submission time " - + zs.getSubmissionTime(), - zs.getCompletionTime() >= zs.getSubmissionTime()); + assertTrue(zs.getCompletionTime() > 0, + "Completion time should be positive. " + zs.getCompletionTime()); + assertTrue(zs.getCompletionTime() >= zs.getSubmissionTime(), + "Completion time " + zs.getCompletionTime() + + " should be no less than submission time " + + zs.getSubmissionTime()); } @Test @@ -1381,15 +1378,15 @@ public Boolean get() { private void assertKeyVersionChanged(final Path file, final FileEncryptionInfo original) throws Exception { final FileEncryptionInfo actual = getFileEncryptionInfo(file); - assertNotEquals("KeyVersion should be different", - original.getEzKeyVersionName(), actual.getEzKeyVersionName()); + assertNotEquals(original.getEzKeyVersionName(), actual.getEzKeyVersionName(), + "KeyVersion should be different"); } private void assertKeyVersionEquals(final Path file, final FileEncryptionInfo expected) throws Exception { final FileEncryptionInfo actual = getFileEncryptionInfo(file); - assertEquals("KeyVersion should be the same", - expected.getEzKeyVersionName(), actual.getEzKeyVersionName()); + assertEquals(expected.getEzKeyVersionName(), actual.getEzKeyVersionName(), + "KeyVersion should be the same"); } @Test diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryptionWithKMS.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryptionWithKMS.java index 642d5e5370752..beedb40ba43fb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryptionWithKMS.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryptionWithKMS.java @@ -24,16 +24,16 @@ import org.apache.hadoop.crypto.key.kms.server.KMSWebApp; import org.apache.hadoop.crypto.key.kms.server.MiniKMS; import org.apache.hadoop.fs.Path; -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 java.io.File; import java.io.FileWriter; import java.io.Writer; import java.util.UUID; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test class for re-encryption with minikms. @@ -49,7 +49,7 @@ protected String getKeyProviderURI() { miniKMS.getKMSUrl().toExternalForm().replace("://", "@"); } - @Before + @BeforeEach public void setup() throws Exception { kmsDir = "target/test-classes/" + UUID.randomUUID().toString(); final File dir = new File(kmsDir); @@ -60,7 +60,7 @@ public void setup() throws Exception { super.setup(); } - @After + @AfterEach public void teardown() { super.teardown(); if (miniKMS != null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestFSMainOperationsWebHdfs.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestFSMainOperationsWebHdfs.java index e88937a6297d7..99ad6b000f27a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestFSMainOperationsWebHdfs.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestFSMainOperationsWebHdfs.java @@ -17,8 +17,12 @@ */ package org.apache.hadoop.hdfs.web; -import static org.mockito.Mockito.spy; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; import java.io.IOException; import java.io.InputStream; @@ -45,10 +49,9 @@ import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.test.GenericTestUtils; import org.slf4j.event.Level; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TestFSMainOperationsWebHdfs extends FSMainOperationsBaseTest { { @@ -68,7 +71,7 @@ protected FileSystem createFileSystem() throws Exception { return fileSystem; } - @BeforeClass + @BeforeAll public static void setupCluster() { final Configuration conf = new Configuration(); conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024); @@ -100,7 +103,7 @@ public FileSystem run() throws Exception { } } - @AfterClass + @AfterAll public static void shutdownCluster() { if (cluster != null) { cluster.shutdown(); @@ -125,16 +128,16 @@ public void testConcat() throws Exception { Path catPath = new Path("/test/hadoop/catFile"); DFSTestUtil.createFile(fSys, catPath, 1024, (short) 3, 0); - Assert.assertTrue(exists(fSys, catPath)); + assertTrue(exists(fSys, catPath)); fSys.concat(catPath, paths); - Assert.assertFalse(exists(fSys, paths[0])); - Assert.assertFalse(exists(fSys, paths[1])); - Assert.assertFalse(exists(fSys, paths[2])); + assertFalse(exists(fSys, paths[0])); + assertFalse(exists(fSys, paths[1])); + assertFalse(exists(fSys, paths[2])); FileStatus fileStatus = fSys.getFileStatus(catPath); - Assert.assertEquals(1024*4, fileStatus.getLen()); + assertEquals(1024*4, fileStatus.getLen()); } @Test @@ -152,16 +155,15 @@ public void testTruncate() throws Exception { boolean isReady = fSys.truncate(file, newLength); - Assert.assertTrue("Recovery is not expected.", isReady); + assertTrue(isReady, "Recovery is not expected."); FileStatus fileStatus = fSys.getFileStatus(file); - Assert.assertEquals(fileStatus.getLen(), newLength); + assertEquals(fileStatus.getLen(), newLength); AppendTestUtil.checkFullFile(fSys, file, newLength, data, file.toString()); ContentSummary cs = fSys.getContentSummary(dir); - Assert.assertEquals("Bad disk space usage", cs.getSpaceConsumed(), - newLength * repl); - Assert.assertTrue("Deleted", fSys.delete(dir, true)); + assertEquals(cs.getSpaceConsumed(), newLength * repl, "Bad disk space usage"); + assertTrue(fSys.delete(dir, true), "Deleted"); } // Test that WebHdfsFileSystem.jsonParse() closes the connection's input @@ -196,11 +198,11 @@ public int read() throws IOException { doReturn(myIn).when(spyConn).getInputStream(); try { - Assert.assertFalse(closedInputStream); + assertFalse(closedInputStream); WebHdfsFileSystem.jsonParse(spyConn, false); - Assert.assertTrue(closedInputStream); + assertTrue(closedInputStream); } catch(IOException ioe) { - junit.framework.TestCase.fail(); + fail(); } conn.disconnect(); } @@ -209,21 +211,21 @@ public int read() throws IOException { @Test public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception { Path testDir = getTestRootPath(fSys, "test/hadoop"); - Assert.assertFalse(exists(fSys, testDir)); + assertFalse(exists(fSys, testDir)); fSys.mkdirs(testDir); - Assert.assertTrue(exists(fSys, testDir)); + assertTrue(exists(fSys, testDir)); createFile(getTestRootPath(fSys, "test/hadoop/file")); Path testSubDir = getTestRootPath(fSys, "test/hadoop/file/subdir"); try { fSys.mkdirs(testSubDir); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } try { - Assert.assertFalse(exists(fSys, testSubDir)); + assertFalse(exists(fSys, testSubDir)); } catch(AccessControlException e) { // also okay for HDFS. } @@ -231,12 +233,12 @@ public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception { Path testDeepSubDir = getTestRootPath(fSys, "test/hadoop/file/deep/sub/dir"); try { fSys.mkdirs(testDeepSubDir); - Assert.fail("Should throw IOException."); + fail("Should throw IOException."); } catch (IOException e) { // expected } try { - Assert.assertFalse(exists(fSys, testDeepSubDir)); + assertFalse(exists(fSys, testDeepSubDir)); } catch(AccessControlException e) { // also okay for HDFS. } diff --git a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextCreateMkdir.java b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextCreateMkdir.java index 7bddbd0e8f112..fbf7de7443483 100644 --- a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextCreateMkdir.java +++ b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextCreateMkdir.java @@ -21,7 +21,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileContextCreateMkdirBaseTest; import org.apache.hadoop.fs.aliyun.oss.AliyunOSSTestUtils; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import java.io.IOException; @@ -31,7 +31,7 @@ public class TestOSSFileContextCreateMkdir extends FileContextCreateMkdirBaseTest { - @Before + @BeforeEach public void setUp() throws IOException, Exception { Configuration conf = new Configuration(); fc = AliyunOSSTestUtils.createTestFileContext(conf); diff --git a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextMainOperations.java b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextMainOperations.java index 36d02df4c4219..cc5e2a27c2a1e 100644 --- a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextMainOperations.java +++ b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextMainOperations.java @@ -21,9 +21,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileContextMainOperationsBaseTest; import org.apache.hadoop.fs.aliyun.oss.AliyunOSSTestUtils; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -33,7 +33,7 @@ public class TestOSSFileContextMainOperations extends FileContextMainOperationsBaseTest { - @Before + @BeforeEach public void setUp() throws IOException, Exception { Configuration conf = new Configuration(); fc = AliyunOSSTestUtils.createTestFileContext(conf); @@ -46,25 +46,25 @@ protected boolean listCorruptedBlocksSupported() { } @Test - @Ignore + @Disabled public void testCreateFlagAppendExistingFile() throws IOException { // append not supported, so test removed } @Test - @Ignore + @Disabled public void testCreateFlagCreateAppendExistingFile() throws IOException { // append not supported, so test removed } @Test - @Ignore + @Disabled public void testSetVerifyChecksum() throws IOException { // checksums ignored, so test ignored } @Test - @Ignore + @Disabled public void testBuilderCreateAppendExistingFile() throws IOException { // append not supported, so test removed } diff --git a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextStatistics.java b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextStatistics.java index cbb7d85f6099b..b54e260795b89 100644 --- a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextStatistics.java +++ b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextStatistics.java @@ -18,14 +18,15 @@ package org.apache.hadoop.fs.aliyun.oss.fileContext; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FCStatisticsBaseTest; import org.apache.hadoop.fs.FileContext; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.aliyun.oss.AliyunOSSTestUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.net.URI; @@ -34,7 +35,7 @@ */ public class TestOSSFileContextStatistics extends FCStatisticsBaseTest { - @Before + @BeforeEach public void setUp() throws Exception { Configuration conf = new Configuration(); fc = AliyunOSSTestUtils.createTestFileContext(conf); @@ -43,7 +44,7 @@ public void setUp() throws Exception { FileContext.clearStatistics(); } - @After + @AfterEach public void tearDown() throws Exception { if (fc != null) { fc.delete(fileContextTestHelper.getTestRootPath(fc, "test"), true); @@ -53,13 +54,13 @@ public void tearDown() throws Exception { @Override protected void verifyReadBytes(FileSystem.Statistics stats) { // one blockSize for read, one for pread - Assert.assertEquals(2 * blockSize, stats.getBytesRead()); + assertEquals(2 * blockSize, stats.getBytesRead()); } @Override protected void verifyWrittenBytes(FileSystem.Statistics stats) { // no extra bytes are written - Assert.assertEquals(blockSize, stats.getBytesWritten()); + assertEquals(blockSize, stats.getBytesWritten()); } @Override diff --git a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextURI.java b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextURI.java index cde708e3e0bc0..3944aad9ca4fa 100644 --- a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextURI.java +++ b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/fileContext/TestOSSFileContextURI.java @@ -22,9 +22,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileContextURIBase; import org.apache.hadoop.fs.aliyun.oss.AliyunOSSTestUtils; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -33,7 +33,7 @@ */ public class TestOSSFileContextURI extends FileContextURIBase { - @Before + @BeforeEach public void setUp() throws IOException, Exception { Configuration conf = new Configuration(); fc1 = AliyunOSSTestUtils.createTestFileContext(conf); @@ -43,7 +43,7 @@ public void setUp() throws IOException, Exception { } @Test - @Ignore + @Disabled public void testFileStatus() throws IOException { // test ignored // (the statistics tested with this method are not relevant for an OSSFS) diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AFSMainOperations.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AFSMainOperations.java index 3c405cb7c5101..88b6ce169925e 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AFSMainOperations.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AFSMainOperations.java @@ -20,19 +20,18 @@ import java.io.IOException; -import org.assertj.core.api.Assertions; -import org.junit.Ignore; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSMainOperationsBaseTest; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.contract.s3a.S3AContract; +import org.junit.jupiter.api.Disabled; import static org.apache.hadoop.fs.s3a.S3ATestUtils.createTestPath; import static org.apache.hadoop.fs.s3a.S3ATestUtils.isCreatePerformanceEnabled; import static org.apache.hadoop.fs.s3a.S3ATestUtils.setPerformanceFlags; import static org.apache.hadoop.fs.s3a.S3ATestUtils.skipIfAnalyticsAcceleratorEnabled; +import static org.assertj.core.api.Assertions.assertThat; /** * S3A Test suite for the FSMainOperationsBaseTest tests. @@ -64,17 +63,17 @@ public void tearDown() throws Exception { } @Override - @Ignore("Permissions not supported") + @Disabled("Permissions not supported") public void testListStatusThrowsExceptionForUnreadableDir() { } @Override - @Ignore("Permissions not supported") + @Disabled("Permissions not supported") public void testGlobStatusThrowsExceptionForUnreadableDir() { } @Override - @Ignore("local FS path setup broken") + @Disabled("local FS path setup broken") public void testCopyToLocalWithUseRawLocalFileSystemOption() throws Exception { } @@ -106,7 +105,7 @@ public void testOverwrite() throws IOException { boolean createPerformance = isCreatePerformanceEnabled(fSys); try { super.testOverwrite(); - Assertions.assertThat(createPerformance) + assertThat(createPerformance) .describedAs("create performance enabled") .isFalse(); } catch (AssertionError e) { diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextCreateMkdir.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextCreateMkdir.java index 095d2239eed70..65ec8678012e8 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextCreateMkdir.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextCreateMkdir.java @@ -16,7 +16,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileContextCreateMkdirBaseTest; import org.apache.hadoop.fs.s3a.S3ATestUtils; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import static org.apache.hadoop.fs.s3a.S3ATestUtils.setPerformanceFlags; @@ -26,7 +26,7 @@ public class ITestS3AFileContextCreateMkdir extends FileContextCreateMkdirBaseTest { - @Before + @BeforeEach public void setUp() throws Exception { Configuration conf = setPerformanceFlags( new Configuration(), diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextCreateMkdirCreatePerf.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextCreateMkdirCreatePerf.java index 68dde70bfeb50..1834476ae321d 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextCreateMkdirCreatePerf.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextCreateMkdirCreatePerf.java @@ -13,8 +13,8 @@ */ package org.apache.hadoop.fs.s3a.fileContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileContextCreateMkdirBaseTest; @@ -30,7 +30,7 @@ public class ITestS3AFileContextCreateMkdirCreatePerf extends FileContextCreateMkdirBaseTest { - @Before + @BeforeEach public void setUp() throws Exception { Configuration conf = setPerformanceFlags( new Configuration(), diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextMainOperations.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextMainOperations.java index cc630484a131c..1e7829c901d00 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextMainOperations.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextMainOperations.java @@ -17,9 +17,9 @@ import java.io.IOException; import java.util.UUID; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileContextMainOperationsBaseTest; @@ -36,7 +36,7 @@ public class ITestS3AFileContextMainOperations extends FileContextMainOperationsBaseTest { - @Before + @BeforeEach public void setUp() throws IOException, Exception { Configuration conf = setPerformanceFlags( new Configuration(), @@ -65,25 +65,25 @@ protected boolean listCorruptedBlocksSupported() { } @Test - @Ignore + @Disabled public void testCreateFlagAppendExistingFile() throws IOException { //append not supported, so test removed } @Test - @Ignore + @Disabled public void testCreateFlagCreateAppendExistingFile() throws IOException { //append not supported, so test removed } @Test - @Ignore + @Disabled public void testBuilderCreateAppendExistingFile() throws IOException { // not supported } @Test - @Ignore + @Disabled public void testSetVerifyChecksum() throws IOException { //checksums ignored, so test removed } diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextStatistics.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextStatistics.java index 5b489c1c39c7a..f81a3882d8918 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextStatistics.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextStatistics.java @@ -26,11 +26,11 @@ import org.apache.hadoop.fs.s3a.S3ATestUtils; import org.apache.hadoop.fs.s3a.auth.STSClientFactory; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import static org.apache.hadoop.fs.s3a.S3ATestUtils.skipIfAnalyticsAcceleratorEnabled; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * S3a implementation of FCStatisticsBaseTest. @@ -43,7 +43,7 @@ public class ITestS3AFileContextStatistics extends FCStatisticsBaseTest { private Path testRootPath; private Configuration conf; - @Before + @BeforeEach public void setUp() throws Exception { conf = new Configuration(); // Analytics accelerator currently does not support IOStatistics, this will be added as @@ -57,7 +57,7 @@ public void setUp() throws Exception { FileContext.clearStatistics(); } - @After + @AfterEach public void tearDown() throws Exception { S3ATestUtils.callQuietly(LOG, () -> fc != null && fc.delete(testRootPath, true)); @@ -66,7 +66,7 @@ public void tearDown() throws Exception { @Override protected void verifyReadBytes(FileSystem.Statistics stats) { // one blockSize for read, one for pread - Assert.assertEquals(2 * blockSize, stats.getBytesRead()); + assertEquals(2 * blockSize, stats.getBytesRead()); } /** @@ -76,8 +76,8 @@ protected void verifyReadBytes(FileSystem.Statistics stats) { @Override protected void verifyWrittenBytes(FileSystem.Statistics stats) { //No extra bytes are written - Assert.assertEquals("Mismatch in bytes written", blockSize, - stats.getBytesWritten()); + assertEquals(blockSize, + stats.getBytesWritten(), "Mismatch in bytes written"); } @Override diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextURI.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextURI.java index 54161d10128e5..5674a463b6611 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextURI.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/fileContext/ITestS3AFileContextURI.java @@ -17,9 +17,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileContextURIBase; import org.apache.hadoop.fs.s3a.S3ATestUtils; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import static org.apache.hadoop.fs.s3a.S3ATestUtils.setPerformanceFlags; @@ -30,7 +30,7 @@ public class ITestS3AFileContextURI extends FileContextURIBase { private Configuration conf; - @Before + @BeforeEach public void setUp() throws IOException, Exception { conf = setPerformanceFlags( new Configuration(), @@ -42,7 +42,7 @@ public void setUp() throws IOException, Exception { } @Test - @Ignore + @Disabled public void testFileStatus() throws IOException { // test disabled // (the statistics tested with this method are not relevant for an S3FS) diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlFileContextCreateMkdirLive.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlFileContextCreateMkdirLive.java index 5166de12e4046..8e022cecfdd56 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlFileContextCreateMkdirLive.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlFileContextCreateMkdirLive.java @@ -19,14 +19,15 @@ package org.apache.hadoop.fs.adl.live; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.DelegateToFileSystem; import org.apache.hadoop.fs.FileContext; import org.apache.hadoop.fs.FileContextCreateMkdirBaseTest; import org.apache.hadoop.fs.FileContextTestHelper; import org.apache.hadoop.fs.FileSystem; -import org.junit.Assume; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import java.net.URI; import java.util.UUID; @@ -38,9 +39,9 @@ public class TestAdlFileContextCreateMkdirLive extends FileContextCreateMkdirBaseTest { private static final String KEY_FILE_SYSTEM = "test.fs.adl.name"; - @BeforeClass + @BeforeAll public static void skipTestCheck() { - Assume.assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); + assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); } @Override diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlFileContextMainOperationsLive.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlFileContextMainOperationsLive.java index ee10da79aa9b0..b046f53abd20b 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlFileContextMainOperationsLive.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlFileContextMainOperationsLive.java @@ -19,11 +19,12 @@ package org.apache.hadoop.fs.adl.live; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URI; @@ -39,9 +40,9 @@ public class TestAdlFileContextMainOperationsLive private static final String KEY_FILE_SYSTEM = "test.fs.adl.name"; - @BeforeClass + @BeforeAll public static void skipTestCheck() { - Assume.assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); + assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); } @Override @@ -81,7 +82,7 @@ public void testWorkingDirectory() throws Exception { // set. // The test is failing with NPE on windows platform only, with Linux // platform test passes. - Assume.assumeTrue(false); + assumeTrue(false); } else { super.testWorkingDirectory(); } @@ -89,11 +90,11 @@ public void testWorkingDirectory() throws Exception { @Override public void testUnsupportedSymlink() throws IOException { - Assume.assumeTrue(false); + assumeTrue(false); } @Test public void testSetVerifyChecksum() throws IOException { - Assume.assumeTrue(false); + assumeTrue(false); } } \ No newline at end of file diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestNativeAzureFileSystemOperationsMocked.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestNativeAzureFileSystemOperationsMocked.java index 89ed381aee55d..f70787e366442 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestNativeAzureFileSystemOperationsMocked.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestNativeAzureFileSystemOperationsMocked.java @@ -23,6 +23,7 @@ import org.apache.hadoop.fs.FSMainOperationsBaseTest; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.junit.jupiter.api.BeforeEach; public class TestNativeAzureFileSystemOperationsMocked extends FSMainOperationsBaseTest { @@ -34,6 +35,7 @@ public TestNativeAzureFileSystemOperationsMocked (){ super(TEST_ROOT_DIR); } + @BeforeEach @Override public void setUp() throws Exception { fSys = AzureBlobStorageTestAccount.createMock().getFileSystem(); diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemMainOperation.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemMainOperation.java index 41abfe84943b8..6956dbcade26a 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemMainOperation.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemMainOperation.java @@ -18,11 +18,10 @@ package org.apache.hadoop.fs.azurebfs; -import org.junit.Ignore; - import org.apache.hadoop.fs.FSMainOperationsBaseTest; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.azurebfs.contract.ABFSContractTestBinding; +import org.junit.jupiter.api.Disabled; /** * Test AzureBlobFileSystem main operations. @@ -63,14 +62,14 @@ protected FileSystem createFileSystem() throws Exception { } @Override - @Ignore("Permission check for getFileInfo doesn't match the HdfsPermissionsGuide") + @Disabled("Permission check for getFileInfo doesn't match the HdfsPermissionsGuide") public void testListStatusThrowsExceptionForUnreadableDir() { // Permission Checks: // https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-hdfs/HdfsPermissionsGuide.html } @Override - @Ignore("Permission check for getFileInfo doesn't match the HdfsPermissionsGuide") + @Disabled("Permission check for getFileInfo doesn't match the HdfsPermissionsGuide") public void testGlobStatusThrowsExceptionForUnreadableDir() { // Permission Checks: // https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-hdfs/HdfsPermissionsGuide.html