commonTest.aws.sdk.kotlin.runtime.http.retries.AwsDefaultRetryPolicyTest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-http Show documentation
Show all versions of aws-http Show documentation
HTTP core for AWS service clients
package aws.sdk.kotlin.runtime.http.retries
import aws.smithy.kotlin.runtime.ErrorMetadata
import aws.smithy.kotlin.runtime.ServiceErrorMetadata
import aws.smithy.kotlin.runtime.ServiceException
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.retries.policy.RetryDirective
import kotlin.test.Test
import kotlin.test.assertEquals
class AwsDefaultRetryPolicyTest {
@Test
fun testErrorsByErrorCode() {
AwsDefaultRetryPolicy.knownErrorTypes.forEach { (errorCode, errorType) ->
val ex = ServiceException()
ex.sdkErrorMetadata.attributes[ServiceErrorMetadata.ErrorType] = ServiceException.ErrorType.Server
ex.sdkErrorMetadata.attributes[ErrorMetadata.Retryable] = true
ex.sdkErrorMetadata.attributes[ServiceErrorMetadata.ErrorCode] = errorCode
val result = AwsDefaultRetryPolicy.evaluate(Result.failure(ex))
assertEquals(RetryDirective.RetryError(errorType), result)
}
}
@Test
fun testErrorsByStatusCode() {
AwsDefaultRetryPolicy.knownStatusCodes.forEach { (statusCode, errorType) ->
val modeledStatusCode = HttpStatusCode.fromValue(statusCode)
val response = HttpResponse(modeledStatusCode, Headers.Empty, HttpBody.Empty)
val ex = ServiceException()
ex.sdkErrorMetadata.attributes[ServiceErrorMetadata.ErrorType] = ServiceException.ErrorType.Server
ex.sdkErrorMetadata.attributes[ErrorMetadata.Retryable] = true
ex.sdkErrorMetadata.attributes[ServiceErrorMetadata.ProtocolResponse] = response
val result = AwsDefaultRetryPolicy.evaluate(Result.failure(ex))
assertEquals(RetryDirective.RetryError(errorType), result)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy