From 1da9959c957726471aec7a4ce448c7dc60453bf4 Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Fri, 20 Sep 2024 03:10:57 -0700 Subject: [PATCH 01/14] Moved ABFS client timer initialization inside metric collection check --- .../fs/azurebfs/services/AbfsClient.java | 13 +++-- .../fs/azurebfs/services/ITestAbfsClient.java | 51 +++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java index a2d65c145b625..ffa78ebcce3f9 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java @@ -122,7 +122,7 @@ public class AbfsClient implements Closeable { private AccessTokenProvider tokenProvider; private SASTokenProvider sasTokenProvider; private final AbfsCounters abfsCounters; - private final Timer timer; + private Timer timer; private final String abfsMetricUrl; private boolean isMetricCollectionEnabled = false; private final MetricFormat metricFormat; @@ -231,9 +231,9 @@ private AbfsClient(final URL baseUrl, throw new IOException("Exception while initializing metric credentials " + e); } } - this.timer = new Timer( - "abfs-timer-client", true); if (isMetricCollectionEnabled) { + this.timer = new Timer( + "abfs-timer-client", true); timer.schedule(new TimerTaskImpl(), metricIdlePeriod, metricIdlePeriod); @@ -265,7 +265,7 @@ public AbfsClient(final URL baseUrl, final SharedKeyCredentials sharedKeyCredent @Override public void close() throws IOException { - if (runningTimerTask != null) { + if (runningTimerTask != null && isMetricCollectionEnabled) { runningTimerTask.cancel(); timer.purge(); } @@ -1833,7 +1833,7 @@ private TracingContext getMetricTracingContext() { boolean timerOrchestrator(TimerFunctionality timerFunctionality, TimerTask timerTask) { switch (timerFunctionality) { case RESUME: - if (isMetricCollectionStopped.get()) { + if (isMetricCollectionEnabled) { synchronized (this) { if (isMetricCollectionStopped.get()) { resumeTimer(); @@ -2011,4 +2011,7 @@ AbfsApacheHttpClient getAbfsApacheHttpClient() { KeepAliveCache getKeepAliveCache() { return keepAliveCache; } + + @VisibleForTesting + Timer getTimer() {return timer;} } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java index 909e7cf1749a1..0110354cab138 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java @@ -26,10 +26,12 @@ import java.net.URL; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Random; import java.util.regex.Pattern; import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl; +import org.apache.hadoop.fs.azurebfs.utils.MetricFormat; import org.assertj.core.api.Assertions; import org.junit.Assume; import org.junit.Test; @@ -90,6 +92,7 @@ import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.SINGLE_WHITE_SPACE; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_NAME; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_TYPE; +import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_FORMAT; import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.TEST_CONFIGURATION_FILE_NAME; /** @@ -682,4 +685,52 @@ public void testExpectHundredContinue() throws Exception { .describedAs("The expect header is not false") .isFalse(); } + + @Test + public void testTimerNotInitialize() throws Exception { + // Create an AzureBlobFileSystem instance. + final Configuration configuration = getRawConfiguration(); + configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.EMPTY)); + final AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration); + + // Get an instance of AbfsClient. + AbfsClient testClient = super.getAbfsClient(super.getAbfsStore(fs)); + assertNull(testClient.getTimer()); + + boolean isTimerThreadPresent = isThreadRunning("abfs-timer-client"); + assertFalse("Expected thread 'abfs-timer-client' not found", isTimerThreadPresent); + // Close the AzureBlobFileSystem. + fs.close(); + } + + @Test + public void testTimerInitialize() throws Exception { + // Create an AzureBlobFileSystem instance. + final Configuration configuration = getRawConfiguration(); + configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT)); + final AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration); + + // Get an instance of AbfsClient. + AbfsClient testClient = super.getAbfsClient(super.getAbfsStore(fs)); + assertNotNull(testClient.getTimer()); + // Check if a thread with the name "abfs-timer-client" exists + boolean isTimerThreadPresent = isThreadRunning("abfs-timer-client"); + assertTrue("Expected thread 'abfs-timer-client' found", isTimerThreadPresent); + + // Close the AzureBlobFileSystem. + fs.close(); + } + + private boolean isThreadRunning(String threadName) { + // Get all threads and their stack traces + Map allThreads = Thread.getAllStackTraces(); + + // Check if any thread has the specified name + for (Thread thread : allThreads.keySet()) { + if (thread.getName().equals(threadName)) { + return true; + } + } + return false; + } } From 3cfadf2aa7d53198c6607fb5dac9436f91a79cc3 Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Fri, 20 Sep 2024 09:05:24 -0700 Subject: [PATCH 02/14] Test cases correction for timer variable --- .../fs/azurebfs/services/ITestAbfsClient.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java index 0110354cab138..ad1348f8577f1 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java @@ -93,6 +93,8 @@ import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_NAME; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_TYPE; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_FORMAT; +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_ACCOUNT_KEY; import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.TEST_CONFIGURATION_FILE_NAME; /** @@ -690,17 +692,22 @@ public void testExpectHundredContinue() throws Exception { public void testTimerNotInitialize() throws Exception { // Create an AzureBlobFileSystem instance. final Configuration configuration = getRawConfiguration(); - configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.EMPTY)); - final AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration); + AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME); + + AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd"))); + AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); // Get an instance of AbfsClient. - AbfsClient testClient = super.getAbfsClient(super.getAbfsStore(fs)); - assertNull(testClient.getTimer()); + AbfsClient client = new AbfsClient(new URL("https://azure.com"), + null, + abfsConfiguration, + (AccessTokenProvider) null, + null, + abfsClientContext); + assertNull(client.getTimer()); boolean isTimerThreadPresent = isThreadRunning("abfs-timer-client"); assertFalse("Expected thread 'abfs-timer-client' not found", isTimerThreadPresent); - // Close the AzureBlobFileSystem. - fs.close(); } @Test @@ -708,17 +715,25 @@ public void testTimerInitialize() throws Exception { // Create an AzureBlobFileSystem instance. final Configuration configuration = getRawConfiguration(); configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT)); - final AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration); + configuration.set(FS_AZURE_METRIC_ACCOUNT_NAME, ACCOUNT_NAME); + configuration.set(FS_AZURE_METRIC_ACCOUNT_KEY, "vvE5oEbtg19iy5SSPXmuCNeglr3DsvpPe5JIE7eTrDmK6K2vzmoVs5VnY9Q7bI/DiviU+a3YbHx3+AStzRmEJQ=="); + AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME); + + AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd"))); + AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); // Get an instance of AbfsClient. - AbfsClient testClient = super.getAbfsClient(super.getAbfsStore(fs)); - assertNotNull(testClient.getTimer()); + AbfsClient client = new AbfsClient(new URL("https://azure.com"), + null, + abfsConfiguration, + (AccessTokenProvider) null, + null, + abfsClientContext); + + assertNotNull(client.getTimer()); // Check if a thread with the name "abfs-timer-client" exists boolean isTimerThreadPresent = isThreadRunning("abfs-timer-client"); assertTrue("Expected thread 'abfs-timer-client' found", isTimerThreadPresent); - - // Close the AzureBlobFileSystem. - fs.close(); } private boolean isThreadRunning(String threadName) { From 05154ea605dfbb26be83e2cd494531021a9e70e4 Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Fri, 20 Sep 2024 09:29:44 -0700 Subject: [PATCH 03/14] Unit Test cases for timer changes --- .../apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java index ad1348f8577f1..9fedd5ff08962 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java @@ -31,6 +31,7 @@ import java.util.regex.Pattern; import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl; +import org.apache.hadoop.fs.azurebfs.utils.Base64; import org.apache.hadoop.fs.azurebfs.utils.MetricFormat; import org.assertj.core.api.Assertions; import org.junit.Assume; @@ -105,6 +106,7 @@ public final class ITestAbfsClient extends AbstractAbfsIntegrationTest { private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net"; + private static final String ACCOUNT_KEY = "testAccountKey"; private static final String FS_AZURE_USER_AGENT_PREFIX = "Partner Service"; private static final String HUNDRED_CONTINUE_USER_AGENT = SINGLE_WHITE_SPACE + HUNDRED_CONTINUE + SEMICOLON; private static final String TEST_PATH = "/testfile"; @@ -716,7 +718,7 @@ public void testTimerInitialize() throws Exception { final Configuration configuration = getRawConfiguration(); configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT)); configuration.set(FS_AZURE_METRIC_ACCOUNT_NAME, ACCOUNT_NAME); - configuration.set(FS_AZURE_METRIC_ACCOUNT_KEY, "vvE5oEbtg19iy5SSPXmuCNeglr3DsvpPe5JIE7eTrDmK6K2vzmoVs5VnY9Q7bI/DiviU+a3YbHx3+AStzRmEJQ=="); + 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"))); From efb4eef269089c06ed7fb0201e5f24a92f6eea4a Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Fri, 20 Sep 2024 09:15:05 -0700 Subject: [PATCH 04/14] Test cases correction for timer variable --- .../org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java index 9fedd5ff08962..8cabcaa6062ab 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java @@ -106,7 +106,7 @@ public final class ITestAbfsClient extends AbstractAbfsIntegrationTest { private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net"; - private static final String ACCOUNT_KEY = "testAccountKey"; + private static final String ACCOUNT_KEY = "testKey"; private static final String FS_AZURE_USER_AGENT_PREFIX = "Partner Service"; private static final String HUNDRED_CONTINUE_USER_AGENT = SINGLE_WHITE_SPACE + HUNDRED_CONTINUE + SEMICOLON; private static final String TEST_PATH = "/testfile"; From 1b22d8200de7213f7ae427f5b9e603614df434a6 Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Mon, 23 Sep 2024 00:23:16 -0700 Subject: [PATCH 05/14] cancel the timer when file system is getting close --- .../java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java index ffa78ebcce3f9..e4925362aa20d 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java @@ -267,7 +267,7 @@ public AbfsClient(final URL baseUrl, final SharedKeyCredentials sharedKeyCredent public void close() throws IOException { if (runningTimerTask != null && isMetricCollectionEnabled) { runningTimerTask.cancel(); - timer.purge(); + timer.cancel(); } if (keepAliveCache != null) { keepAliveCache.close(); From 7a16f6f7ca0a03c0e2840c0cfd91e7a0e08e743d Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Mon, 23 Sep 2024 02:21:32 -0700 Subject: [PATCH 06/14] Creating AbfsDfsClient class object instead of AbfsClient class --- .../hadoop/fs/azurebfs/services/ITestAbfsClient.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java index 8a4b3d9a15a10..1fdadc23fa56b 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java @@ -703,7 +703,7 @@ public void testTimerNotInitialize() throws Exception { AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); // Get an instance of AbfsClient. - AbfsClient client = new AbfsClient(new URL("https://azure.com"), + AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"), null, abfsConfiguration, (AccessTokenProvider) null, @@ -712,7 +712,10 @@ public void testTimerNotInitialize() throws Exception { assertNull(client.getTimer()); boolean isTimerThreadPresent = isThreadRunning("abfs-timer-client"); - assertFalse("Expected thread 'abfs-timer-client' not found", isTimerThreadPresent); + + // Check if a thread with the name "abfs-timer-client" exists + assertFalse("Unexpected thread 'abfs-timer-client' found", isTimerThreadPresent); + client.close(); } @Test @@ -728,7 +731,7 @@ public void testTimerInitialize() throws Exception { AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); // Get an instance of AbfsClient. - AbfsClient client = new AbfsClient(new URL("https://azure.com"), + AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"), null, abfsConfiguration, (AccessTokenProvider) null, @@ -738,7 +741,8 @@ public void testTimerInitialize() throws Exception { assertNotNull(client.getTimer()); // Check if a thread with the name "abfs-timer-client" exists boolean isTimerThreadPresent = isThreadRunning("abfs-timer-client"); - assertTrue("Expected thread 'abfs-timer-client' found", isTimerThreadPresent); + assertTrue("Expected thread 'abfs-timer-client' not found", isTimerThreadPresent); + client.close(); } private boolean isThreadRunning(String threadName) { From 3a20550896964a0c673c98ea9446aeea681bfd2c Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Mon, 23 Sep 2024 04:15:14 -0700 Subject: [PATCH 07/14] Refactor getTimer method and use Assertions.assertThat --- .../fs/azurebfs/services/AbfsClient.java | 4 +++- .../fs/azurebfs/services/ITestAbfsClient.java | 24 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java index a563ac4e89f04..5f9d3b541eefa 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java @@ -1598,7 +1598,9 @@ KeepAliveCache getKeepAliveCache() { } @VisibleForTesting - Timer getTimer() {return timer;} + Timer getTimer() { + return timer; + } protected String getUserAgent() { return userAgent; diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java index 1fdadc23fa56b..8b84ad31798f9 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java @@ -710,11 +710,14 @@ public void testTimerNotInitialize() throws Exception { null, abfsClientContext); - assertNull(client.getTimer()); - boolean isTimerThreadPresent = isThreadRunning("abfs-timer-client"); + Assertions.assertThat(client.getTimer()) + .describedAs("Timer should not be initialized") + .isNull(); // Check if a thread with the name "abfs-timer-client" exists - assertFalse("Unexpected thread 'abfs-timer-client' found", isTimerThreadPresent); + Assertions.assertThat(isThreadRunning("abfs-timer-client")) + .describedAs("Expected thread 'abfs-timer-client' not found") + .isEqualTo(false); client.close(); } @@ -738,11 +741,20 @@ public void testTimerInitialize() throws Exception { null, abfsClientContext); - assertNotNull(client.getTimer()); + Assertions.assertThat(client.getTimer()) + .describedAs("Timer should be initialized") + .isNotNull(); + // Check if a thread with the name "abfs-timer-client" exists - boolean isTimerThreadPresent = isThreadRunning("abfs-timer-client"); - assertTrue("Expected thread 'abfs-timer-client' not found", isTimerThreadPresent); + Assertions.assertThat(isThreadRunning("abfs-timer-client")) + .describedAs("Expected thread 'abfs-timer-client' not found") + .isEqualTo(true); client.close(); + + // Check if the thread is removed after closing the client + Assertions.assertThat(isThreadRunning("abfs-timer-client")) + .describedAs("Unexpected thread 'abfs-timer-client' found") + .isEqualTo(false); } private boolean isThreadRunning(String threadName) { From 468987f69b03e2a3a2e8d1cb2c2594e318eb5c2b Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Tue, 24 Sep 2024 01:53:37 -0700 Subject: [PATCH 08/14] Moved testTimerNotInitialize and testTimerInitialize test cases to TestAbfsClient class --- .../fs/azurebfs/services/ITestAbfsClient.java | 84 ---------------- .../fs/azurebfs/services/TestAbfsClient.java | 97 +++++++++++++++++++ 2 files changed, 97 insertions(+), 84 deletions(-) create mode 100644 hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java index 8b84ad31798f9..81897a568763e 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java @@ -26,13 +26,10 @@ import java.net.URL; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Random; import java.util.regex.Pattern; import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl; -import org.apache.hadoop.fs.azurebfs.utils.Base64; -import org.apache.hadoop.fs.azurebfs.utils.MetricFormat; import org.assertj.core.api.Assertions; import org.junit.Assume; import org.junit.Test; @@ -93,9 +90,6 @@ import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.SINGLE_WHITE_SPACE; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_NAME; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_TYPE; -import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_FORMAT; -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_ACCOUNT_KEY; import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.TEST_CONFIGURATION_FILE_NAME; /** @@ -106,7 +100,6 @@ public final class ITestAbfsClient extends AbstractAbfsIntegrationTest { private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net"; - private static final String ACCOUNT_KEY = "testKey"; private static final String FS_AZURE_USER_AGENT_PREFIX = "Partner Service"; private static final String HUNDRED_CONTINUE_USER_AGENT = SINGLE_WHITE_SPACE + HUNDRED_CONTINUE + SEMICOLON; private static final String TEST_PATH = "/testfile"; @@ -692,81 +685,4 @@ public void testExpectHundredContinue() throws Exception { .describedAs("The expect header is not false") .isFalse(); } - - @Test - public void testTimerNotInitialize() throws Exception { - // Create an AzureBlobFileSystem instance. - final Configuration configuration = getRawConfiguration(); - AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME); - - AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd"))); - AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); - - // Get an instance of AbfsClient. - AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"), - null, - abfsConfiguration, - (AccessTokenProvider) null, - null, - abfsClientContext); - - Assertions.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-timer-client")) - .describedAs("Expected thread 'abfs-timer-client' not found") - .isEqualTo(false); - client.close(); - } - - @Test - public void testTimerInitialize() throws Exception { - // Create an AzureBlobFileSystem instance. - final Configuration configuration = getRawConfiguration(); - configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT)); - configuration.set(FS_AZURE_METRIC_ACCOUNT_NAME, ACCOUNT_NAME); - 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"))); - AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); - - // Get an instance of AbfsClient. - AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"), - null, - abfsConfiguration, - (AccessTokenProvider) null, - null, - abfsClientContext); - - Assertions.assertThat(client.getTimer()) - .describedAs("Timer should be initialized") - .isNotNull(); - - // Check if a thread with the name "abfs-timer-client" exists - Assertions.assertThat(isThreadRunning("abfs-timer-client")) - .describedAs("Expected thread 'abfs-timer-client' not found") - .isEqualTo(true); - client.close(); - - // Check if the thread is removed after closing the client - Assertions.assertThat(isThreadRunning("abfs-timer-client")) - .describedAs("Unexpected thread 'abfs-timer-client' found") - .isEqualTo(false); - } - - private boolean isThreadRunning(String threadName) { - // Get all threads and their stack traces - Map allThreads = Thread.getAllStackTraces(); - - // Check if any thread has the specified name - for (Thread thread : allThreads.keySet()) { - if (thread.getName().equals(threadName)) { - return true; - } - } - return false; - } } 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 new file mode 100644 index 0000000000000..437ff5f1162e7 --- /dev/null +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java @@ -0,0 +1,97 @@ +package org.apache.hadoop.fs.azurebfs.services; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.azurebfs.AbfsConfiguration; +import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl; +import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider; +import org.apache.hadoop.fs.azurebfs.utils.Base64; +import org.apache.hadoop.fs.azurebfs.utils.MetricFormat; +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.mockito.Mockito; + +import java.net.URI; +import java.net.URL; +import java.util.Map; + +import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.*; + +public class TestAbfsClient { + private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net"; + private static final String ACCOUNT_KEY = "testKey"; + + @Test + public void testTimerNotInitialize() throws Exception { + final Configuration configuration = new Configuration(); + AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME); + + AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd"))); + AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); + + // Get an instance of AbfsClient. + AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"), + null, + abfsConfiguration, + (AccessTokenProvider) null, + null, + abfsClientContext); + + Assertions.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-timer-client")) + .describedAs("Expected thread 'abfs-timer-client' not found") + .isEqualTo(false); + client.close(); + } + + @Test + public void testTimerInitialize() throws Exception { + final Configuration configuration = new Configuration(); + configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT)); + configuration.set(FS_AZURE_METRIC_ACCOUNT_NAME, ACCOUNT_NAME); + 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"))); + AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build(); + + // Get an instance of AbfsClient. + AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"), + null, + abfsConfiguration, + (AccessTokenProvider) null, + null, + abfsClientContext); + + Assertions.assertThat(client.getTimer()) + .describedAs("Timer should be initialized") + .isNotNull(); + + // Check if a thread with the name "abfs-timer-client" exists + Assertions.assertThat(isThreadRunning("abfs-timer-client")) + .describedAs("Expected thread 'abfs-timer-client' not found") + .isEqualTo(true); + client.close(); + + // Check if the thread is removed after closing the client + Assertions.assertThat(isThreadRunning("abfs-timer-client")) + .describedAs("Unexpected thread 'abfs-timer-client' found") + .isEqualTo(false); + } + + private boolean isThreadRunning(String threadName) { + // Get all threads and their stack traces + Map allThreads = Thread.getAllStackTraces(); + + // Check if any thread has the specified name + for (Thread thread : allThreads.keySet()) { + if (thread.getName().equals(threadName)) { + return true; + } + } + return false; + } +} From 99e1cc9fea8bf936e518667282e199771dcc3200 Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Tue, 24 Sep 2024 06:17:02 -0700 Subject: [PATCH 09/14] Fix Formatting and license error --- .../fs/azurebfs/services/TestAbfsClient.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 437ff5f1162e7..c4db0032534d4 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 @@ -1,3 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.apache.hadoop.fs.azurebfs.services; import org.apache.hadoop.conf.Configuration; @@ -14,7 +32,9 @@ import java.net.URL; import java.util.Map; -import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.*; +import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_ACCOUNT_KEY; +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; public class TestAbfsClient { private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net"; From 401edded40bed5769d6af0665136d28f2bdd0620 Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Tue, 24 Sep 2024 10:08:06 -0700 Subject: [PATCH 10/14] Abfs Client Timer Thread Name Constant and getTimer method protected --- .../org/apache/hadoop/fs/azurebfs/services/AbfsClient.java | 5 +++-- .../apache/hadoop/fs/azurebfs/services/TestAbfsClient.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java index 5f9d3b541eefa..bdf833470e079 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java @@ -131,6 +131,7 @@ public abstract class AbfsClient implements Closeable { public static final Logger LOG = LoggerFactory.getLogger(AbfsClient.class); public static final String HUNDRED_CONTINUE_USER_AGENT = SINGLE_WHITE_SPACE + HUNDRED_CONTINUE + SEMICOLON; + public static final String ABFS_CLIENT_TIMER_THREAD_NAME = "abfs-timer-client"; private final URL baseUrl; private final SharedKeyCredentials sharedKeyCredentials; @@ -260,7 +261,7 @@ private AbfsClient(final URL baseUrl, } if (isMetricCollectionEnabled) { this.timer = new Timer( - "abfs-timer-client", true); + ABFS_CLIENT_TIMER_THREAD_NAME, true); timer.schedule(new TimerTaskImpl(), metricIdlePeriod, metricIdlePeriod); @@ -1598,7 +1599,7 @@ KeepAliveCache getKeepAliveCache() { } @VisibleForTesting - Timer getTimer() { + protected Timer getTimer() { return timer; } 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 c4db0032534d4..045365cd1d634 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 @@ -35,6 +35,7 @@ import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_ACCOUNT_KEY; 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; public class TestAbfsClient { private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net"; @@ -61,7 +62,7 @@ public void testTimerNotInitialize() throws Exception { .isNull(); // Check if a thread with the name "abfs-timer-client" exists - Assertions.assertThat(isThreadRunning("abfs-timer-client")) + Assertions.assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) .describedAs("Expected thread 'abfs-timer-client' not found") .isEqualTo(false); client.close(); @@ -91,7 +92,7 @@ public void testTimerInitialize() throws Exception { .isNotNull(); // Check if a thread with the name "abfs-timer-client" exists - Assertions.assertThat(isThreadRunning("abfs-timer-client")) + Assertions.assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) .describedAs("Expected thread 'abfs-timer-client' not found") .isEqualTo(true); client.close(); From 69365575e86834ee382d7e927b8cc9566a1021e9 Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Wed, 25 Sep 2024 23:23:46 -0700 Subject: [PATCH 11/14] Add additional check on metrics Collection Stopped in Resume metrics --- .../org/apache/hadoop/fs/azurebfs/services/AbfsClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java index bdf833470e079..034a7f9e8a4d7 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsClient.java @@ -293,7 +293,7 @@ public AbfsClient(final URL baseUrl, final SharedKeyCredentials sharedKeyCredent @Override public void close() throws IOException { - if (runningTimerTask != null && isMetricCollectionEnabled) { + if (isMetricCollectionEnabled && runningTimerTask != null) { runningTimerTask.cancel(); timer.cancel(); } @@ -1419,7 +1419,7 @@ private TracingContext getMetricTracingContext() { boolean timerOrchestrator(TimerFunctionality timerFunctionality, TimerTask timerTask) { switch (timerFunctionality) { case RESUME: - if (isMetricCollectionEnabled) { + if (isMetricCollectionEnabled && isMetricCollectionStopped.get()) { synchronized (this) { if (isMetricCollectionStopped.get()) { resumeTimer(); From f729b48dfbe0baefdf1d6372cba048f57800a91e Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Thu, 26 Sep 2024 01:44:21 -0700 Subject: [PATCH 12/14] Added sleep of 500ms after closing client --- .../org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 045365cd1d634..693f2bbf53c9b 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 @@ -98,7 +98,8 @@ public void testTimerInitialize() throws Exception { client.close(); // Check if the thread is removed after closing the client - Assertions.assertThat(isThreadRunning("abfs-timer-client")) + Thread.sleep(500); + Assertions.assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) .describedAs("Unexpected thread 'abfs-timer-client' found") .isEqualTo(false); } From 7cc5e4b17baa6559a54a4018812bb39331addc08 Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Thu, 26 Sep 2024 04:00:17 -0700 Subject: [PATCH 13/14] Define constant for SLEEP_DURATION_MS --- .../org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 693f2bbf53c9b..7d3f26dfb634a 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 @@ -40,6 +40,7 @@ public class TestAbfsClient { private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net"; private static final String ACCOUNT_KEY = "testKey"; + private static final long SLEEP_DURATION_MS = 500; @Test public void testTimerNotInitialize() throws Exception { @@ -98,7 +99,7 @@ public void testTimerInitialize() throws Exception { client.close(); // Check if the thread is removed after closing the client - Thread.sleep(500); + Thread.sleep(SLEEP_DURATION_MS); Assertions.assertThat(isThreadRunning(ABFS_CLIENT_TIMER_THREAD_NAME)) .describedAs("Unexpected thread 'abfs-timer-client' found") .isEqualTo(false); From cc0b8ab95743fb3d69a09904462e8abc8dd57b9b Mon Sep 17 00:00:00 2001 From: manishbhatt Date: Mon, 30 Sep 2024 01:20:18 -0700 Subject: [PATCH 14/14] Comments on TestAbfsClient --- .../fs/azurebfs/services/TestAbfsClient.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) 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 7d3f26dfb634a..e8ab4291b32c5 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 @@ -18,32 +18,41 @@ package org.apache.hadoop.fs.azurebfs.services; +import java.net.URI; +import java.net.URL; +import java.util.Map; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.mockito.Mockito; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.azurebfs.AbfsConfiguration; import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl; import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider; import org.apache.hadoop.fs.azurebfs.utils.Base64; import org.apache.hadoop.fs.azurebfs.utils.MetricFormat; -import org.assertj.core.api.Assertions; -import org.junit.Test; -import org.mockito.Mockito; - -import java.net.URI; -import java.net.URL; -import java.util.Map; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_ACCOUNT_KEY; 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; +/** + * Unit test cases for the AbfsClient class. + */ public class TestAbfsClient { private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net"; private static final String ACCOUNT_KEY = "testKey"; private static final long SLEEP_DURATION_MS = 500; + /** + * Test the initialization of the AbfsClient timer when metric collection is disabled. + * In case of metric collection being disabled, the timer should not be initialized. + * Asserting that the timer is null and the abfs-timer-client thread is not running. + */ @Test - public void testTimerNotInitialize() throws Exception { + public void testTimerInitializationWithoutMetricCollection() throws Exception { final Configuration configuration = new Configuration(); AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME); @@ -69,8 +78,14 @@ public void testTimerNotInitialize() throws Exception { client.close(); } + /** + * Test the initialization of the AbfsClient timer when metric collection is enabled. + * In case of metric collection being enabled, the timer should be initialized. + * Asserting that the timer is not null and the abfs-timer-client thread is running. + * Also, asserting that the thread is removed after closing the client. + */ @Test - public void testTimerInitialize() throws Exception { + public void testTimerInitializationWithMetricCollection() throws Exception { final Configuration configuration = new Configuration(); configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT)); configuration.set(FS_AZURE_METRIC_ACCOUNT_NAME, ACCOUNT_NAME); @@ -105,6 +120,12 @@ public void testTimerInitialize() throws Exception { .isEqualTo(false); } + /** + * Check if a thread with the specified name is running. + * + * @param threadName Name of the thread to check + * @return true if the thread is running, false otherwise + */ private boolean isThreadRunning(String threadName) { // Get all threads and their stack traces Map allThreads = Thread.getAllStackTraces();