-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-19280. [ABFS] Initialize client timer only if metric collection is enabled #7061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
steveloughran
merged 16 commits into
apache:trunk
from
bhattmanish98:HADOOP-19280_AbfsClientTimer
Sep 30, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1da9959
Moved ABFS client timer initialization inside metric collection check
3cfadf2
Test cases correction for timer variable
05154ea
Unit Test cases for timer changes
efb4eef
Test cases correction for timer variable
af594f4
Merge branch 'trunk' into HADOOP-19280_AbfsClientTimer
bhattmanish98 1b22d82
cancel the timer when file system is getting close
d227693
Merge branch 'HADOOP-19280_AbfsClientTimer' of https://github.com/bha…
7a16f6f
Creating AbfsDfsClient class object instead of AbfsClient class
3a20550
Refactor getTimer method and use Assertions.assertThat
468987f
Moved testTimerNotInitialize and testTimerInitialize test cases to Te…
99e1cc9
Fix Formatting and license error
401edde
Abfs Client Timer Thread Name Constant and getTimer method protected
6936557
Add additional check on metrics Collection Stopped in Resume metrics
f729b48
Added sleep of 500ms after closing client
7cc5e4b
Define constant for SLEEP_DURATION_MS
cc0b8ab
Comments on TestAbfsClient
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...ols/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /** | ||
| * 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 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 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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a little Java explaining what it is trying to test. |
||
| 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 testTimerInitializationWithoutMetricCollection() 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_CLIENT_TIMER_THREAD_NAME)) | ||
| .describedAs("Expected thread 'abfs-timer-client' not found") | ||
| .isEqualTo(false); | ||
| 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 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); | ||
| 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_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)) | ||
| .describedAs("Unexpected thread 'abfs-timer-client' found") | ||
| .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) { | ||
steveloughran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Get all threads and their stack traces | ||
| Map<Thread, StackTraceElement[]> 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; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.