|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +use std::time::Duration; |
| 7 | + |
| 8 | +use aws_credential_types::Credentials; |
| 9 | +use aws_sdk_dynamodb::types::AttributeValue; |
| 10 | +use aws_sdk_dynamodb::Client; |
| 11 | +use aws_smithy_async::rt::sleep::{SharedAsyncSleep, TokioSleep}; |
| 12 | +use aws_smithy_runtime::client::http::test_util::wire::{ReplayedEvent, WireMockServer}; |
| 13 | +use aws_smithy_runtime::{ev, match_events}; |
| 14 | +use aws_smithy_types::retry::RetryConfig; |
| 15 | +use aws_smithy_types::timeout::TimeoutConfig; |
| 16 | +use aws_types::region::Region; |
| 17 | +use bytes::Bytes; |
| 18 | + |
| 19 | +const DYNAMO_THROTTLING_RESPONSE: &str = r#"{"__type":"com.amazonaws.dynamodb.v20120810#ThrottlingException", |
| 20 | +"message":"enhance your calm"}"#; |
| 21 | + |
| 22 | +const DYNAMODB_DB_SUCCESS_RESPONSE: &str = r#"{"Count":0,"Items":[],"ScannedCount":2}"#; |
| 23 | + |
| 24 | +#[tokio::test] |
| 25 | +async fn test_no_reconnect_500_throttling() { |
| 26 | + assert_error_not_transient(ReplayedEvent::HttpResponse { |
| 27 | + status: 500, |
| 28 | + body: Bytes::from(DYNAMO_THROTTLING_RESPONSE), |
| 29 | + }) |
| 30 | + .await |
| 31 | +} |
| 32 | + |
| 33 | +#[tokio::test] |
| 34 | +async fn test_no_reconnect_429_throttling() { |
| 35 | + assert_error_not_transient(ReplayedEvent::HttpResponse { |
| 36 | + status: 429, |
| 37 | + body: Bytes::from(DYNAMO_THROTTLING_RESPONSE), |
| 38 | + }) |
| 39 | + .await |
| 40 | +} |
| 41 | + |
| 42 | +async fn assert_error_not_transient(error: ReplayedEvent) { |
| 43 | + let mock = WireMockServer::start(vec![ |
| 44 | + error, |
| 45 | + ReplayedEvent::with_body(DYNAMODB_DB_SUCCESS_RESPONSE), |
| 46 | + ]) |
| 47 | + .await; |
| 48 | + |
| 49 | + let config = aws_sdk_dynamodb::Config::builder() |
| 50 | + .region(Region::from_static("us-east-2")) |
| 51 | + .credentials_provider(Credentials::for_tests()) |
| 52 | + .sleep_impl(SharedAsyncSleep::new(TokioSleep::new())) |
| 53 | + .endpoint_url(mock.endpoint_url()) |
| 54 | + .http_client(mock.http_client()) |
| 55 | + .timeout_config( |
| 56 | + TimeoutConfig::builder() |
| 57 | + .operation_attempt_timeout(Duration::from_millis(100)) |
| 58 | + .build(), |
| 59 | + ) |
| 60 | + .retry_config(RetryConfig::standard()) |
| 61 | + .build(); |
| 62 | + let client = Client::from_conf(config); |
| 63 | + let _item = client |
| 64 | + .get_item() |
| 65 | + .key("foo", AttributeValue::Bool(true)) |
| 66 | + .send() |
| 67 | + .await |
| 68 | + .expect("should succeed"); |
| 69 | + match_events!(ev!(dns), ev!(connect), _, ev!(http(200)))(&mock.events()); |
| 70 | +} |
0 commit comments