Skip to content

Commit 468987f

Browse files
author
manishbhatt
committed
Moved testTimerNotInitialize and testTimerInitialize test cases to TestAbfsClient class
1 parent 3a20550 commit 468987f

File tree

2 files changed

+97
-84
lines changed

2 files changed

+97
-84
lines changed

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@
2626
import java.net.URL;
2727
import java.util.Arrays;
2828
import java.util.List;
29-
import java.util.Map;
3029
import java.util.Random;
3130
import java.util.regex.Pattern;
3231

3332
import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl;
34-
import org.apache.hadoop.fs.azurebfs.utils.Base64;
35-
import org.apache.hadoop.fs.azurebfs.utils.MetricFormat;
3633
import org.assertj.core.api.Assertions;
3734
import org.junit.Assume;
3835
import org.junit.Test;
@@ -93,9 +90,6 @@
9390
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.SINGLE_WHITE_SPACE;
9491
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_NAME;
9592
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_CLUSTER_TYPE;
96-
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_FORMAT;
97-
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_ACCOUNT_NAME;
98-
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_METRIC_ACCOUNT_KEY;
9993
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.TEST_CONFIGURATION_FILE_NAME;
10094

10195
/**
@@ -106,7 +100,6 @@
106100
public final class ITestAbfsClient extends AbstractAbfsIntegrationTest {
107101

108102
private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net";
109-
private static final String ACCOUNT_KEY = "testKey";
110103
private static final String FS_AZURE_USER_AGENT_PREFIX = "Partner Service";
111104
private static final String HUNDRED_CONTINUE_USER_AGENT = SINGLE_WHITE_SPACE + HUNDRED_CONTINUE + SEMICOLON;
112105
private static final String TEST_PATH = "/testfile";
@@ -692,81 +685,4 @@ public void testExpectHundredContinue() throws Exception {
692685
.describedAs("The expect header is not false")
693686
.isFalse();
694687
}
695-
696-
@Test
697-
public void testTimerNotInitialize() throws Exception {
698-
// Create an AzureBlobFileSystem instance.
699-
final Configuration configuration = getRawConfiguration();
700-
AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME);
701-
702-
AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd")));
703-
AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build();
704-
705-
// Get an instance of AbfsClient.
706-
AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"),
707-
null,
708-
abfsConfiguration,
709-
(AccessTokenProvider) null,
710-
null,
711-
abfsClientContext);
712-
713-
Assertions.assertThat(client.getTimer())
714-
.describedAs("Timer should not be initialized")
715-
.isNull();
716-
717-
// Check if a thread with the name "abfs-timer-client" exists
718-
Assertions.assertThat(isThreadRunning("abfs-timer-client"))
719-
.describedAs("Expected thread 'abfs-timer-client' not found")
720-
.isEqualTo(false);
721-
client.close();
722-
}
723-
724-
@Test
725-
public void testTimerInitialize() throws Exception {
726-
// Create an AzureBlobFileSystem instance.
727-
final Configuration configuration = getRawConfiguration();
728-
configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT));
729-
configuration.set(FS_AZURE_METRIC_ACCOUNT_NAME, ACCOUNT_NAME);
730-
configuration.set(FS_AZURE_METRIC_ACCOUNT_KEY, Base64.encode(ACCOUNT_KEY.getBytes()));
731-
AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME);
732-
733-
AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd")));
734-
AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build();
735-
736-
// Get an instance of AbfsClient.
737-
AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"),
738-
null,
739-
abfsConfiguration,
740-
(AccessTokenProvider) null,
741-
null,
742-
abfsClientContext);
743-
744-
Assertions.assertThat(client.getTimer())
745-
.describedAs("Timer should be initialized")
746-
.isNotNull();
747-
748-
// Check if a thread with the name "abfs-timer-client" exists
749-
Assertions.assertThat(isThreadRunning("abfs-timer-client"))
750-
.describedAs("Expected thread 'abfs-timer-client' not found")
751-
.isEqualTo(true);
752-
client.close();
753-
754-
// Check if the thread is removed after closing the client
755-
Assertions.assertThat(isThreadRunning("abfs-timer-client"))
756-
.describedAs("Unexpected thread 'abfs-timer-client' found")
757-
.isEqualTo(false);
758-
}
759-
760-
private boolean isThreadRunning(String threadName) {
761-
// Get all threads and their stack traces
762-
Map<Thread, StackTraceElement[]> allThreads = Thread.getAllStackTraces();
763-
764-
// Check if any thread has the specified name
765-
for (Thread thread : allThreads.keySet()) {
766-
if (thread.getName().equals(threadName)) {
767-
return true;
768-
}
769-
}
770-
return false;
771-
}
772688
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.apache.hadoop.fs.azurebfs.services;
2+
3+
import org.apache.hadoop.conf.Configuration;
4+
import org.apache.hadoop.fs.azurebfs.AbfsConfiguration;
5+
import org.apache.hadoop.fs.azurebfs.AbfsCountersImpl;
6+
import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider;
7+
import org.apache.hadoop.fs.azurebfs.utils.Base64;
8+
import org.apache.hadoop.fs.azurebfs.utils.MetricFormat;
9+
import org.assertj.core.api.Assertions;
10+
import org.junit.Test;
11+
import org.mockito.Mockito;
12+
13+
import java.net.URI;
14+
import java.net.URL;
15+
import java.util.Map;
16+
17+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.*;
18+
19+
public class TestAbfsClient {
20+
private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net";
21+
private static final String ACCOUNT_KEY = "testKey";
22+
23+
@Test
24+
public void testTimerNotInitialize() throws Exception {
25+
final Configuration configuration = new Configuration();
26+
AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME);
27+
28+
AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd")));
29+
AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build();
30+
31+
// Get an instance of AbfsClient.
32+
AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"),
33+
null,
34+
abfsConfiguration,
35+
(AccessTokenProvider) null,
36+
null,
37+
abfsClientContext);
38+
39+
Assertions.assertThat(client.getTimer())
40+
.describedAs("Timer should not be initialized")
41+
.isNull();
42+
43+
// Check if a thread with the name "abfs-timer-client" exists
44+
Assertions.assertThat(isThreadRunning("abfs-timer-client"))
45+
.describedAs("Expected thread 'abfs-timer-client' not found")
46+
.isEqualTo(false);
47+
client.close();
48+
}
49+
50+
@Test
51+
public void testTimerInitialize() throws Exception {
52+
final Configuration configuration = new Configuration();
53+
configuration.set(FS_AZURE_METRIC_FORMAT, String.valueOf(MetricFormat.INTERNAL_BACKOFF_METRIC_FORMAT));
54+
configuration.set(FS_AZURE_METRIC_ACCOUNT_NAME, ACCOUNT_NAME);
55+
configuration.set(FS_AZURE_METRIC_ACCOUNT_KEY, Base64.encode(ACCOUNT_KEY.getBytes()));
56+
AbfsConfiguration abfsConfiguration = new AbfsConfiguration(configuration, ACCOUNT_NAME);
57+
58+
AbfsCounters abfsCounters = Mockito.spy(new AbfsCountersImpl(new URI("abcd")));
59+
AbfsClientContext abfsClientContext = new AbfsClientContextBuilder().withAbfsCounters(abfsCounters).build();
60+
61+
// Get an instance of AbfsClient.
62+
AbfsClient client = new AbfsDfsClient(new URL("https://azure.com"),
63+
null,
64+
abfsConfiguration,
65+
(AccessTokenProvider) null,
66+
null,
67+
abfsClientContext);
68+
69+
Assertions.assertThat(client.getTimer())
70+
.describedAs("Timer should be initialized")
71+
.isNotNull();
72+
73+
// Check if a thread with the name "abfs-timer-client" exists
74+
Assertions.assertThat(isThreadRunning("abfs-timer-client"))
75+
.describedAs("Expected thread 'abfs-timer-client' not found")
76+
.isEqualTo(true);
77+
client.close();
78+
79+
// Check if the thread is removed after closing the client
80+
Assertions.assertThat(isThreadRunning("abfs-timer-client"))
81+
.describedAs("Unexpected thread 'abfs-timer-client' found")
82+
.isEqualTo(false);
83+
}
84+
85+
private boolean isThreadRunning(String threadName) {
86+
// Get all threads and their stack traces
87+
Map<Thread, StackTraceElement[]> allThreads = Thread.getAllStackTraces();
88+
89+
// Check if any thread has the specified name
90+
for (Thread thread : allThreads.keySet()) {
91+
if (thread.getName().equals(threadName)) {
92+
return true;
93+
}
94+
}
95+
return false;
96+
}
97+
}

0 commit comments

Comments
 (0)