Skip to content

Commit

Permalink
fault injection 408 fix (#34723)
Browse files Browse the repository at this point in the history
* fault injection 408 fix

---------

Co-authored-by: annie-mac <xinlian@microsoft.com>
  • Loading branch information
xinlian12 and annie-mac committed Apr 28, 2023
1 parent 3267b8b commit 658c6d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos-test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### Breaking Changes

#### Bugs Fixed
* Fixed an issue where `FaultInjectionServerErrorType.TIMEOUT` is not injecting the correct error response - See [PR 34723](https://github.com/Azure/azure-sdk-for-java/pull/34723)

#### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public boolean isApplicable(String ruleId, RxDocumentServiceRequest request) {
return this.times == null || request.faultInjectionRequestContext.getFaultInjectionRuleApplyCount(ruleId) < this.times;
}

// IMPORTANT: Please keep the behavior be consistent with RequestManager
public CosmosException getInjectedServerError(RxDocumentServiceRequest request) {

CosmosException cosmosException;
Expand All @@ -75,7 +76,7 @@ public CosmosException getInjectedServerError(RxDocumentServiceRequest request)

switch (this.serverErrorType) {
case GONE:
GoneException goneException = new GoneException(this.getErrorMessage(RMResources.Gone));
GoneException goneException = new GoneException(this.getErrorMessage(RMResources.Gone), HttpConstants.SubStatusCodes.SERVER_GENERATED_410);
goneException.setIsBasedOn410ResponseFromService();
cosmosException = goneException;
break;
Expand All @@ -93,7 +94,17 @@ public CosmosException getInjectedServerError(RxDocumentServiceRequest request)
break;

case TIMEOUT:
cosmosException = new RequestTimeoutException(null, lsn, partitionKeyRangeId, responseHeaders);
// For server return 408, SDK internally will wrap into 410
// Details can be found in RntbdRequestManager
RequestTimeoutException rootException = new RequestTimeoutException(null, lsn, partitionKeyRangeId, responseHeaders);
cosmosException = new GoneException(
null,
null,
lsn,
partitionKeyRangeId,
responseHeaders,
rootException,
HttpConstants.SubStatusCodes.SERVER_GENERATED_408);
break;

case INTERNAL_SERVER_ERROR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ public static Object[][] faultInjectionOperationTypeProvider() {
public static Object[][] faultInjectionServerErrorResponseProvider() {
return new Object[][]{
// faultInjectionServerError, will SDK retry, errorStatusCode, errorSubStatusCode
{ FaultInjectionServerErrorType.GONE, true, 410, HttpConstants.SubStatusCodes.SERVER_GENERATED_410 },
{ FaultInjectionServerErrorType.INTERNAL_SERVER_ERROR, false, 500, 0 },
{ FaultInjectionServerErrorType.RETRY_WITH, true, 449, 0 },
{ FaultInjectionServerErrorType.TOO_MANY_REQUEST, true, 429, 0 },
{ FaultInjectionServerErrorType.READ_SESSION_NOT_AVAILABLE, true, 404, 1002 },
{ FaultInjectionServerErrorType.TIMEOUT, false, 408, 0 },
{ FaultInjectionServerErrorType.TIMEOUT, true, 410, HttpConstants.SubStatusCodes.SERVER_GENERATED_408 }, // for server return 408, SDK will wrap into 410/21010
{ FaultInjectionServerErrorType.PARTITION_IS_MIGRATING, true, 410, 1008 },
{ FaultInjectionServerErrorType.PARTITION_IS_SPLITTING, true, 410, 1007 }
};
Expand Down

0 comments on commit 658c6d5

Please sign in to comment.