diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestAzureADTokenProvider.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestAzureADTokenProvider.java index a68e6ac2bb07d..aeb986731f651 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestAzureADTokenProvider.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestAzureADTokenProvider.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Path; import com.microsoft.azure.datalake.store.oauth2.DeviceCodeTokenProvider; import com.microsoft.azure.datalake.store.oauth2.MsiTokenProvider; @@ -44,16 +45,16 @@ .AZURE_AD_TOKEN_PROVIDER_TYPE_KEY; import static org.apache.hadoop.fs.adl.AdlConfKeys.DEVICE_CODE_CLIENT_APP_ID; import static org.apache.hadoop.fs.adl.TokenProviderType.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.apache.hadoop.security.ProviderUtils; import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; /** * Test appropriate token provider is loaded as per configuration. @@ -65,8 +66,8 @@ public class TestAzureADTokenProvider { private static final String CLIENT_SECRET = "MY_CLIENT_SECRET"; private static final String REFRESH_URL = "http://localhost:8080/refresh"; - @Rule - public final TemporaryFolder tempDir = new TemporaryFolder(); + @TempDir + private Path tempDir; @Test public void testRefreshTokenProvider() @@ -81,7 +82,7 @@ public void testRefreshTokenProvider() AdlFileSystem fileSystem = new AdlFileSystem(); fileSystem.initialize(uri, conf); AccessTokenProvider tokenProvider = fileSystem.getTokenProvider(); - Assert.assertTrue(tokenProvider instanceof RefreshTokenBasedTokenProvider); + assertTrue(tokenProvider instanceof RefreshTokenBasedTokenProvider); } @Test @@ -97,7 +98,7 @@ public void testClientCredTokenProvider() AdlFileSystem fileSystem = new AdlFileSystem(); fileSystem.initialize(uri, conf); AccessTokenProvider tokenProvider = fileSystem.getTokenProvider(); - Assert.assertTrue(tokenProvider instanceof ClientCredsTokenProvider); + assertTrue(tokenProvider instanceof ClientCredsTokenProvider); } @Test @@ -110,7 +111,7 @@ public void testMSITokenProvider() AdlFileSystem fileSystem = new AdlFileSystem(); fileSystem.initialize(uri, conf); AccessTokenProvider tokenProvider = fileSystem.getTokenProvider(); - Assert.assertTrue(tokenProvider instanceof MsiTokenProvider); + assertTrue(tokenProvider instanceof MsiTokenProvider); } @Test @@ -129,7 +130,7 @@ public void testDeviceCodeTokenProvider() AdlFileSystem fileSystem = new AdlFileSystem(); fileSystem.initialize(uri, conf); AccessTokenProvider tokenProvider = fileSystem.getTokenProvider(); - Assert.assertTrue(tokenProvider instanceof DeviceCodeTokenProvider); + assertTrue(tokenProvider instanceof DeviceCodeTokenProvider); } } @@ -145,7 +146,7 @@ public void testCustomCredTokenProvider() AdlFileSystem fileSystem = new AdlFileSystem(); fileSystem.initialize(uri, conf); AccessTokenProvider tokenProvider = fileSystem.getTokenProvider(); - Assert.assertTrue(tokenProvider instanceof SdkTokenProviderAdapter); + assertTrue(tokenProvider instanceof SdkTokenProviderAdapter); } @Test @@ -157,7 +158,7 @@ public void testInvalidProviderConfigurationForType() AdlFileSystem fileSystem = new AdlFileSystem(); try { fileSystem.initialize(uri, conf); - Assert.fail("Initialization should have failed due no token provider " + fail("Initialization should have failed due no token provider " + "configuration"); } catch (IllegalArgumentException e) { GenericTestUtils.assertExceptionContains( @@ -179,17 +180,17 @@ public void testInvalidProviderConfigurationForClassPath() "wrong.classpath.CustomMockTokenProvider"); try { fileSystem.initialize(uri, conf); - Assert.fail("Initialization should have failed due invalid provider " + fail("Initialization should have failed due invalid provider " + "configuration"); } catch (RuntimeException e) { - Assert.assertTrue( + assertTrue( e.getMessage().contains("wrong.classpath.CustomMockTokenProvider")); } } private CredentialProvider createTempCredProvider(Configuration conf) throws URISyntaxException, IOException { - final File file = tempDir.newFile("test.jks"); + final File file = tempDir.resolve("test.jks").toFile(); final URI jks = ProviderUtils.nestURIForLocalJavaKeyStoreProvider( file.toURI()); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, @@ -217,7 +218,7 @@ public void testRefreshTokenWithCredentialProvider() fileSystem.initialize(uri, conf); RefreshTokenBasedTokenProvider expected = new RefreshTokenBasedTokenProvider(CLIENT_ID, REFRESH_TOKEN); - Assert.assertTrue(EqualsBuilder.reflectionEquals(expected, + assertTrue(EqualsBuilder.reflectionEquals(expected, fileSystem.getTokenProvider())); } @@ -236,7 +237,7 @@ public void testRefreshTokenWithCredentialProviderFallback() fileSystem.initialize(uri, conf); RefreshTokenBasedTokenProvider expected = new RefreshTokenBasedTokenProvider(CLIENT_ID, REFRESH_TOKEN); - Assert.assertTrue(EqualsBuilder.reflectionEquals(expected, + assertTrue(EqualsBuilder.reflectionEquals(expected, fileSystem.getTokenProvider())); } @@ -263,7 +264,7 @@ public void testClientCredWithCredentialProvider() fileSystem.initialize(uri, conf); ClientCredsTokenProvider expected = new ClientCredsTokenProvider( REFRESH_URL, CLIENT_ID, CLIENT_SECRET); - Assert.assertTrue(EqualsBuilder.reflectionEquals(expected, + assertTrue(EqualsBuilder.reflectionEquals(expected, fileSystem.getTokenProvider())); } @@ -283,7 +284,7 @@ public void testClientCredWithCredentialProviderFallback() fileSystem.initialize(uri, conf); ClientCredsTokenProvider expected = new ClientCredsTokenProvider( REFRESH_URL, CLIENT_ID, CLIENT_SECRET); - Assert.assertTrue(EqualsBuilder.reflectionEquals(expected, + assertTrue(EqualsBuilder.reflectionEquals(expected, fileSystem.getTokenProvider())); } diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestRelativePathFormation.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestRelativePathFormation.java index 334c372e7b106..618a934fdf846 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestRelativePathFormation.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestRelativePathFormation.java @@ -20,8 +20,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URI; @@ -31,6 +30,7 @@ .AZURE_AD_TOKEN_PROVIDER_CLASS_KEY; import static org.apache.hadoop.fs.adl.AdlConfKeys .AZURE_AD_TOKEN_PROVIDER_TYPE_KEY; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * This class verifies path conversion to SDK. @@ -48,17 +48,17 @@ public void testToRelativePath() throws URISyntaxException, IOException { fs.initialize(new URI("adl://temp.account.net"), configuration); - Assert.assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr"))); - Assert.assertEquals("/usr", + assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr"))); + assertEquals("/usr", fs.toRelativeFilePath(new Path("adl://temp.account.net/usr"))); // When working directory is set. fs.setWorkingDirectory(new Path("/a/b/")); - Assert.assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr"))); - Assert.assertEquals("/a/b/usr", fs.toRelativeFilePath(new Path("usr"))); - Assert.assertEquals("/usr", + assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr"))); + assertEquals("/a/b/usr", fs.toRelativeFilePath(new Path("usr"))); + assertEquals("/usr", fs.toRelativeFilePath(new Path("adl://temp.account.net/usr"))); - Assert.assertEquals("/usr", + assertEquals("/usr", fs.toRelativeFilePath(new Path("wasb://temp.account.net/usr"))); } diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestValidateConfiguration.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestValidateConfiguration.java index 0308a693421a2..eb67d48d04b3f 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestValidateConfiguration.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/TestValidateConfiguration.java @@ -20,7 +20,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.hadoop.fs.adl.AdlConfKeys.ADL_BLOCK_SIZE; import static org.apache.hadoop.fs.adl.AdlConfKeys @@ -57,7 +57,7 @@ .TOKEN_PROVIDER_TYPE_REFRESH_TOKEN; import static org.apache.hadoop.fs.adl.AdlConfKeys.WRITE_BUFFER_SIZE_KEY; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.io.FileOutputStream; diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlDifferentSizeWritesLive.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlDifferentSizeWritesLive.java index 5421e0b772b01..d2f57bc19d728 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlDifferentSizeWritesLive.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlDifferentSizeWritesLive.java @@ -23,13 +23,10 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.adl.common.Parallelized; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.IOException; import java.net.URISyntaxException; @@ -39,19 +36,21 @@ import java.util.UUID; import static org.apache.hadoop.fs.adl.AdlConfKeys.WRITE_BUFFER_SIZE_KEY; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Verify data integrity with different data sizes with buffer size. */ -@RunWith(Parallelized.class) public class TestAdlDifferentSizeWritesLive { private static Random rand = new Random(); private int totalSize; private int chunkSize; - public TestAdlDifferentSizeWritesLive(int totalSize, int chunkSize) { - this.totalSize = totalSize; - this.chunkSize = chunkSize; + public void initTestAdlDifferentSizeWritesLive(int pTotalSize, int pChunkSize) { + this.totalSize = pTotalSize; + this.chunkSize = pChunkSize; } public static byte[] getRandomByteArrayData(int size) { @@ -60,8 +59,6 @@ public static byte[] getRandomByteArrayData(int size) { return b; } - @Parameterized.Parameters(name = "{index}: Data Size [{0}] ; Chunk Size " - + "[{1}]") public static Collection testDataForIntegrityTest() { return Arrays.asList( new Object[][] {{4 * 1024, 1 * 1024}, {4 * 1024, 7 * 1024}, @@ -71,7 +68,7 @@ public static Collection testDataForIntegrityTest() { {10 * 1024, 8 * 1024}}); } - @BeforeClass + @BeforeAll public static void cleanUpParent() throws IOException, URISyntaxException { if (AdlStorageConfiguration.isContractTestEnabled()) { Path path = new Path("/test/dataIntegrityCheck/"); @@ -80,14 +77,15 @@ public static void cleanUpParent() throws IOException, URISyntaxException { } } - @Before + @BeforeEach public void setup() throws Exception { - org.junit.Assume - .assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); + assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); } - @Test - public void testDataIntegrity() throws IOException { + @MethodSource("testDataForIntegrityTest") + @ParameterizedTest(name = "{index}: Data Size [{0}] ; Chunk Size [{1}]") + public void testDataIntegrity(int pTotalSize, int pChunkSize) throws IOException { + initTestAdlDifferentSizeWritesLive(pTotalSize, pChunkSize); Path path = new Path( "/test/dataIntegrityCheck/" + UUID.randomUUID().toString()); FileSystem fs = null; @@ -117,7 +115,7 @@ public void testDataIntegrity() throws IOException { FSDataInputStream in = fs.open(path); in.readFully(0, actualData); in.close(); - Assert.assertArrayEquals(expectedData, actualData); - Assert.assertTrue(fs.delete(path, true)); + assertArrayEquals(expectedData, actualData); + assertTrue(fs.delete(path, true)); } } diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlInternalCreateNonRecursive.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlInternalCreateNonRecursive.java index 7e11a548f803f..afaca97df6d05 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlInternalCreateNonRecursive.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlInternalCreateNonRecursive.java @@ -23,14 +23,9 @@ import org.apache.hadoop.fs.FileAlreadyExistsException; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.adl.common.Parallelized; import org.apache.hadoop.fs.permission.FsPermission; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -38,10 +33,13 @@ import java.util.Collection; import java.util.UUID; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + /** * Test createNonRecursive API. */ -@RunWith(Parallelized.class) public class TestAdlInternalCreateNonRecursive { private Path inputFileName; private FsPermission inputPermission; @@ -51,9 +49,9 @@ public class TestAdlInternalCreateNonRecursive { private Class expectedExceptionType; private FileSystem adlStore; - public TestAdlInternalCreateNonRecursive(String testScenario, String fileName, + public void initTestAdlInternalCreateNonRecursive(String testScenario, String fileName, FsPermission permission, boolean override, boolean fileAlreadyExist, - boolean parentAlreadyExist, Class exceptionType) { + boolean parentAlreadyExist, Class exceptionType) throws Exception { // Random parent path for each test so that parallel execution does not fail // other running test. @@ -64,9 +62,9 @@ public TestAdlInternalCreateNonRecursive(String testScenario, String fileName, inputOverride = override; inputParentAlreadyExist = parentAlreadyExist; expectedExceptionType = exceptionType; + setUp(); } - @Parameterized.Parameters(name = "{0}") public static Collection adlCreateNonRecursiveTestData() throws UnsupportedEncodingException { /* @@ -92,14 +90,18 @@ public static Collection adlCreateNonRecursiveTestData() IOException.class }*/}); } - @Before public void setUp() throws Exception { - Assume.assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); + assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); adlStore = AdlStorageConfiguration.createStorageConnector(); } - @Test - public void testCreateNonRecursiveFunctionality() throws IOException { + @MethodSource("adlCreateNonRecursiveTestData") + @ParameterizedTest(name = "{0}") + public void testCreateNonRecursiveFunctionality(String testScenario, String fileName, + FsPermission permission, boolean override, boolean fileAlreadyExist, + boolean parentAlreadyExist, Class exceptionType) throws Exception { + initTestAdlInternalCreateNonRecursive(testScenario, fileName, permission, + override, fileAlreadyExist, parentAlreadyExist, exceptionType); if (inputFileAlreadyExist) { FileSystem.create(adlStore, inputFileName, inputPermission); } @@ -122,12 +124,12 @@ public void testCreateNonRecursiveFunctionality() throws IOException { throw e; } - Assert.assertEquals(expectedExceptionType, e.getClass()); + assertEquals(expectedExceptionType, e.getClass()); return; } if (expectedExceptionType != null) { - Assert.fail("CreateNonRecursive should have failed with exception " + fail("CreateNonRecursive should have failed with exception " + expectedExceptionType.getName()); } } diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlSdkConfiguration.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlSdkConfiguration.java index 27004db578788..5a3ad6bd7e1ce 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlSdkConfiguration.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlSdkConfiguration.java @@ -23,15 +23,16 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.adl.AdlFileSystem; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URISyntaxException; import static org.apache.hadoop.fs.adl.AdlConfKeys.ADL_HTTP_TIMEOUT; import static org.apache.hadoop.fs.adl.AdlConfKeys.ADL_SSL_CHANNEL_MODE; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Tests interactions with SDK and ensures configuration is having the desired @@ -55,10 +56,10 @@ public void testDefaultTimeout() throws IOException { } // Skip this test if we can't get a real FS - Assume.assumeNotNull(fs); + assumeTrue(fs != null); effectiveTimeout = fs.getAdlClient().getDefaultTimeout(); - Assert.assertFalse("A negative timeout is not supposed to take effect", - effectiveTimeout < 0); + assertFalse(effectiveTimeout < 0, + "A negative timeout is not supposed to take effect"); conf = AdlStorageConfiguration.getConfiguration(); conf.setInt(ADL_HTTP_TIMEOUT, 17); @@ -71,8 +72,8 @@ public void testDefaultTimeout() throws IOException { } effectiveTimeout = fs.getAdlClient().getDefaultTimeout(); - Assert.assertEquals("Timeout is getting set", - effectiveTimeout, 17); + assertEquals( + effectiveTimeout, 17, "Timeout is getting set"); // The default value may vary by SDK, so that value is not tested here. } @@ -98,11 +99,11 @@ public void testSSLChannelMode(SSLChannelMode expectedMode, conf = AdlStorageConfiguration.getConfiguration(); conf.set(ADL_SSL_CHANNEL_MODE, sslChannelModeConfigValue); fs = (AdlFileSystem) (AdlStorageConfiguration.createStorageConnector(conf)); - Assume.assumeNotNull(fs); + assumeTrue(fs != null); SSLChannelMode sslChannelMode = fs.getAdlClient().getSSLChannelMode(); - Assert.assertEquals( + assertEquals(expectedMode, sslChannelMode, "Unexpected SSL Channel Mode for adl.ssl.channel.mode config value : " - + sslChannelModeConfigValue, expectedMode, sslChannelMode); + + sslChannelModeConfigValue); } } diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlSupportedCharsetInPath.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlSupportedCharsetInPath.java index d80b6bf96820f..f053ff3626125 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlSupportedCharsetInPath.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestAdlSupportedCharsetInPath.java @@ -19,16 +19,17 @@ package org.apache.hadoop.fs.adl.live; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.adl.common.Parallelized; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +42,6 @@ * Test supported ASCII, UTF-8 character set supported by Adl storage file * system on file/folder operation. */ -@RunWith(Parallelized.class) public class TestAdlSupportedCharsetInPath { private static final String TEST_ROOT = "/test/"; @@ -49,11 +49,10 @@ public class TestAdlSupportedCharsetInPath { .getLogger(TestAdlSupportedCharsetInPath.class); private String path; - public TestAdlSupportedCharsetInPath(String filePath) { + public void initTestAdlSupportedCharsetInPath(String filePath) { path = filePath; } - @Parameterized.Parameters(name = "{0}") public static Collection adlCharTestData() throws UnsupportedEncodingException { @@ -246,7 +245,7 @@ private static void fillUnicodes(ArrayList filePathList) { filePathList.add("bob΄"); } - @AfterClass + @AfterAll public static void testReport() throws IOException, URISyntaxException { if (!AdlStorageConfiguration.isContractTestEnabled()) { return; @@ -256,23 +255,22 @@ public static void testReport() throws IOException, URISyntaxException { fs.delete(new Path(TEST_ROOT), true); } - @Test - public void testAllowedSpecialCharactersMkdir() + @MethodSource("adlCharTestData") + @ParameterizedTest(name = "filePath {0}") + public void testAllowedSpecialCharactersMkdir(String filePath) throws IOException, URISyntaxException { + initTestAdlSupportedCharsetInPath(filePath); Path parentPath = new Path(TEST_ROOT, UUID.randomUUID().toString() + "/"); Path specialFile = new Path(parentPath, path); FileSystem fs = AdlStorageConfiguration.createStorageConnector(); - Assert.assertTrue("Mkdir failed : " + specialFile, fs.mkdirs(specialFile)); - Assert.assertTrue("File not Found after Mkdir success" + specialFile, - fs.exists(specialFile)); - Assert.assertTrue("Not listed under parent " + parentPath, - contains(fs.listStatus(parentPath), - fs.makeQualified(specialFile).toString())); - Assert.assertTrue("Delete failed : " + specialFile, - fs.delete(specialFile, true)); - Assert.assertFalse("File still exist after delete " + specialFile, - fs.exists(specialFile)); + assertTrue(fs.mkdirs(specialFile), "Mkdir failed : " + specialFile); + assertTrue(fs.exists(specialFile), + "File not Found after Mkdir success" + specialFile); + assertTrue(contains(fs.listStatus(parentPath), + fs.makeQualified(specialFile).toString()), "Not listed under parent " + parentPath); + assertTrue(fs.delete(specialFile, true), "Delete failed : " + specialFile); + assertFalse(fs.exists(specialFile), "File still exist after delete " + specialFile); } private boolean contains(FileStatus[] statuses, String remotePath) { @@ -286,49 +284,46 @@ private boolean contains(FileStatus[] statuses, String remotePath) { return false; } - @Before + @BeforeEach public void setup() throws Exception { - org.junit.Assume - .assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); + assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); } - @Test - public void testAllowedSpecialCharactersRename() + @MethodSource("adlCharTestData") + @ParameterizedTest(name = "filePath {0}") + public void testAllowedSpecialCharactersRename(String filePath) throws IOException, URISyntaxException { - + initTestAdlSupportedCharsetInPath(filePath); String parentPath = TEST_ROOT + UUID.randomUUID().toString() + "/"; Path specialFile = new Path(parentPath + path); Path anotherLocation = new Path(parentPath + UUID.randomUUID().toString()); FileSystem fs = AdlStorageConfiguration.createStorageConnector(); - Assert.assertTrue("Could not create " + specialFile.toString(), - fs.createNewFile(specialFile)); - Assert.assertTrue( - "Failed to rename " + specialFile.toString() + " --> " + anotherLocation - .toString(), fs.rename(specialFile, anotherLocation)); - Assert.assertFalse("File should not be present after successful rename : " - + specialFile.toString(), fs.exists(specialFile)); - Assert.assertTrue("File should be present after successful rename : " - + anotherLocation.toString(), fs.exists(anotherLocation)); - Assert.assertFalse( - "Listed under parent whereas expected not listed : " + parentPath, - contains(fs.listStatus(new Path(parentPath)), - fs.makeQualified(specialFile).toString())); + assertTrue(fs.createNewFile(specialFile), + "Could not create " + specialFile.toString()); + assertTrue(fs.rename(specialFile, anotherLocation), + "Failed to rename " + specialFile.toString() + " --> " + anotherLocation.toString()); + assertFalse(fs.exists(specialFile), "File should not be present after successful rename : " + + specialFile.toString()); + assertTrue(fs.exists(anotherLocation), "File should be present after successful rename : " + + anotherLocation.toString()); + assertFalse(contains(fs.listStatus(new Path(parentPath)), + fs.makeQualified(specialFile).toString()), + "Listed under parent whereas expected not listed : " + parentPath); - Assert.assertTrue( + assertTrue(fs.rename(anotherLocation, specialFile), "Failed to rename " + anotherLocation.toString() + " --> " + specialFile - .toString(), fs.rename(anotherLocation, specialFile)); - Assert.assertTrue( - "File should be present after successful rename : " + "" + specialFile - .toString(), fs.exists(specialFile)); - Assert.assertFalse("File should not be present after successful rename : " - + anotherLocation.toString(), fs.exists(anotherLocation)); + .toString()); + assertTrue(fs.exists(specialFile), + "File should be present after successful rename : " + "" + specialFile.toString()); + assertFalse(fs.exists(anotherLocation), + "File should not be present after successful rename : " + + anotherLocation.toString()); - Assert.assertTrue("Not listed under parent " + parentPath, - contains(fs.listStatus(new Path(parentPath)), - fs.makeQualified(specialFile).toString())); + assertTrue(contains(fs.listStatus(new Path(parentPath)), + fs.makeQualified(specialFile).toString()), "Not listed under parent " + parentPath); - Assert.assertTrue("Failed to delete " + parentPath, - fs.delete(new Path(parentPath), true)); + assertTrue(fs.delete(new Path(parentPath), true), + "Failed to delete " + parentPath); } } \ No newline at end of file diff --git a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestMetadata.java b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestMetadata.java index dbcaa390d6c75..88ed4e20d3e8b 100644 --- a/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestMetadata.java +++ b/hadoop-tools/hadoop-azure-datalake/src/test/java/org/apache/hadoop/fs/adl/live/TestMetadata.java @@ -23,17 +23,18 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.adl.AdlFileSystem; -import org.junit.After; -import org.junit.Assert; -import org.junit.Assume; -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.IOException; import java.io.OutputStream; import java.util.UUID; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * This class is responsible for testing ContentSummary, ListStatus on @@ -48,13 +49,13 @@ public TestMetadata() { parent = new Path("test"); } - @Before + @BeforeEach public void setUp() throws Exception { - Assume.assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); + assumeTrue(AdlStorageConfiguration.isContractTestEnabled()); adlStore = AdlStorageConfiguration.createStorageConnector(); } - @After + @AfterEach public void cleanUp() throws Exception { if (AdlStorageConfiguration.isContractTestEnabled()) { adlStore.delete(parent, true); @@ -72,12 +73,12 @@ public void testContentSummaryOnFile() throws IOException { } out.close(); - Assert.assertTrue(adlStore.isFile(testFile)); + assertTrue(adlStore.isFile(testFile)); ContentSummary summary = adlStore.getContentSummary(testFile); - Assert.assertEquals(1024, summary.getSpaceConsumed()); - Assert.assertEquals(1, summary.getFileCount()); - Assert.assertEquals(0, summary.getDirectoryCount()); - Assert.assertEquals(1024, summary.getLength()); + assertEquals(1024, summary.getSpaceConsumed()); + assertEquals(1, summary.getFileCount()); + assertEquals(0, summary.getDirectoryCount()); + assertEquals(1024, summary.getLength()); } @Test @@ -91,12 +92,12 @@ public void testContentSummaryOnFolder() throws IOException { } out.close(); - Assert.assertTrue(adlStore.isFile(testFile)); + assertTrue(adlStore.isFile(testFile)); ContentSummary summary = adlStore.getContentSummary(parent); - Assert.assertEquals(1024, summary.getSpaceConsumed()); - Assert.assertEquals(1, summary.getFileCount()); - Assert.assertEquals(1, summary.getDirectoryCount()); - Assert.assertEquals(1024, summary.getLength()); + assertEquals(1024, summary.getSpaceConsumed()); + assertEquals(1, summary.getFileCount()); + assertEquals(1, summary.getDirectoryCount()); + assertEquals(1024, summary.getLength()); } @Test @@ -104,11 +105,10 @@ public void listStatusOnFile() throws IOException { Path path = new Path(parent, "a.txt"); FileSystem fs = adlStore; fs.createNewFile(path); - Assert.assertTrue(fs.isFile(path)); + assertTrue(fs.isFile(path)); FileStatus[] statuses = fs.listStatus(path); - Assert - .assertEquals(path.makeQualified(fs.getUri(), fs.getWorkingDirectory()), - statuses[0].getPath()); + assertEquals(path.makeQualified(fs.getUri(), fs.getWorkingDirectory()), + statuses[0].getPath()); } @Test @@ -122,7 +122,7 @@ public void testUserRepresentationConfiguration() throws IOException { // That is non GUID value. fs.setUserGroupRepresentationAsUPN(false); fs.createNewFile(path); - Assert.assertTrue(fs.isFile(path)); + assertTrue(fs.isFile(path)); FileStatus fileStatus = fs.getFileStatus(path); UUID.fromString(fileStatus.getGroup()); UUID.fromString(fileStatus.getOwner());