Skip to content

Commit 213cdaa

Browse files
author
Anuj Modi
committed
Addressing Comments
1 parent 25cc6d9 commit 213cdaa

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,19 @@ public void testListPathTracingContext() throws Exception {
165165
List<FileStatus> fileStatuses = new ArrayList<>();
166166
spiedStore.listStatus(new Path("/"), "", fileStatuses, true, null, spiedTracingContext);
167167

168-
// Assert that there were 2 paginated ListPath calls were made.
168+
// Assert that there were 2 paginated ListPath calls were made 1 and 2.
169+
// 1. Without continuation token
169170
Mockito.verify(spiedClient, times(1)).listPath(
170171
"/", false,
171172
spiedFs.getAbfsStore().getAbfsConfiguration().getListMaxResults(),
172173
null, spiedTracingContext);
174+
// 2. With continuation token
173175
Mockito.verify(spiedClient, times(1)).listPath(
174176
"/", false,
175177
spiedFs.getAbfsStore().getAbfsConfiguration().getListMaxResults(),
176178
TEST_CONTINUATION_TOKEN, spiedTracingContext);
179+
180+
// Assert that none of the API calls used the same tracing header.
177181
Mockito.verify(spiedTracingContext, times(0)).constructHeader(any(), any());
178182
}
179183

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,22 @@ public static void setMockAbfsRestOperationForListPathOperation(
6868
Mockito.doReturn(abfsRestOperation).when(spiedClient).getAbfsRestOperation(
6969
eq(AbfsRestOperationType.ListPaths), any(), any(), any());
7070

71-
addMockBehaviourToAbfsClient(spiedClient, retryPolicy);
72-
addMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation);
71+
addGeneralMockBehaviourToAbfsClient(spiedClient, retryPolicy);
72+
addGeneralMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation);
7373

7474
functionRaisingIOE.apply(httpOperation);
7575
}
7676

77-
public static void addMockBehaviourToRestOpAndHttpOp(final AbfsRestOperation abfsRestOperation,
78-
final AbfsHttpOperation httpOperation) throws IOException {
77+
/**
78+
* Adding general mock behaviour to AbfsRestOperation and AbfsHttpOperation
79+
* to avoid any NPE occurring. These will avoid any network call made and
80+
* will return the relevant exception or return value directly.
81+
* @param abfsRestOperation to be mocked
82+
* @param httpOperation to be mocked
83+
* @throws IOException
84+
*/
85+
public static void addGeneralMockBehaviourToRestOpAndHttpOp(final AbfsRestOperation abfsRestOperation,
86+
final AbfsHttpOperation httpOperation) throws IOException {
7987
HttpURLConnection httpURLConnection = Mockito.mock(HttpURLConnection.class);
8088
Mockito.doNothing().when(httpURLConnection)
8189
.setRequestProperty(nullable(String.class), nullable(String.class));
@@ -84,8 +92,15 @@ public static void addMockBehaviourToRestOpAndHttpOp(final AbfsRestOperation abf
8492
Mockito.doReturn(httpOperation).when(abfsRestOperation).createHttpOperation();
8593
}
8694

87-
public static void addMockBehaviourToAbfsClient(final AbfsClient abfsClient,
88-
final ExponentialRetryPolicy retryPolicy) throws IOException {
95+
/**
96+
* Adding general mock behaviour to AbfsClient to avoid any NPE occurring.
97+
* These will avoid any network call made and will return the relevant exception or return value directly.
98+
* @param abfsClient to be mocked
99+
* @param retryPolicy to be mocked
100+
* @throws IOException
101+
*/
102+
public static void addGeneralMockBehaviourToAbfsClient(final AbfsClient abfsClient,
103+
final ExponentialRetryPolicy retryPolicy) throws IOException {
89104
Mockito.doReturn(OAuth).when(abfsClient).getAuthType();
90105
Mockito.doReturn("").when(abfsClient).getAccessToken();
91106
AbfsThrottlingIntercept intercept = Mockito.mock(

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import static java.net.HttpURLConnection.HTTP_UNAVAILABLE;
3838
import static org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode.EGRESS_OVER_ACCOUNT_LIMIT;
3939
import static org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode.INGRESS_OVER_ACCOUNT_LIMIT;
40-
import static org.apache.hadoop.fs.azurebfs.services.AbfsClientTestUtil.addMockBehaviourToAbfsClient;
41-
import static org.apache.hadoop.fs.azurebfs.services.AbfsClientTestUtil.addMockBehaviourToRestOpAndHttpOp;
40+
import static org.apache.hadoop.fs.azurebfs.services.AbfsClientTestUtil.addGeneralMockBehaviourToAbfsClient;
41+
import static org.apache.hadoop.fs.azurebfs.services.AbfsClientTestUtil.addGeneralMockBehaviourToRestOpAndHttpOp;
4242
import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.CONNECTION_RESET_ABBREVIATION;
4343
import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.CONNECTION_RESET_MESSAGE;
4444
import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.CONNECTION_TIMEOUT_ABBREVIATION;
@@ -165,7 +165,7 @@ private void testClientRequestIdForStatusRetry(int status,
165165
AbfsClient abfsClient = Mockito.mock(AbfsClient.class);
166166
ExponentialRetryPolicy retryPolicy = Mockito.mock(
167167
ExponentialRetryPolicy.class);
168-
addMockBehaviourToAbfsClient(abfsClient, retryPolicy);
168+
addGeneralMockBehaviourToAbfsClient(abfsClient, retryPolicy);
169169

170170

171171
AbfsRestOperation abfsRestOperation = Mockito.spy(new AbfsRestOperation(
@@ -177,7 +177,7 @@ private void testClientRequestIdForStatusRetry(int status,
177177
));
178178

179179
AbfsHttpOperation httpOperation = Mockito.mock(AbfsHttpOperation.class);
180-
addMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation);
180+
addGeneralMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation);
181181

182182
Mockito.doNothing()
183183
.doNothing()
@@ -226,7 +226,7 @@ private void testClientRequestIdForTimeoutRetry(Exception[] exceptions,
226226
AbfsClient abfsClient = Mockito.mock(AbfsClient.class);
227227
ExponentialRetryPolicy retryPolicy = Mockito.mock(
228228
ExponentialRetryPolicy.class);
229-
addMockBehaviourToAbfsClient(abfsClient, retryPolicy);
229+
addGeneralMockBehaviourToAbfsClient(abfsClient, retryPolicy);
230230

231231

232232
AbfsRestOperation abfsRestOperation = Mockito.spy(new AbfsRestOperation(
@@ -238,7 +238,7 @@ private void testClientRequestIdForTimeoutRetry(Exception[] exceptions,
238238
));
239239

240240
AbfsHttpOperation httpOperation = Mockito.mock(AbfsHttpOperation.class);
241-
addMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation);
241+
addGeneralMockBehaviourToRestOpAndHttpOp(abfsRestOperation, httpOperation);
242242

243243
Stubber stubber = Mockito.doThrow(exceptions[0]);
244244
for (int iteration = 1; iteration < len; iteration++) {

0 commit comments

Comments
 (0)