Skip to content

Commit 108d6de

Browse files
author
Anuj Modi
committed
Test Failures Fixes
1 parent ad8ce43 commit 108d6de

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsRestOperation.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.apache.hadoop.fs.statistics.impl.IOStatisticsBinding;
4040

4141
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.HTTP_CONTINUE;
42-
import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.CONNECTION_TIMEOUT_ABBREVIATION;
4342
import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.EGRESS_LIMIT_BREACH_ABBREVIATION;
4443
import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.INGRESS_LIMIT_BREACH_ABBREVIATION;
4544
import static org.apache.hadoop.fs.azurebfs.services.RetryReasonConstants.OPERATION_LIMIT_BREACH_ABBREVIATION;
@@ -325,14 +324,18 @@ private boolean executeHttpOperation(final int retryCount,
325324
incrementCounter(AbfsStatistic.SERVER_UNAVAILABLE, 1);
326325
}
327326

328-
// If no exception occurred here it means http operation was successfully complete and
327+
// If no exception occurred till here it means http operation was successfully complete and
329328
// a response from server has been received which might be failure or success.
329+
// If any kind of exception has occurred it will be caught below.
330+
// If request failed determine failure reason and retry policy here.
331+
// else simply return with success after saving the result.
330332
LOG.debug("HttpRequest: {}: {}", operationType, httpOperation);
331333

332-
// If request failed at server and should be retried, we will determine failure reason and retry policy here
334+
int status = httpOperation.getStatusCode();
335+
failureReason = RetryReason.getAbbreviation(null, status, httpOperation.getStorageErrorMessage());
336+
retryPolicy = client.getRetryPolicy(failureReason);
337+
333338
if (retryPolicy.shouldRetry(retryCount, httpOperation.getStatusCode())) {
334-
int status = httpOperation.getStatusCode();
335-
failureReason = RetryReason.getAbbreviation(null, status, httpOperation.getStorageErrorMessage());
336339
return false;
337340
}
338341

