diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/AbstractWasbTestWithTimeout.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/AbstractWasbTestWithTimeout.java index 5d005bdea5889..ad737b55acf81 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/AbstractWasbTestWithTimeout.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/AbstractWasbTestWithTimeout.java @@ -26,13 +26,15 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.apache.hadoop.test.TestName; +import java.util.concurrent.TimeUnit; + import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Base class for any Wasb test with timeouts & named threads. * This class does not attempt to bind to Azure. */ -@Timeout(AzureTestConstants.AZURE_TEST_TIMEOUT) +@Timeout(value = AzureTestConstants.AZURE_TEST_TIMEOUT, unit = TimeUnit.MILLISECONDS) public class AbstractWasbTestWithTimeout extends Assertions { /** diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/integration/AbstractAzureScaleTest.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/integration/AbstractAzureScaleTest.java index ec56732f3ddd5..7e37a44fe0e0c 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/integration/AbstractAzureScaleTest.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/integration/AbstractAzureScaleTest.java @@ -26,6 +26,8 @@ import org.apache.hadoop.fs.azure.AbstractWasbTestBase; import org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount; +import java.util.concurrent.TimeUnit; + import static org.apache.hadoop.fs.azure.integration.AzureTestUtils.*; /** @@ -34,7 +36,7 @@ * tests if not. * */ -@Timeout(AzureTestConstants.SCALE_TEST_TIMEOUT_MILLIS) +@Timeout(value = AzureTestConstants.SCALE_TEST_TIMEOUT_MILLIS, unit = TimeUnit.MILLISECONDS) public abstract class AbstractAzureScaleTest extends AbstractWasbTestBase implements Sizes { 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 6956dbcade26a..749db790715d5 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 @@ -21,6 +21,8 @@ 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.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; /** @@ -41,12 +43,14 @@ public ITestAzureBlobFileSystemMainOperation () throws Exception { binding = new ABFSContractTestBinding(false); } + @BeforeEach @Override public void setUp() throws Exception { binding.setup(); fSys = binding.getFileSystem(); } + @AfterEach @Override public void tearDown() throws Exception { // Note: Because "tearDown()" is called during the testing, diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/TestBlobListXmlParser.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/TestBlobListXmlParser.java index 2b7e04f45dfc4..45e9fcc331963 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/TestBlobListXmlParser.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/TestBlobListXmlParser.java @@ -23,15 +23,15 @@ import javax.xml.parsers.SAXParserFactory; import java.io.ByteArrayInputStream; import java.io.InputStream; -import org.assertj.core.api.Assertions; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import org.apache.hadoop.fs.azurebfs.contracts.services.BlobListResultEntrySchema; import org.apache.hadoop.fs.azurebfs.contracts.services.BlobListResultSchema; import org.apache.hadoop.fs.azurebfs.contracts.services.BlobListXmlParser; +import static org.assertj.core.api.Assertions.assertThat; public class TestBlobListXmlParser { @Test @@ -105,12 +105,12 @@ public void testXMLParser() throws Exception { + ""; BlobListResultSchema listResultSchema = getResultSchema(xmlResponseWithDelimiter); List paths = listResultSchema.paths(); - Assertions.assertThat(paths.size()).isEqualTo(4); - Assertions.assertThat(paths.get(0).isDirectory()).isEqualTo(true); - Assertions.assertThat(paths.get(1).isDirectory()).isEqualTo(true); - Assertions.assertThat(paths.get(2).isDirectory()).isEqualTo(true); - Assertions.assertThat(paths.get(3).isDirectory()).isEqualTo(false); - Assertions.assertThat(listResultSchema.getNextMarker()).isNotNull(); + assertThat(paths.size()).isEqualTo(4); + assertThat(paths.get(0).isDirectory()).isEqualTo(true); + assertThat(paths.get(1).isDirectory()).isEqualTo(true); + assertThat(paths.get(2).isDirectory()).isEqualTo(true); + assertThat(paths.get(3).isDirectory()).isEqualTo(false); + assertThat(listResultSchema.getNextMarker()).isNotNull(); } @Test @@ -124,8 +124,8 @@ public void testEmptyBlobListNullCT() throws Exception { + ""; BlobListResultSchema listResultSchema = getResultSchema(xmlResponse); List paths = listResultSchema.paths(); - Assertions.assertThat(paths.size()).isEqualTo(0); - Assertions.assertThat(listResultSchema.getNextMarker()).isNull(); + assertThat(paths.size()).isEqualTo(0); + assertThat(listResultSchema.getNextMarker()).isNull(); } @Test @@ -140,8 +140,8 @@ public void testEmptyBlobListValidCT() throws Exception { + ""; BlobListResultSchema listResultSchema = getResultSchema(xmlResponse); List paths = listResultSchema.paths(); - Assertions.assertThat(paths.size()).isEqualTo(0); - Assertions.assertThat(listResultSchema.getNextMarker()).isNotNull(); + assertThat(paths.size()).isEqualTo(0); + assertThat(listResultSchema.getNextMarker()).isNotNull(); } @Test @@ -160,8 +160,8 @@ public void testNonEmptyBlobListNullCT() throws Exception { + ""; BlobListResultSchema listResultSchema = getResultSchema(xmlResponse); List paths = listResultSchema.paths(); - Assertions.assertThat(paths.size()).isEqualTo(1); - Assertions.assertThat(listResultSchema.getNextMarker()).isNull(); + assertThat(paths.size()).isEqualTo(1); + assertThat(listResultSchema.getNextMarker()).isNull(); } private static final ThreadLocal SAX_PARSER_THREAD_LOCAL diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/TestDfsListJsonParser.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/TestDfsListJsonParser.java index d62265ea57f78..3fe6c1b4b691c 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/TestDfsListJsonParser.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/contract/TestDfsListJsonParser.java @@ -21,7 +21,7 @@ import java.io.IOException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.apache.hadoop.fs.azurebfs.contracts.services.DfsListResultSchema; import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultEntrySchema; diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/diagnostics/TestConfigurationValidators.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/diagnostics/TestConfigurationValidators.java index 6a02435fc6e5e..58a60387788e0 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/diagnostics/TestConfigurationValidators.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/diagnostics/TestConfigurationValidators.java @@ -18,8 +18,8 @@ package org.apache.hadoop.fs.azurebfs.diagnostics; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidConfigurationValueException; import org.apache.hadoop.fs.azurebfs.utils.Base64; @@ -36,7 +36,7 @@ /** * Test configuration validators. */ -public class TestConfigurationValidators extends Assert { +public class TestConfigurationValidators extends Assertions { private static final String FAKE_KEY = "FakeKey"; @@ -54,11 +54,14 @@ public void testIntegerConfigValidator() throws Exception { assertEquals(MAX_BUFFER_SIZE, (int) integerConfigurationValidator.validate("104857600")); } - @Test(expected = InvalidConfigurationValueException.class) + @Test public void testIntegerConfigValidatorThrowsIfMissingValidValue() throws Exception { - IntegerConfigurationBasicValidator integerConfigurationValidator = new IntegerConfigurationBasicValidator( - MIN_BUFFER_SIZE, MAX_BUFFER_SIZE, DEFAULT_READ_BUFFER_SIZE, FAKE_KEY, true); - integerConfigurationValidator.validate("3072"); + assertThrows(InvalidConfigurationValueException.class, () -> { + IntegerConfigurationBasicValidator integerConfigurationValidator = + new IntegerConfigurationBasicValidator( + MIN_BUFFER_SIZE, MAX_BUFFER_SIZE, DEFAULT_READ_BUFFER_SIZE, FAKE_KEY, true); + integerConfigurationValidator.validate("3072"); + }); } @Test @@ -73,12 +76,15 @@ public void testIntegerWithOutlierConfigValidator() throws Exception { assertEquals(MAX_LEASE_DURATION, (int) integerConfigurationValidator.validate("60")); } - @Test(expected = InvalidConfigurationValueException.class) + @Test public void testIntegerWithOutlierConfigValidatorThrowsIfMissingValidValue() throws Exception { - IntegerConfigurationBasicValidator integerConfigurationValidator = new IntegerConfigurationBasicValidator( - INFINITE_LEASE_DURATION, MIN_LEASE_DURATION, MAX_LEASE_DURATION, DEFAULT_LEASE_DURATION, FAKE_KEY, - true); - integerConfigurationValidator.validate("14"); + assertThrows(InvalidConfigurationValueException.class, () -> { + IntegerConfigurationBasicValidator integerConfigurationValidator = + new IntegerConfigurationBasicValidator( + INFINITE_LEASE_DURATION, MIN_LEASE_DURATION, MAX_LEASE_DURATION, DEFAULT_LEASE_DURATION, FAKE_KEY, + true); + integerConfigurationValidator.validate("14"); + }); } @Test @@ -91,11 +97,13 @@ public void testLongConfigValidator() throws Exception { assertEquals(MAX_BUFFER_SIZE, (long) longConfigurationValidator.validate("104857600")); } - @Test(expected = InvalidConfigurationValueException.class) + @Test public void testLongConfigValidatorThrowsIfMissingValidValue() throws Exception { - LongConfigurationBasicValidator longConfigurationValidator = new LongConfigurationBasicValidator( - MIN_BUFFER_SIZE, MAX_BUFFER_SIZE, DEFAULT_READ_BUFFER_SIZE, FAKE_KEY, true); - longConfigurationValidator.validate(null); + assertThrows(InvalidConfigurationValueException.class, () -> { + LongConfigurationBasicValidator longConfigurationValidator = new LongConfigurationBasicValidator( + MIN_BUFFER_SIZE, MAX_BUFFER_SIZE, DEFAULT_READ_BUFFER_SIZE, FAKE_KEY, true); + longConfigurationValidator.validate(null); + }); } @Test @@ -107,10 +115,13 @@ public void testBooleanConfigValidator() throws Exception { assertEquals(false, booleanConfigurationValidator.validate(null)); } - @Test(expected = InvalidConfigurationValueException.class) + @Test public void testBooleanConfigValidatorThrowsIfMissingValidValue() throws Exception { - BooleanConfigurationBasicValidator booleanConfigurationValidator = new BooleanConfigurationBasicValidator(FAKE_KEY, false, true); - booleanConfigurationValidator.validate("almostTrue"); + assertThrows(InvalidConfigurationValueException.class, () -> { + BooleanConfigurationBasicValidator booleanConfigurationValidator = + new BooleanConfigurationBasicValidator(FAKE_KEY, false, true); + booleanConfigurationValidator.validate("almostTrue"); + }); } @Test @@ -121,10 +132,13 @@ public void testStringConfigValidator() throws Exception { assertEquals("someValue", stringConfigurationValidator.validate("someValue")); } - @Test(expected = InvalidConfigurationValueException.class) + @Test public void testStringConfigValidatorThrowsIfMissingValidValue() throws Exception { - StringConfigurationBasicValidator stringConfigurationValidator = new StringConfigurationBasicValidator(FAKE_KEY, "value", true); - stringConfigurationValidator.validate(null); + assertThrows(InvalidConfigurationValueException.class, () -> { + StringConfigurationBasicValidator stringConfigurationValidator = + new StringConfigurationBasicValidator(FAKE_KEY, "value", true); + stringConfigurationValidator.validate(null); + }); } @Test @@ -136,9 +150,12 @@ public void testBase64StringConfigValidator() throws Exception { assertEquals(encodedVal, base64StringConfigurationValidator.validate(encodedVal)); } - @Test(expected = InvalidConfigurationValueException.class) + @Test public void testBase64StringConfigValidatorThrowsIfMissingValidValue() throws Exception { - Base64StringConfigurationBasicValidator base64StringConfigurationValidator = new Base64StringConfigurationBasicValidator(FAKE_KEY, "value", true); - base64StringConfigurationValidator.validate("some&%Value"); + assertThrows(InvalidConfigurationValueException.class, () -> { + Base64StringConfigurationBasicValidator base64StringConfigurationValidator = + new Base64StringConfigurationBasicValidator(FAKE_KEY, "value", true); + base64StringConfigurationValidator.validate("some&%Value"); + }); } } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/extensions/KerberizedAbfsCluster.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/extensions/KerberizedAbfsCluster.java index 35444f8e4455b..49c96bb5f7244 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/extensions/KerberizedAbfsCluster.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/extensions/KerberizedAbfsCluster.java @@ -44,7 +44,7 @@ import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION; import static org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytabAndReturnUGI; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * composite service for adding kerberos login for ABFS @@ -256,8 +256,8 @@ public void loginPrincipal() throws IOException { * General assertion that security is turred on for a cluster. */ public static void assertSecurityEnabled() { - assertTrue("Security is needed for this test", - UserGroupInformation.isSecurityEnabled()); + assertTrue(UserGroupInformation.isSecurityEnabled(), + "Security is needed for this test"); } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsBackoffMetrics.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsBackoffMetrics.java index 02b25520877f3..b8ce3ba411c0c 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsBackoffMetrics.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsBackoffMetrics.java @@ -18,9 +18,8 @@ package org.apache.hadoop.fs.azurebfs.services; -import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.apache.hadoop.fs.azurebfs.enums.AbfsBackoffMetricsEnum.NUMBER_OF_REQUESTS_SUCCEEDED; import static org.apache.hadoop.fs.azurebfs.enums.AbfsBackoffMetricsEnum.TOTAL_NUMBER_OF_REQUESTS; @@ -29,6 +28,7 @@ import static org.apache.hadoop.fs.azurebfs.enums.RetryValue.TWO; import static org.apache.hadoop.fs.azurebfs.enums.StatisticTypeEnum.TYPE_COUNTER; import static org.apache.hadoop.fs.azurebfs.enums.StatisticTypeEnum.TYPE_GAUGE; +import static org.assertj.core.api.Assertions.assertThat; public class TestAbfsBackoffMetrics { private AbfsBackoffMetrics metrics; @@ -38,7 +38,7 @@ public class TestAbfsBackoffMetrics { /** * Sets up the test environment by initializing the AbfsBackoffMetrics instance. */ - @Before + @BeforeEach public void setUp() { metrics = new AbfsBackoffMetrics(); } @@ -48,12 +48,12 @@ public void setUp() { */ @Test public void retrievesMetricNamesBasedOnStatisticType() { - String[] counterMetrics = metrics.getMetricNamesByType(TYPE_COUNTER); - String[] gaugeMetrics = metrics.getMetricNamesByType(TYPE_GAUGE); - Assertions.assertThat(counterMetrics.length) + String[] counterMetrics = metrics.getMetricNamesByType(TYPE_COUNTER); + String[] gaugeMetrics = metrics.getMetricNamesByType(TYPE_GAUGE); + assertThat(counterMetrics.length) .describedAs("Counter metrics should have 22 elements") .isEqualTo(TOTAL_COUNTERS); - Assertions.assertThat(gaugeMetrics.length) + assertThat(gaugeMetrics.length) .describedAs("Gauge metrics should have 21 elements") .isEqualTo(TOTAL_GAUGES); } @@ -64,10 +64,10 @@ public void retrievesMetricNamesBasedOnStatisticType() { @Test public void retrievesValueOfSpecificMetric() { metrics.setMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, 5, ONE); - Assertions.assertThat(metrics.getMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, ONE)) + assertThat(metrics.getMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, ONE)) .describedAs("Number of request succeeded for retry 1 should be 5") .isEqualTo(5); - Assertions.assertThat(metrics.getMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, TWO)) + assertThat(metrics.getMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, TWO)) .describedAs("Number of request succeeded for other retries except 1 should be 0") .isEqualTo(0); } @@ -78,10 +78,10 @@ public void retrievesValueOfSpecificMetric() { @Test public void incrementsValueOfSpecificMetric() { metrics.incrementMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, ONE); - Assertions.assertThat(metrics.getMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, ONE)) + assertThat(metrics.getMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, ONE)) .describedAs("Number of request succeeded for retry 1 should be 1") .isEqualTo(1); - Assertions.assertThat(metrics.getMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, THREE)) + assertThat(metrics.getMetricValue(NUMBER_OF_REQUESTS_SUCCEEDED, THREE)) .describedAs("Number of request succeeded for other retries except 1 should be 0") .isEqualTo(0); } @@ -91,10 +91,10 @@ public void incrementsValueOfSpecificMetric() { */ @Test public void returnsStringRepresentationOfEmptyBackoffMetrics() { - Assertions.assertThat(metrics.getMetricValue(TOTAL_NUMBER_OF_REQUESTS)) + assertThat(metrics.getMetricValue(TOTAL_NUMBER_OF_REQUESTS)) .describedAs("String representation of backoff metrics should be empty") .isEqualTo(0); - Assertions.assertThat(metrics.toString()) + assertThat(metrics.toString()) .describedAs("String representation of backoff metrics should be empty") .isEmpty(); } @@ -105,10 +105,10 @@ public void returnsStringRepresentationOfEmptyBackoffMetrics() { @Test public void returnsStringRepresentationOfBackoffMetrics() { metrics.incrementMetricValue(TOTAL_NUMBER_OF_REQUESTS); - Assertions.assertThat(metrics.getMetricValue(TOTAL_NUMBER_OF_REQUESTS)) + assertThat(metrics.getMetricValue(TOTAL_NUMBER_OF_REQUESTS)) .describedAs("String representation of backoff metrics should not be empty") .isEqualTo(1); - Assertions.assertThat(metrics.toString()) + assertThat(metrics.toString()) .describedAs("String representation of backoff metrics should not be empty") .contains("$TR=1"); } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java index 2f433b2b400a1..fe481970e0b9a 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java @@ -22,9 +22,7 @@ import java.net.URL; import java.util.Map; -import org.assertj.core.api.Assertions; -import org.junit.Test; -import org.mockito.Mockito; +import org.junit.jupiter.api.Test; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.azurebfs.AbfsConfiguration; @@ -38,7 +36,11 @@ import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_ACCOUNT_NAME; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_FORMAT; import static org.apache.hadoop.fs.azurebfs.services.AbfsClient.ABFS_CLIENT_TIMER_THREAD_NAME; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; /** * Unit test cases for the AbfsClient class. @@ -59,7 +61,7 @@ public void testTimerInitializationWithoutMetricCollection() throws Exception { AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME); abfsConfiguration.unset(FS_AZURE_METRIC_FORMAT); - AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd"))); + AbfsCounters abfsCounters = spy(new AbfsCountersImpl(new URI("abcd"))); AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); // Get an instance of AbfsClient. @@ -70,12 +72,12 @@ public void testTimerInitializationWithoutMetricCollection() throws Exception { null, abfsClientContext); - Assertions.assertThat(client.getTimer()) + assertThat(client.getTimer()) .describedAs("Timer should not be initialized") .isNull(); // Check if a thread with the name "abfs-timer-client" exists - Assertions.assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) + assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) .describedAs("Expected thread 'abfs-timer-client' not found") .isEqualTo(false); client.close(); @@ -95,7 +97,7 @@ public void testTimerInitializationWithMetricCollection() throws Exception { configuration.set(FS_AZURE_METRIC_ACCOUNT_KEY, Base64.encode(ACCOUNT_KEY.getBytes())); AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME); - AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd"))); + AbfsCounters abfsCounters = spy(new AbfsCountersImpl(new URI("abcd"))); AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); // Get an instance of AbfsClient. @@ -106,19 +108,19 @@ public void testTimerInitializationWithMetricCollection() throws Exception { null, abfsClientContext); - Assertions.assertThat(client.getTimer()) + assertThat(client.getTimer()) .describedAs("Timer should be initialized") .isNotNull(); // Check if a thread with the name "abfs-timer-client" exists - Assertions.assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) + assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) .describedAs("Expected thread 'abfs-timer-client' not found") .isEqualTo(true); client.close(); // Check if the thread is removed after closing the client Thread.sleep(SLEEP_DURATION_MS); - Assertions.assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) + assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) .describedAs("Unexpected thread 'abfs-timer-client' found") .isEqualTo(false); } @@ -154,10 +156,10 @@ private boolean isThreadRunning(String threadName) { public static void mockAbfsOperationCreation(final AbfsClient abfsClient, final MockIntercept mockIntercept, int failedCall) throws Exception { int[] flag = new int[1]; - Mockito.doAnswer(answer -> { + doAnswer(answer -> { if (flag[0] == failedCall) { flag[0] += 1; - AbfsRestOperation op = Mockito.spy( + AbfsRestOperation op = spy( new AbfsRestOperation( answer.getArgument(0), abfsClient, @@ -166,12 +168,12 @@ public static void mockAbfsOperationCreation(final AbfsClient abfsClient, answer.getArgument(3), abfsClient.getAbfsConfiguration() )); - Mockito.doAnswer((answer1) -> { + doAnswer((answer1) -> { mockIntercept.answer(op, answer1); return null; }).when(op) .execute(any()); - Mockito.doReturn(true).when(op).isARetriedRequest(); + doReturn(true).when(op).isARetriedRequest(); return op; } flag[0] += 1; diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClientThrottlingAnalyzer.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClientThrottlingAnalyzer.java index 22649cd190d83..69dc0a607cbf2 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClientThrottlingAnalyzer.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClientThrottlingAnalyzer.java @@ -23,12 +23,12 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.azurebfs.AbfsConfiguration; import org.apache.hadoop.fs.contract.ContractTestUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_ANALYSIS_PERIOD; import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.TEST_CONFIGURATION_FILE_NAME; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests for AbfsClientThrottlingAnalyzer. @@ -61,32 +61,28 @@ private void fuzzyValidate(long expected, long actual, double percentage) { final double lowerBound = Math.max(expected - percentage / 100 * expected, 0); final double upperBound = expected + percentage / 100 * expected; - assertTrue( - String.format( - "The actual value %1$d is not within the expected range: " - + "[%2$.2f, %3$.2f].", - actual, - lowerBound, - upperBound), - actual >= lowerBound && actual <= upperBound); + assertTrue(actual >= lowerBound && actual <= upperBound, String.format( + "The actual value %1$d is not within the expected range: " + + "[%2$.2f, %3$.2f].", + actual, + lowerBound, + upperBound)); } private void validate(long expected, long actual) { - assertEquals( + assertEquals(expected, actual, String.format("The actual value %1$d is not the expected value %2$d.", - actual, - expected), - expected, actual); + actual, + expected)); } private void validateLessThanOrEqual(long maxExpected, long actual) { - assertTrue( + assertTrue(actual < maxExpected, String.format( - "The actual value %1$d is not less than or equal to the maximum" - + " expected value %2$d.", - actual, - maxExpected), - actual < maxExpected); + "The actual value %1$d is not less than or equal to the maximum" + + " expected value %2$d.", + actual, + maxExpected)); } /** diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsHttpOperation.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsHttpOperation.java index 36914a4e4f365..7353810d91054 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsHttpOperation.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsHttpOperation.java @@ -23,10 +23,10 @@ import java.net.URL; import java.net.URLEncoder; -import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.apache.hadoop.fs.azurebfs.utils.UriUtils; +import static org.assertj.core.api.Assertions.assertThat; public class TestAbfsHttpOperation { @@ -100,17 +100,16 @@ private void testIfMaskAndEncodeSuccessful(final String scenario, final String url, final String expectedMaskedUrl) throws UnsupportedEncodingException, MalformedURLException { - Assertions.assertThat(UriUtils.getMaskedUrl(new URL(url))) + assertThat(UriUtils.getMaskedUrl(new URL(url))) .describedAs(url + " (" + scenario + ") after masking should be: " - + expectedMaskedUrl).isEqualTo(expectedMaskedUrl); + + expectedMaskedUrl).isEqualTo(expectedMaskedUrl); final String expectedMaskedEncodedUrl = URLEncoder .encode(expectedMaskedUrl, "UTF-8"); - Assertions.assertThat(UriUtils.encodedUrlStr(expectedMaskedUrl)) + assertThat(UriUtils.encodedUrlStr(expectedMaskedUrl)) .describedAs( - url + " (" + scenario + ") after masking and encoding should " - + "be: " + expectedMaskedEncodedUrl) + url + " (" + scenario + ") after masking and encoding should " + + "be: " + expectedMaskedEncodedUrl) .isEqualTo(expectedMaskedEncodedUrl); } - } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsOutputStream.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsOutputStream.java index 0e7cad909040d..5a2ed528d5d5d 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsOutputStream.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsOutputStream.java @@ -24,7 +24,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsPerfTracker.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsPerfTracker.java index 7ff95c6565f98..90c149d0a09c9 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsPerfTracker.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsPerfTracker.java @@ -28,9 +28,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,12 +56,12 @@ public TestAbfsPerfTracker() throws Exception { this.url = new URL("http", "www.microsoft.com", "/bogusFile"); } - @Before + @BeforeEach public void setUp() throws Exception { executorService = Executors.newCachedThreadPool(); } - @After + @AfterEach public void tearDown() throws Exception { executorService.shutdown(); } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsReadFooterMetrics.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsReadFooterMetrics.java index 2f5a45555b945..2759d152874ac 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsReadFooterMetrics.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsReadFooterMetrics.java @@ -18,9 +18,9 @@ package org.apache.hadoop.fs.azurebfs.services; -import org.assertj.core.api.Assertions; -import org.junit.Test; -import org.junit.Before; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; /** * Unit test for Abfs read footer metrics @@ -33,7 +33,7 @@ public class TestAbfsReadFooterMetrics { private static final String TEST_FILE2 = "TestFile2"; private AbfsReadFooterMetrics metrics; - @Before + @BeforeEach public void setUp() { metrics = new AbfsReadFooterMetrics(); } @@ -44,7 +44,7 @@ public void setUp() { @Test public void metricsUpdateForFirstRead() { metrics.updateReadMetrics(TEST_FILE1, LENGTH, CONTENT_LENGTH, NEXT_READ_POS); - Assertions.assertThat(metrics.getTotalFiles()) + assertThat(metrics.getTotalFiles()) .describedAs("Total number of files") .isEqualTo(0); } @@ -56,7 +56,7 @@ public void metricsUpdateForFirstRead() { public void metricsUpdateForSecondRead() { metrics.updateReadMetrics(TEST_FILE1, LENGTH, CONTENT_LENGTH, NEXT_READ_POS); metrics.updateReadMetrics(TEST_FILE1, LENGTH, CONTENT_LENGTH, NEXT_READ_POS+LENGTH); - Assertions.assertThat(metrics.getTotalFiles()) + assertThat(metrics.getTotalFiles()) .describedAs("Total number of files") .isEqualTo(1); } @@ -69,10 +69,10 @@ public void metricsUpdateForOneFile() { metrics.updateReadMetrics(TEST_FILE1, LENGTH, CONTENT_LENGTH, NEXT_READ_POS); metrics.updateReadMetrics(TEST_FILE1, LENGTH, CONTENT_LENGTH, NEXT_READ_POS+LENGTH); metrics.updateReadMetrics(TEST_FILE1, LENGTH, CONTENT_LENGTH, NEXT_READ_POS+2*LENGTH); - Assertions.assertThat(metrics.getTotalFiles()) + assertThat(metrics.getTotalFiles()) .describedAs("Total number of files") .isEqualTo(1); - Assertions.assertThat(metrics.toString()) + assertThat(metrics.toString()) .describedAs("Metrics after reading 3 reads of the same file") .isEqualTo("$NON_PARQUET:$FR=10000.000_20000.000$SR=10000.000_10000.000$FL=50000.000$RL=10000.000"); } @@ -88,10 +88,10 @@ public void metricsUpdateForMultipleFiles() { metrics.updateReadMetrics(TEST_FILE2, LENGTH, CONTENT_LENGTH/2, NEXT_READ_POS); metrics.updateReadMetrics(TEST_FILE2, LENGTH, CONTENT_LENGTH/2, NEXT_READ_POS+LENGTH); metrics.updateReadMetrics(TEST_FILE2, LENGTH, CONTENT_LENGTH/2, NEXT_READ_POS+2*LENGTH); - Assertions.assertThat(metrics.getTotalFiles()) + assertThat(metrics.getTotalFiles()) .describedAs("Total number of files") .isEqualTo(2); - Assertions.assertThat(metrics.toString()) + assertThat(metrics.toString()) .describedAs("Metrics after reading 3 reads of the same file") .isEqualTo("$NON_PARQUET:$FR=10000.000_12500.000$SR=10000.000_10000.000$FL=37500.000$RL=10000.000"); } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRestOperation.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRestOperation.java index a914dd1c27864..1c49afb99bdce 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRestOperation.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRestOperation.java @@ -22,7 +22,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.azurebfs.AbfsConfiguration; import org.apache.hadoop.fs.azurebfs.utils.MetricFormat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.HTTP_METHOD_DELETE; import static org.apache.hadoop.fs.azurebfs.enums.AbfsBackoffMetricsEnum.NUMBER_OF_REQUESTS_FAILED; import static org.apache.hadoop.fs.azurebfs.services.AbfsRestOperationType.DeletePath; @@ -34,7 +34,6 @@ import org.apache.hadoop.fs.azurebfs.AbstractAbfsIntegrationTest; import java.util.ArrayList; import java.util.Arrays; -import org.junit.Assert; import java.net.HttpURLConnection; public class TestAbfsRestOperation extends @@ -83,8 +82,9 @@ public void testBackoffRetryMetrics() throws Exception { } // For retry count greater than the max configured value, the request should fail. - Assert.assertEquals("Number of failed requests does not match expected value.", - "3", String.valueOf(testClient.getAbfsCounters().getAbfsBackoffMetrics().getMetricValue(NUMBER_OF_REQUESTS_FAILED))); + assertEquals("Number of failed requests does not match expected value.", + "3", String.valueOf(testClient.getAbfsCounters().getAbfsBackoffMetrics(). + getMetricValue(NUMBER_OF_REQUESTS_FAILED))); // Close the AzureBlobFileSystem. fs.close(); diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRestOperationMockFailures.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRestOperationMockFailures.java index 4aaa53003d48b..d086a8c96b2f0 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRestOperationMockFailures.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsRestOperationMockFailures.java @@ -23,9 +23,7 @@ import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.util.ArrayList; -import org.assertj.core.api.Assertions; -import org.junit.Test; -import org.mockito.Mockito; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Stubber; import org.apache.hadoop.fs.azurebfs.AbfsConfiguration; @@ -58,9 +56,17 @@ import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.READ_TIMEOUT_JDK_MESSAGE; import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.SOCKET_EXCEPTION_ABBREVIATION; import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.UNKNOWN_HOST_EXCEPTION_ABBREVIATION; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +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; public class TestAbfsRestOperationMockFailures { @@ -195,48 +201,48 @@ public void testClientRequestIdFor503OtherRetry() throws Exception { @Test public void testRetryPolicyWithDifferentFailureReasons() throws Exception { - AbfsClient abfsClient = Mockito.mock(AbfsClient.class); - ExponentialRetryPolicy exponentialRetryPolicy = Mockito.mock( + AbfsClient abfsClient = mock(AbfsClient.class); + ExponentialRetryPolicy exponentialRetryPolicy = mock( ExponentialRetryPolicy.class); - StaticRetryPolicy staticRetryPolicy = Mockito.mock(StaticRetryPolicy.class); - AbfsThrottlingIntercept intercept = Mockito.mock( + StaticRetryPolicy staticRetryPolicy = mock(StaticRetryPolicy.class); + AbfsThrottlingIntercept intercept = mock( AbfsThrottlingIntercept.class); - addGeneralMockBehaviourToAbfsClient(abfsClient, exponentialRetryPolicy, staticRetryPolicy, intercept, Mockito.mock( + addGeneralMockBehaviourToAbfsClient(abfsClient, exponentialRetryPolicy, staticRetryPolicy, intercept, mock( ListResponseData.class)); - AbfsRestOperation abfsRestOperation = Mockito.spy(new AbfsRestOperation( + AbfsRestOperation abfsRestOperation = spy(new AbfsRestOperation( AbfsRestOperationType.ReadFile, abfsClient, "PUT", null, new ArrayList<>(), - Mockito.mock(AbfsConfiguration.class) + mock(AbfsConfiguration.class) )); - AbfsHttpOperation httpOperation = Mockito.mock(AbfsHttpOperation.class); + AbfsHttpOperation httpOperation = mock(AbfsHttpOperation.class); addGeneralMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation); - Stubber stubber = Mockito.doThrow(new SocketTimeoutException(CONNECTION_TIMEOUT_JDK_MESSAGE)); + Stubber stubber = doThrow(new SocketTimeoutException(CONNECTION_TIMEOUT_JDK_MESSAGE)); stubber.doNothing().when(httpOperation).processResponse( nullable(byte[].class), nullable(int.class), nullable(int.class)); when(httpOperation.getStatusCode()).thenReturn(-1).thenReturn(HTTP_UNAVAILABLE); - TracingContext tracingContext = Mockito.mock(TracingContext.class); - Mockito.doNothing().when(tracingContext).setRetryCount(nullable(int.class)); - Mockito.doReturn("").when(httpOperation).getStorageErrorMessage(); - Mockito.doReturn("").when(httpOperation).getStorageErrorCode(); - Mockito.doReturn("HEAD").when(httpOperation).getMethod(); - Mockito.doReturn("").when(httpOperation).getMaskedUrl(); - Mockito.doReturn("").when(httpOperation).getRequestId(); - Mockito.doReturn(EGRESS_OVER_ACCOUNT_LIMIT.getErrorMessage()).when(httpOperation).getStorageErrorMessage(); - Mockito.doReturn(tracingContext).when(abfsRestOperation).createNewTracingContext(any()); + TracingContext tracingContext = mock(TracingContext.class); + doNothing().when(tracingContext).setRetryCount(nullable(int.class)); + doReturn("").when(httpOperation).getStorageErrorMessage(); + doReturn("").when(httpOperation).getStorageErrorCode(); + doReturn("HEAD").when(httpOperation).getMethod(); + doReturn("").when(httpOperation).getMaskedUrl(); + doReturn("").when(httpOperation).getRequestId(); + doReturn(EGRESS_OVER_ACCOUNT_LIMIT.getErrorMessage()).when(httpOperation).getStorageErrorMessage(); + doReturn(tracingContext).when(abfsRestOperation).createNewTracingContext(any()); try { // Operation will fail with CT first and then 503 thereafter. abfsRestOperation.execute(tracingContext); } catch(AbfsRestOperationException ex) { - Assertions.assertThat(ex.getStatusCode()) + assertThat(ex.getStatusCode()) .describedAs("Status Code must be HTTP_UNAVAILABLE(503)") .isEqualTo(HTTP_UNAVAILABLE); } @@ -245,36 +251,36 @@ public void testRetryPolicyWithDifferentFailureReasons() throws Exception { // One for retry count 0 // One for retry count 1 after failing with CT // One for retry count 2 after failing with 503 - Mockito.verify(httpOperation, times(3)).processResponse( + verify(httpOperation, times(3)).processResponse( nullable(byte[].class), nullable(int.class), nullable(int.class)); // Primary Request Failed with CT. Static Retry Policy should be used. - Mockito.verify(abfsClient, Mockito.times(1)) + verify(abfsClient, times(1)) .getRetryPolicy(CONNECTION_TIMEOUT_ABBREVIATION); - Mockito.verify(staticRetryPolicy, Mockito.times(1)) + verify(staticRetryPolicy, times(1)) .shouldRetry(0, -1); - Mockito.verify(staticRetryPolicy, Mockito.times(1)) + verify(staticRetryPolicy, times(1)) .getRetryInterval(1); - Mockito.verify(tracingContext, Mockito.times(1)) + verify(tracingContext, times(1)) .constructHeader(httpOperation, CONNECTION_TIMEOUT_ABBREVIATION, STATIC_RETRY_POLICY_ABBREVIATION); // Assert that exponential Retry Policy was used during second and third Iteration. // Iteration 2 and 3 failed with 503 and should retry was called with retry count 1 and 2 // Before iteration 3 sleep will be computed using exponential retry policy and retry count 2 // Should retry with retry count 2 will return false and no further requests will be made. - Mockito.verify(abfsClient, Mockito.times(2)) + verify(abfsClient, times(2)) .getRetryPolicy(EGRESS_LIMIT_BREACH_ABBREVIATION); - Mockito.verify(exponentialRetryPolicy, Mockito.times(1)) + verify(exponentialRetryPolicy, times(1)) .shouldRetry(1, HTTP_UNAVAILABLE); - Mockito.verify(exponentialRetryPolicy, Mockito.times(1)) + verify(exponentialRetryPolicy, times(1)) .shouldRetry(2, HTTP_UNAVAILABLE); - Mockito.verify(exponentialRetryPolicy, Mockito.times(1)) + verify(exponentialRetryPolicy, times(1)) .getRetryInterval(2); - Mockito.verify(tracingContext, Mockito.times(1)) + verify(tracingContext, times(1)) .constructHeader(httpOperation, EGRESS_LIMIT_BREACH_ABBREVIATION, EXPONENTIAL_RETRY_POLICY_ABBREVIATION); // Assert that intercept.updateMetrics was called 2 times. Both the retried request fails with EGR. - Mockito.verify(intercept, Mockito.times(2)) + verify(intercept, times(2)) .updateMetrics(nullable(AbfsRestOperationType.class), nullable( AbfsHttpOperation.class)); } @@ -284,29 +290,29 @@ private void testClientRequestIdForStatusRetry(int status, String keyExpected, int numOfTimesCSTMetricsUpdated) throws Exception { - AbfsClient abfsClient = Mockito.mock(AbfsClient.class); - ExponentialRetryPolicy exponentialRetryPolicy = Mockito.mock( + AbfsClient abfsClient = mock(AbfsClient.class); + ExponentialRetryPolicy exponentialRetryPolicy = mock( ExponentialRetryPolicy.class); - StaticRetryPolicy staticRetryPolicy = Mockito.mock(StaticRetryPolicy.class); - AbfsThrottlingIntercept intercept = Mockito.mock( + StaticRetryPolicy staticRetryPolicy = mock(StaticRetryPolicy.class); + AbfsThrottlingIntercept intercept = mock( AbfsThrottlingIntercept.class); - addGeneralMockBehaviourToAbfsClient(abfsClient, exponentialRetryPolicy, staticRetryPolicy, intercept, Mockito.mock( + addGeneralMockBehaviourToAbfsClient(abfsClient, exponentialRetryPolicy, staticRetryPolicy, intercept, mock( ListResponseData.class)); // Create a readfile operation that will fail - AbfsRestOperation abfsRestOperation = Mockito.spy(new AbfsRestOperation( + AbfsRestOperation abfsRestOperation = spy(new AbfsRestOperation( AbfsRestOperationType.ReadFile, abfsClient, "PUT", null, new ArrayList<>(), - Mockito.mock(AbfsConfiguration.class) + mock(AbfsConfiguration.class) )); - AbfsHttpOperation httpOperation = Mockito.mock(AbfsHttpOperation.class); + AbfsHttpOperation httpOperation = mock(AbfsHttpOperation.class); addGeneralMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation); - Mockito.doNothing() + doNothing() .doNothing() .when(httpOperation) .processResponse(nullable(byte[].class), nullable(int.class), @@ -314,7 +320,7 @@ private void testClientRequestIdForStatusRetry(int status, int[] statusCount = new int[1]; statusCount[0] = 0; - Mockito.doAnswer(answer -> { + doAnswer(answer -> { if (statusCount[0] <= 10) { statusCount[0]++; return status; @@ -322,19 +328,19 @@ private void testClientRequestIdForStatusRetry(int status, return HTTP_OK; }).when(httpOperation).getStatusCode(); - Mockito.doReturn(serverErrorMessage) + doReturn(serverErrorMessage) .when(httpOperation) .getStorageErrorMessage(); - TracingContext tracingContext = Mockito.mock(TracingContext.class); - Mockito.doNothing().when(tracingContext).setRetryCount(nullable(int.class)); - Mockito.doReturn(tracingContext).when(abfsRestOperation).createNewTracingContext(any()); + TracingContext tracingContext = mock(TracingContext.class); + doNothing().when(tracingContext).setRetryCount(nullable(int.class)); + doReturn(tracingContext).when(abfsRestOperation).createNewTracingContext(any()); int[] count = new int[1]; count[0] = 0; - Mockito.doAnswer(invocationOnMock -> { + doAnswer(invocationOnMock -> { if (count[0] == 1) { - Assertions.assertThat((String) invocationOnMock.getArgument(1)) + assertThat((String) invocationOnMock.getArgument(1)) .isEqualTo(keyExpected); } count[0]++; @@ -342,9 +348,9 @@ private void testClientRequestIdForStatusRetry(int status, }).when(tracingContext).constructHeader(any(), any(), any()); abfsRestOperation.execute(tracingContext); - Assertions.assertThat(count[0]).isEqualTo(2); + assertThat(count[0]).isEqualTo(2); - Mockito.verify(intercept, Mockito.times(numOfTimesCSTMetricsUpdated)).updateMetrics(any(), any()); + verify(intercept, times(numOfTimesCSTMetricsUpdated)).updateMetrics(any(), any()); } @@ -352,28 +358,28 @@ private void testClientRequestIdForTimeoutRetry(Exception[] exceptions, String[] abbreviationsExpected, int len, int numOfCTExceptions) throws Exception { - AbfsClient abfsClient = Mockito.mock(AbfsClient.class); - ExponentialRetryPolicy exponentialRetryPolicy = Mockito.mock( + AbfsClient abfsClient = mock(AbfsClient.class); + ExponentialRetryPolicy exponentialRetryPolicy = mock( ExponentialRetryPolicy.class); - StaticRetryPolicy staticRetryPolicy = Mockito.mock(StaticRetryPolicy.class); - AbfsThrottlingIntercept intercept = Mockito.mock( + StaticRetryPolicy staticRetryPolicy = mock(StaticRetryPolicy.class); + AbfsThrottlingIntercept intercept = mock( AbfsThrottlingIntercept.class); - addGeneralMockBehaviourToAbfsClient(abfsClient, exponentialRetryPolicy, staticRetryPolicy, intercept, Mockito.mock( + addGeneralMockBehaviourToAbfsClient(abfsClient, exponentialRetryPolicy, staticRetryPolicy, intercept, mock( ListResponseData.class)); - AbfsRestOperation abfsRestOperation = Mockito.spy(new AbfsRestOperation( + AbfsRestOperation abfsRestOperation = spy(new AbfsRestOperation( AbfsRestOperationType.ReadFile, abfsClient, "PUT", null, new ArrayList<>(), - Mockito.mock(AbfsConfiguration.class) + mock(AbfsConfiguration.class) )); - AbfsHttpOperation httpOperation = Mockito.mock(AbfsHttpOperation.class); + AbfsHttpOperation httpOperation = mock(AbfsHttpOperation.class); addGeneralMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation); - Stubber stubber = Mockito.doThrow(exceptions[0]); + Stubber stubber = doThrow(exceptions[0]); for (int iteration = 1; iteration < len; iteration++) { stubber.doThrow(exceptions[iteration]); } @@ -383,17 +389,17 @@ private void testClientRequestIdForTimeoutRetry(Exception[] exceptions, .processResponse(nullable(byte[].class), nullable(int.class), nullable(int.class)); - Mockito.doReturn(HTTP_OK).when(httpOperation).getStatusCode(); + doReturn(HTTP_OK).when(httpOperation).getStatusCode(); - TracingContext tracingContext = Mockito.mock(TracingContext.class); - Mockito.doNothing().when(tracingContext).setRetryCount(nullable(int.class)); - Mockito.doReturn(tracingContext).when(abfsRestOperation).createNewTracingContext(any()); + TracingContext tracingContext = mock(TracingContext.class); + doNothing().when(tracingContext).setRetryCount(nullable(int.class)); + doReturn(tracingContext).when(abfsRestOperation).createNewTracingContext(any()); int[] count = new int[1]; count[0] = 0; - Mockito.doAnswer(invocationOnMock -> { + doAnswer(invocationOnMock -> { if (count[0] > 0 && count[0] <= len) { - Assertions.assertThat((String) invocationOnMock.getArgument(1)) + assertThat((String) invocationOnMock.getArgument(1)) .isEqualTo(abbreviationsExpected[count[0] - 1]); } count[0]++; @@ -401,7 +407,7 @@ private void testClientRequestIdForTimeoutRetry(Exception[] exceptions, }).when(tracingContext).constructHeader(any(), any(), any()); abfsRestOperation.execute(tracingContext); - Assertions.assertThat(count[0]).isEqualTo(len + 1); + assertThat(count[0]).isEqualTo(len + 1); /** * Assert that getRetryPolicy was called with @@ -409,7 +415,7 @@ private void testClientRequestIdForTimeoutRetry(Exception[] exceptions, * For every failed request getRetryPolicy will be called three times * It will be called with failureReason CT for every request failing with CT */ - Mockito.verify(abfsClient, Mockito.times( + verify(abfsClient, times( numOfCTExceptions)) .getRetryPolicy(CONNECTION_TIMEOUT_ABBREVIATION); } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestQueryParams.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestQueryParams.java index e6c6993b1dc97..4bb4bace8ecf1 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestQueryParams.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestQueryParams.java @@ -17,13 +17,16 @@ */ package org.apache.hadoop.fs.azurebfs.services; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.HashMap; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.apache.hadoop.fs.azurebfs.oauth2.QueryParams; + /** * Test query params serialization. */ @@ -41,7 +44,7 @@ public void testOneParam() { QueryParams qp = new QueryParams(); qp.add(key, value); - Assert.assertEquals(key + "=" + value, qp.serialize()); + assertEquals(key + "=" + value, qp.serialize()); } @Test @@ -51,11 +54,11 @@ public void testMultipleParams() { qp.add(entry[0], entry[1]); } Map paramMap = constructMap(qp.serialize()); - Assert.assertEquals(PARAM_ARRAY.length, paramMap.size()); + assertEquals(PARAM_ARRAY.length, paramMap.size()); for (String[] entry : PARAM_ARRAY) { - Assert.assertTrue(paramMap.containsKey(entry[0])); - Assert.assertEquals(entry[1], paramMap.get(entry[0])); + assertTrue(paramMap.containsKey(entry[0])); + assertEquals(entry[1], paramMap.get(entry[0])); } } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestRetryReason.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestRetryReason.java index d9d8ee51f9b30..8d8df08951cb2 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestRetryReason.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestRetryReason.java @@ -23,8 +23,7 @@ import java.net.SocketTimeoutException; import java.net.UnknownHostException; -import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.net.HttpURLConnection.HTTP_FORBIDDEN; import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR; @@ -44,12 +43,13 @@ import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.READ_TIMEOUT_JDK_MESSAGE; import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.SOCKET_EXCEPTION_ABBREVIATION; import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.UNKNOWN_HOST_EXCEPTION_ABBREVIATION; +import static org.assertj.core.api.Assertions.assertThat; public class TestRetryReason { @Test public void test4xxStatusRetryReason() { - Assertions.assertThat(RetryReason.getAbbreviation(null, HTTP_FORBIDDEN, null)) + assertThat(RetryReason.getAbbreviation(null, HTTP_FORBIDDEN, null)) .describedAs("Abbreviation for 4xx should be equal to 4xx") .isEqualTo(HTTP_FORBIDDEN + ""); } @@ -57,13 +57,13 @@ public void test4xxStatusRetryReason() { @Test public void testConnectionResetRetryReason() { SocketException connReset = new SocketException(CONNECTION_RESET_MESSAGE.toUpperCase()); - Assertions.assertThat(RetryReason.getAbbreviation(connReset, null, null)).isEqualTo(CONNECTION_RESET_ABBREVIATION); + assertThat(RetryReason.getAbbreviation(connReset, null, null)).isEqualTo(CONNECTION_RESET_ABBREVIATION); } @Test public void testConnectionTimeoutRetryReason() { SocketTimeoutException connectionTimeoutException = new SocketTimeoutException(CONNECTION_TIMEOUT_JDK_MESSAGE); - Assertions.assertThat(RetryReason.getAbbreviation(connectionTimeoutException, null, null)).isEqualTo( + assertThat(RetryReason.getAbbreviation(connectionTimeoutException, null, null)).isEqualTo( CONNECTION_TIMEOUT_ABBREVIATION ); } @@ -71,63 +71,63 @@ public void testConnectionTimeoutRetryReason() { @Test public void testReadTimeoutRetryReason() { SocketTimeoutException connectionTimeoutException = new SocketTimeoutException(READ_TIMEOUT_JDK_MESSAGE); - Assertions.assertThat(RetryReason.getAbbreviation(connectionTimeoutException, null, null)).isEqualTo( + assertThat(RetryReason.getAbbreviation(connectionTimeoutException, null, null)).isEqualTo( READ_TIMEOUT_ABBREVIATION ); } @Test public void testEgressLimitRetryReason() { - Assertions.assertThat(RetryReason.getAbbreviation(null, HTTP_UNAVAILABLE, EGRESS_OVER_ACCOUNT_LIMIT.getErrorMessage())).isEqualTo( + assertThat(RetryReason.getAbbreviation(null, HTTP_UNAVAILABLE, EGRESS_OVER_ACCOUNT_LIMIT.getErrorMessage())).isEqualTo( EGRESS_LIMIT_BREACH_ABBREVIATION ); } @Test public void testIngressLimitRetryReason() { - Assertions.assertThat(RetryReason.getAbbreviation(null, HTTP_UNAVAILABLE, INGRESS_OVER_ACCOUNT_LIMIT.getErrorMessage())).isEqualTo( + assertThat(RetryReason.getAbbreviation(null, HTTP_UNAVAILABLE, INGRESS_OVER_ACCOUNT_LIMIT.getErrorMessage())).isEqualTo( INGRESS_LIMIT_BREACH_ABBREVIATION ); } @Test public void testOperationLimitRetryReason() { - Assertions.assertThat(RetryReason.getAbbreviation(null, HTTP_UNAVAILABLE, TPS_OVER_ACCOUNT_LIMIT.getErrorMessage())).isEqualTo( + assertThat(RetryReason.getAbbreviation(null, HTTP_UNAVAILABLE, TPS_OVER_ACCOUNT_LIMIT.getErrorMessage())).isEqualTo( TPS_LIMIT_BREACH_ABBREVIATION ); } @Test public void test503UnknownRetryReason() { - Assertions.assertThat(RetryReason.getAbbreviation(null, HTTP_UNAVAILABLE, null)).isEqualTo( + assertThat(RetryReason.getAbbreviation(null, HTTP_UNAVAILABLE, null)).isEqualTo( "503" ); } @Test public void test500RetryReason() { - Assertions.assertThat(RetryReason.getAbbreviation(null, HTTP_INTERNAL_ERROR, null)).isEqualTo( + assertThat(RetryReason.getAbbreviation(null, HTTP_INTERNAL_ERROR, null)).isEqualTo( "500" ); } @Test public void testUnknownHostRetryReason() { - Assertions.assertThat(RetryReason.getAbbreviation(new UnknownHostException(), null, null)).isEqualTo( + assertThat(RetryReason.getAbbreviation(new UnknownHostException(), null, null)).isEqualTo( UNKNOWN_HOST_EXCEPTION_ABBREVIATION ); } @Test public void testUnknownIOExceptionRetryReason() { - Assertions.assertThat(RetryReason.getAbbreviation(new IOException(), null, null)).isEqualTo( + assertThat(RetryReason.getAbbreviation(new IOException(), null, null)).isEqualTo( IO_EXCEPTION_ABBREVIATION ); } @Test public void testUnknownSocketException() { - Assertions.assertThat(RetryReason.getAbbreviation(new SocketException(), null, null)).isEqualTo( + assertThat(RetryReason.getAbbreviation(new SocketException(), null, null)).isEqualTo( SOCKET_EXCEPTION_ABBREVIATION ); } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestShellDecryptionKeyProvider.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestShellDecryptionKeyProvider.java index f039b60156508..a22251aae513d 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestShellDecryptionKeyProvider.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestShellDecryptionKeyProvider.java @@ -21,8 +21,7 @@ import java.io.File; import java.nio.charset.StandardCharsets; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,7 +31,8 @@ import org.apache.hadoop.fs.azurebfs.contracts.exceptions.KeyProviderException; import org.apache.hadoop.util.Shell; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Test ShellDecryptionKeyProvider. @@ -57,8 +57,7 @@ public void testScriptPathNotSpecified() throws Exception { try { provider.getStorageAccountKey(account, conf); - Assert - .fail("fs.azure.shellkeyprovider.script is not specified, we should throw"); + fail("fs.azure.shellkeyprovider.script is not specified, we should throw"); } catch (KeyProviderException e) { LOG.info("Received an expected exception: " + e.getMessage()); } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestTextFileBasedIdentityHandler.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestTextFileBasedIdentityHandler.java index 1e578670cb33f..3ff5ba7b403e8 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestTextFileBasedIdentityHandler.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestTextFileBasedIdentityHandler.java @@ -22,22 +22,23 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.NoSuchFileException; +import java.nio.file.Path; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.apache.commons.io.FileUtils; import org.apache.hadoop.fs.azurebfs.utils.TextFileBasedIdentityHandler; +import org.junit.jupiter.api.io.TempDir; import static org.apache.hadoop.test.LambdaTestUtils.intercept; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestTextFileBasedIdentityHandler { - @ClassRule - public static TemporaryFolder tempDir = new TemporaryFolder(); + @TempDir + public static Path tempDir; + private static File userMappingFile = null; private static File groupMappingFile = null; private static final String NEW_LINE = "\n"; @@ -65,10 +66,10 @@ public class TestTextFileBasedIdentityHandler { private static String testGroupDataLine4 = " " + NEW_LINE; private static String testGroupDataLine5 = "7d83024d-957c-4456-aac1-a57f9e2de914:group4:21000:sgp-group4" + NEW_LINE; - @BeforeClass + @BeforeAll public static void init() throws IOException { - userMappingFile = tempDir.newFile("user-mapping.conf"); - groupMappingFile = tempDir.newFile("group-mapping.conf"); + userMappingFile = tempDir.resolve("user-mapping.conf").toFile(); + groupMappingFile = tempDir.resolve("group-mapping.conf").toFile(); //Stage data for user mapping FileUtils.writeStringToFile(userMappingFile, testUserDataLine1, StandardCharsets.UTF_8, true); @@ -92,7 +93,7 @@ public static void init() throws IOException { private void assertUserLookup(TextFileBasedIdentityHandler handler, String userInTest, String expectedUser) throws IOException { String actualUser = handler.lookupForLocalUserIdentity(userInTest); - Assert.assertEquals("Wrong user identity for ", expectedUser, actualUser); + assertEquals(expectedUser, actualUser, "Wrong user identity for "); } @Test @@ -121,7 +122,7 @@ public void testLookupForUserFileNotFound() throws Exception { private void assertGroupLookup(TextFileBasedIdentityHandler handler, String groupInTest, String expectedGroup) throws IOException { String actualGroup = handler.lookupForLocalGroupIdentity(groupInTest); - Assert.assertEquals("Wrong group identity for ", expectedGroup, actualGroup); + assertEquals(expectedGroup, actualGroup, "Wrong group identity for "); } @Test diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/AclTestHelpers.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/AclTestHelpers.java index 2ec9722049298..dc85cc0704618 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/AclTestHelpers.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/AclTestHelpers.java @@ -26,7 +26,7 @@ import org.apache.hadoop.fs.permission.AclEntryType; import org.apache.hadoop.fs.permission.FsAction; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Helper methods useful for writing ACL tests. diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/CleanupTestContainers.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/CleanupTestContainers.java index b8272319ab851..1b3ce125db77b 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/CleanupTestContainers.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/CleanupTestContainers.java @@ -18,6 +18,7 @@ package org.apache.hadoop.fs.azurebfs.utils; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +43,7 @@ public class CleanupTestContainers extends AbstractAbfsIntegrationTest { public CleanupTestContainers() throws Exception { } - @org.junit.Test + @Test public void testDeleteContainers() throws Throwable { int count = 0; AbfsConfiguration abfsConfig = getAbfsStore(getFileSystem()).getAbfsConfiguration(); diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestCachedSASToken.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestCachedSASToken.java index cbba80877206f..08e9c9d6a94e0 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestCachedSASToken.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestCachedSASToken.java @@ -24,12 +24,13 @@ import java.time.format.DateTimeFormatter; import java.util.UUID; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.DEFAULT_SAS_TOKEN_RENEW_PERIOD_FOR_STREAMS_IN_SECONDS; import static java.time.temporal.ChronoUnit.SECONDS; import static java.time.temporal.ChronoUnit.DAYS; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test CachedSASToken. @@ -48,12 +49,12 @@ public void testUpdateAndGet() throws IOException { // set first time and ensure reference equality cachedSasToken.update(token1); String cachedToken = cachedSasToken.get(); - Assert.assertTrue(token1 == cachedToken); + assertTrue(token1 == cachedToken); // update with same token and ensure reference equality cachedSasToken.update(token1); cachedToken = cachedSasToken.get(); - Assert.assertTrue(token1 == cachedToken); + assertTrue(token1 == cachedToken); // renew and ensure reference equality String se2 = OffsetDateTime.now(ZoneOffset.UTC).plus( @@ -62,7 +63,7 @@ public void testUpdateAndGet() throws IOException { String token2 = "se=" + se2; cachedSasToken.update(token2); cachedToken = cachedSasToken.get(); - Assert.assertTrue(token2 == cachedToken); + assertTrue(token2 == cachedToken); // renew and ensure reference equality with ske String se3 = OffsetDateTime.now(ZoneOffset.UTC).plus( @@ -75,7 +76,7 @@ public void testUpdateAndGet() throws IOException { String token3 = "se=" + se3 + "&ske=" + ske3; cachedSasToken.update(token3); cachedToken = cachedSasToken.get(); - Assert.assertTrue(token3 == cachedToken); + assertTrue(token3 == cachedToken); } @Test @@ -94,7 +95,7 @@ public void testGetExpiration() throws IOException { // SASTokenProvider to get a new SAS). cachedSasToken.setForTesting(token, seDate); String cachedToken = cachedSasToken.get(); - Assert.assertNull(cachedToken); + assertNull(cachedToken); } @Test @@ -109,7 +110,7 @@ public void testUpdateAndGetWithExpiredToken() throws IOException { // set expired token and ensure not cached cachedSasToken.update(token1); String cachedToken = cachedSasToken.get(); - Assert.assertNull(cachedToken); + assertNull(cachedToken); String se2 = OffsetDateTime.now(ZoneOffset.UTC).plus( DEFAULT_SAS_TOKEN_RENEW_PERIOD_FOR_STREAMS_IN_SECONDS * 2, @@ -123,7 +124,7 @@ public void testUpdateAndGetWithExpiredToken() throws IOException { // set with expired ske and ensure not cached cachedSasToken.update(token2); cachedToken = cachedSasToken.get(); - Assert.assertNull(cachedToken); + assertNull(cachedToken); } @@ -135,31 +136,31 @@ public void testUpdateAndGetWithInvalidToken() throws IOException { String token1 = "se="; cachedSasToken.update(token1); String cachedToken = cachedSasToken.get(); - Assert.assertNull(cachedToken); + assertNull(cachedToken); // set and ensure reference that it is not cached String token2 = "se=xyz"; cachedSasToken.update(token2); cachedToken = cachedSasToken.get(); - Assert.assertNull(cachedToken); + assertNull(cachedToken); // set and ensure reference that it is not cached String token3 = "se=2100-01-01T00:00:00Z&ske="; cachedSasToken.update(token3); cachedToken = cachedSasToken.get(); - Assert.assertNull(cachedToken); + assertNull(cachedToken); // set and ensure reference that it is not cached String token4 = "se=2100-01-01T00:00:00Z&ske=xyz&"; cachedSasToken.update(token4); cachedToken = cachedSasToken.get(); - Assert.assertNull(cachedToken); + assertNull(cachedToken); // set and ensure reference that it is not cached String token5 = "se=abc&ske=xyz&"; cachedSasToken.update(token5); cachedToken = cachedSasToken.get(); - Assert.assertNull(cachedToken); + assertNull(cachedToken); } public static CachedSASToken getTestCachedSASTokenInstance() { diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestListUtils.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestListUtils.java index 36acfd8478b29..b8577ab79921d 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestListUtils.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestListUtils.java @@ -21,11 +21,11 @@ import java.util.ArrayList; import java.util.List; -import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.Path; +import static org.assertj.core.api.Assertions.assertThat; /** * Test class for ListUtils. @@ -92,7 +92,7 @@ public void testRemoveDuplicates() { */ private void validateList(List originalList, int expectedSize) { List uniqueList = ListUtils.getUniqueListResult(originalList); - Assertions.assertThat(uniqueList) + assertThat(uniqueList) .describedAs("List Size is not as expected after duplicate removal") .hasSize(expectedSize); } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestUriUtils.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestUriUtils.java index 80d2f70766ab4..eddff9ae316f3 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestUriUtils.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestUriUtils.java @@ -25,14 +25,16 @@ import java.util.List; import java.util.Set; -import org.assertj.core.api.Assertions; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; +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.assertTrue; import static org.apache.hadoop.fs.azurebfs.utils.UriUtils.changeUrlFromBlobToDfs; import static org.apache.hadoop.fs.azurebfs.utils.UriUtils.changeUrlFromDfsToBlob; import static org.apache.hadoop.test.LambdaTestUtils.intercept; @@ -43,23 +45,23 @@ public final class TestUriUtils { @Test public void testIfUriContainsAbfs() throws Exception { - Assert.assertTrue(UriUtils.containsAbfsUrl("abfs.dfs.core.windows.net")); - Assert.assertTrue(UriUtils.containsAbfsUrl("abfs.dfs.preprod.core.windows.net")); - Assert.assertFalse(UriUtils.containsAbfsUrl("abfs.dfs.cores.windows.net")); - Assert.assertFalse(UriUtils.containsAbfsUrl("")); - Assert.assertFalse(UriUtils.containsAbfsUrl(null)); - Assert.assertFalse(UriUtils.containsAbfsUrl("abfs.dfs.cores.windows.net")); - Assert.assertFalse(UriUtils.containsAbfsUrl("xhdfs.blob.core.windows.net")); + assertTrue(UriUtils.containsAbfsUrl("abfs.dfs.core.windows.net")); + assertTrue(UriUtils.containsAbfsUrl("abfs.dfs.preprod.core.windows.net")); + assertFalse(UriUtils.containsAbfsUrl("abfs.dfs.cores.windows.net")); + assertFalse(UriUtils.containsAbfsUrl("")); + assertFalse(UriUtils.containsAbfsUrl(null)); + assertFalse(UriUtils.containsAbfsUrl("abfs.dfs.cores.windows.net")); + assertFalse(UriUtils.containsAbfsUrl("xhdfs.blob.core.windows.net")); } @Test public void testExtractRawAccountName() throws Exception { - Assert.assertEquals("abfs", UriUtils.extractAccountNameFromHostName("abfs.dfs.core.windows.net")); - Assert.assertEquals("abfs", UriUtils.extractAccountNameFromHostName("abfs.dfs.preprod.core.windows.net")); - Assert.assertEquals(null, UriUtils.extractAccountNameFromHostName("abfs.dfs.cores.windows.net")); - Assert.assertEquals(null, UriUtils.extractAccountNameFromHostName("")); - Assert.assertEquals(null, UriUtils.extractAccountNameFromHostName(null)); - Assert.assertEquals(null, UriUtils.extractAccountNameFromHostName("abfs.dfs.cores.windows.net")); + assertEquals("abfs", UriUtils.extractAccountNameFromHostName("abfs.dfs.core.windows.net")); + assertEquals("abfs", UriUtils.extractAccountNameFromHostName("abfs.dfs.preprod.core.windows.net")); + assertEquals(null, UriUtils.extractAccountNameFromHostName("abfs.dfs.cores.windows.net")); + assertEquals(null, UriUtils.extractAccountNameFromHostName("")); + assertEquals(null, UriUtils.extractAccountNameFromHostName(null)); + assertEquals(null, UriUtils.extractAccountNameFromHostName("abfs.dfs.cores.windows.net")); } @Test @@ -73,44 +75,44 @@ public void testMaskUrlQueryParameters() throws Exception { List keyValueList = URLEncodedUtils .parse("abc=123&pqr=45678&def=789&bcd=012&xyz=678", StandardCharsets.UTF_8); - Assert.assertEquals("Incorrect masking", - "abc=XXXXX&pqr=456XX&def=789&bcd=XXXXX&xyz=67X", - UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask)); + assertEquals("abc=XXXXX&pqr=456XX&def=789&bcd=XXXXX&xyz=67X", + UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask), + "Incorrect masking"); //Mask GUIDs keyValueList = URLEncodedUtils .parse("abc=123&pqr=256877f2-c094-48c8-83df-ddb5825694fd&def=789", StandardCharsets.UTF_8); - Assert.assertEquals("Incorrect partial masking for guid", - "abc=XXXXX&pqr=256877f2-c094-48c8XXXXXXXXXXXXXXXXXX&def=789", - UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask)); + assertEquals("abc=XXXXX&pqr=256877f2-c094-48c8XXXXXXXXXXXXXXXXXX&def=789", + UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask), + "Incorrect partial masking for guid"); //For params entered for both full and partial masks, full mask applies partialMask.add("abc"); - Assert.assertEquals("Full mask should apply", - "abc=XXXXX&pqr=256877f2-c094-48c8XXXXXXXXXXXXXXXXXX&def=789", - UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask)); + assertEquals("abc=XXXXX&pqr=256877f2-c094-48c8XXXXXXXXXXXXXXXXXX&def=789", + UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask), + "Full mask should apply"); //Duplicate key (to be masked) with different values keyValueList = URLEncodedUtils .parse("abc=123&pqr=4561234&abc=789", StandardCharsets.UTF_8); - Assert.assertEquals("Duplicate key: Both values should get masked", - "abc=XXXXX&pqr=4561XXX&abc=XXXXX", - UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask)); + assertEquals("abc=XXXXX&pqr=4561XXX&abc=XXXXX", + UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask), + "Duplicate key: Both values should get masked"); //Duplicate key (not to be masked) with different values keyValueList = URLEncodedUtils .parse("abc=123&def=456&pqrs=789&def=000", StandardCharsets.UTF_8); - Assert.assertEquals("Duplicate key: Values should not get masked", - "abc=XXXXX&def=456&pqrs=789&def=000", - UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask)); + assertEquals("abc=XXXXX&def=456&pqrs=789&def=000", + UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask), + "Duplicate key: Values should not get masked"); //Empty param value keyValueList = URLEncodedUtils .parse("abc=123&def=&pqr=789&s=1", StandardCharsets.UTF_8); - Assert.assertEquals("Incorrect url with empty query value", - "abc=XXXXX&def=&pqr=78X&s=1", - UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask)); + assertEquals("abc=XXXXX&def=&pqr=78X&s=1", + UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask), + "Incorrect url with empty query value"); //Empty param key keyValueList = URLEncodedUtils @@ -124,17 +126,16 @@ public void testMaskUrlQueryParameters() throws Exception { keyValueList = URLEncodedUtils .parse("abc=123&s=1", StandardCharsets.UTF_8); keyValueList.add(new BasicNameValuePair("null1", null)); - Assert.assertEquals("Null value, incorrect query construction", - "abc=XXXXX&s=1&null1=", - UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask)); + assertEquals("abc=XXXXX&s=1&null1=", + UriUtils.maskUrlQueryParameters(keyValueList, fullMask, partialMask), + "Null value, incorrect query construction"); //Param (to be masked) with null value keyValueList.add(new BasicNameValuePair("null2", null)); fullMask.add("null2"); - Assert.assertEquals("No mask should be added for null value", - "abc=XXXXX&s=1&null1=&null2=", UriUtils - .maskUrlQueryParameters(keyValueList, fullMask, - partialMask)); //no mask + assertEquals("abc=XXXXX&s=1&null1=&null2=", UriUtils + .maskUrlQueryParameters(keyValueList, fullMask, partialMask), + "No mask should be added for null value"); //no mask } @Test @@ -161,7 +162,7 @@ public void testConvertUrlFromDfsToBlob() throws Exception{ "https://accountName.blob.core.windows.net/blob.containerName"); for (int i = 0; i < inputUrls.size(); i++) { - Assertions.assertThat(changeUrlFromDfsToBlob(new URL(inputUrls.get(i))).toString()) + assertThat(changeUrlFromDfsToBlob(new URL(inputUrls.get(i))).toString()) .describedAs("URL conversion not as expected").isEqualTo(expectedUrls.get(i)); } } @@ -188,7 +189,7 @@ public void testConvertUrlFromBlobToDfs() throws Exception{ "https://accountName.dfs.core.windows.net/blob.containerName"); for (int i = 0; i < inputUrls.size(); i++) { - Assertions.assertThat(changeUrlFromBlobToDfs(new URL(inputUrls.get(i))).toString()) + assertThat(changeUrlFromBlobToDfs(new URL(inputUrls.get(i))).toString()) .describedAs("Url Conversion Not as Expected").isEqualTo(expectedUrls.get(i)); } }