@@ -370,7 +373,7 @@ private boolean executeHttpOperation(final int retryCount,
370373
1. Status code in 2xx range: Successful Operations should contribute
371374
2. Status code in 3xx range: Redirection Operations should not contribute
372375
3. Status code in 4xx range: User Errors should not contribute
373-
4. Status code in 503 range: Server Error should contribute as following:
376+
4. Status code is 503: Throttling Error should contribute as following:
374377
a. 503, Ingress Over Account Limit: Should Contribute
375378
b. 503, Egress Over Account Limit: Should Contribute
376379
c. 503, TPS Over Account Limit: Should Contribute

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import static org.apache.hadoop.fs.azurebfs.constants.HttpQueryParams.QUERY_PARAM_POSITION;
6262
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_ABFS_ACCOUNT_NAME;
6363
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.TEST_CONFIGURATION_FILE_NAME;
64+
import static org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode.EGRESS_OVER_ACCOUNT_LIMIT;
6465
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
6566
import static org.mockito.Mockito.mock;
6667
import static org.mockito.Mockito.never;
@@ -233,6 +234,11 @@ private AbfsRestOperation getRestOperation() throws Exception {
233234
// mocked the response code and the response message to check different
234235
// behaviour based on response code.
235236
Mockito.doReturn(responseCode).when(abfsHttpOperation).getConnResponseCode();
237+
if (responseCode == HTTP_UNAVAILABLE) {
238+
Mockito.doReturn(EGRESS_OVER_ACCOUNT_LIMIT.getErrorMessage())
239+
.when(abfsHttpOperation)
240+
.getStorageErrorMessage();
241+
}
236242
Mockito.doReturn(responseMessage)
237243
.when(abfsHttpOperation)
238244
.getConnResponseMessage();

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ public void testClientRequestIdFor503OtherRetry() throws Exception {
192192
* 2. Tracing header construction takes place with proper arguments based on the failure reason and retry policy used
193193
* @throws Exception
194194
*/
195-
196195
@Test
197196
public void testRetryPolicyWithDifferentFailureReasons() throws Exception {
198197

@@ -226,27 +225,26 @@ public void testRetryPolicyWithDifferentFailureReasons() throws Exception {
226225
Mockito.doReturn("").when(httpOperation).getStorageErrorMessage();
227226
Mockito.doReturn("").when(httpOperation).getStorageErrorCode();
228227
Mockito.doReturn("HEAD").when(httpOperation).getMethod();
228+
Mockito.doReturn(EGRESS_OVER_ACCOUNT_LIMIT.getErrorMessage()).when(httpOperation).getStorageErrorMessage();
229229
Mockito.doReturn(tracingContext).when(abfsRestOperation).createNewTracingContext(any());
230230

231231
try {
232232
// Operation will fail with CT first and then 503 thereafter.
233233
abfsRestOperation.execute(tracingContext);
234234
} catch(AbfsRestOperationException ex) {
235235
Assertions.assertThat(ex.getStatusCode())
236-
.describedAs("Status Code must be HTTP_UNAVAILABLE(409)")
236+
.describedAs("Status Code must be HTTP_UNAVAILABLE(503)")
237237
.isEqualTo(HTTP_UNAVAILABLE);
238238
}
239239

240240
// Assert that httpOperation.processResponse was called 3 times.
241241
// One for retry count 0
242242
// One for retry count 1 after failing with CT
243-
// One for retry count 2 after failing with 50
243+
// One for retry count 2 after failing with 503
244244
Mockito.verify(httpOperation, times(3)).processResponse(
245245
nullable(byte[].class), nullable(int.class), nullable(int.class));
246246

247-
// Assert that Static Retry Policy was used after CT failure.
248-
// Iteration 1 failed with CT and shouldRetry was called with retry count 0
249-
// Before iteration 2 sleep will be computed using static retry policy and retry count 1
247+
// Primary Request Failed with CT. Static Retry Policy should be used.
250248
Mockito.verify(abfsClient, Mockito.times(1))
251249
.getRetryPolicy(CONNECTION_TIMEOUT_ABBREVIATION);
252250
Mockito.verify(staticRetryPolicy, Mockito.times(1))
@@ -261,17 +259,17 @@ public void testRetryPolicyWithDifferentFailureReasons() throws Exception {
261259
// Before iteration 3 sleep will be computed using exponential retry policy and retry count 2
262260
// Should retry with retry count 2 will return false and no further requests will be made.
263261
Mockito.verify(abfsClient, Mockito.times(2))
264-
.getRetryPolicy("503");
262+
.getRetryPolicy(EGRESS_LIMIT_BREACH_ABBREVIATION);
265263
Mockito.verify(exponentialRetryPolicy, Mockito.times(1))
266264
.shouldRetry(1, HTTP_UNAVAILABLE);
267265
Mockito.verify(exponentialRetryPolicy, Mockito.times(1))
268266
.shouldRetry(2, HTTP_UNAVAILABLE);
269267
Mockito.verify(exponentialRetryPolicy, Mockito.times(1))
270268
.getRetryInterval(2);
271269
Mockito.verify(tracingContext, Mockito.times(1))
272-
.constructHeader(httpOperation, "503", EXPONENTIAL_RETRY_POLICY_ABBREVIATION);
270+
.constructHeader(httpOperation, EGRESS_LIMIT_BREACH_ABBREVIATION, EXPONENTIAL_RETRY_POLICY_ABBREVIATION);
273271

274-
// Assert that intercept.updateMetrics was called only once during second Iteration
272+
// Assert that intercept.updateMetrics was called 2 times. Both the retried request fails with EGR.
275273
Mockito.verify(intercept, Mockito.times(2))
276274
.updateMetrics(nullable(AbfsRestOperationType.class), nullable(AbfsHttpOperation.class));
277275
}

0 commit comments

Comments
 (0)