Skip to content

Commit

Permalink
Add retry count to Outcome template; add more tracing to a test
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Nov 10, 2023
1 parent e1d97a8 commit 1128914
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 80 deletions.
17 changes: 15 additions & 2 deletions src/aws-cpp-sdk-core/include/aws/core/utils/Outcome.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace Aws
result = o.result;
error = o.error;
success = o.success;
retryCount = o.retryCount;
}

return *this;
Expand All @@ -109,7 +110,8 @@ namespace Aws
Outcome(Outcome&& o) : // Required to force Move Constructor
result(std::move(o.result)),
error(std::move(o.error)),
success(o.success)
success(o.success),
retryCount(std::move(o.retryCount))
{
}

Expand All @@ -120,6 +122,7 @@ namespace Aws
result = std::move(o.result);
error = std::move(o.error);
success = o.success;
retryCount = std::move(o.retryCount);
}

return *this;
Expand Down Expand Up @@ -160,10 +163,20 @@ namespace Aws
return this->success;
}

/**
* Returns how many times the retry happened before getting this outcome.
*/
inline unsigned int GetRetryCount() const { return retryCount; }
/**
* Sets the retry count.
*/
inline void SetRetryCount(const unsigned int iRetryCount) { retryCount = iRetryCount; }

private:
R result;
E error;
bool success;
bool success = false;
unsigned int retryCount = 0;
};

} // namespace Utils
Expand Down
2 changes: 2 additions & 0 deletions src/aws-cpp-sdk-core/source/client/AWSClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri,
httpRequest->SetEventStreamRequest(request.IsEventStreamRequest());

outcome = AttemptOneRequest(httpRequest, request, signerName, signerRegion, signerServiceNameOverride);
outcome.SetRetryCount(retries);
if (retries == 0)
{
m_retryStrategy->RequestBookkeeping(outcome);
Expand Down Expand Up @@ -422,6 +423,7 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri,

};
outcome = AttemptOneRequest(httpRequest, signerName, requestName, signerRegion, signerServiceNameOverride);
outcome.SetRetryCount(retries);
if (retries == 0)
{
m_retryStrategy->RequestBookkeeping(outcome);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,28 @@ namespace

void EnsureUniqueBucketNames()
{
AppendUUID(BASE_CREATE_BUCKET_TEST_NAME);
AppendUUID(BASE_DNS_UNFRIENDLY_TEST_NAME);
AppendUUID(BASE_LOCATION_BUCKET_TEST_NAME);
AppendUUID(BASE_OBJECTS_BUCKET_NAME);
AppendUUID(BASE_OBJECTS_DEFAULT_CTOR_BUCKET_NAME);
AppendUUID(BASE_PUT_OBJECTS_BUCKET_NAME);
AppendUUID(BASE_PUT_WEIRD_CHARSETS_OBJECTS_BUCKET_NAME);
AppendUUID(BASE_PUT_OBJECTS_PRESIGNED_URLS_BUCKET_NAME);
AppendUUID(BASE_PUT_MULTIPART_BUCKET_NAME);
AppendUUID(BASE_ERRORS_TESTING_BUCKET);
AppendUUID(BASE_EVENT_STREAM_TEST_BUCKET_NAME);
AppendUUID(BASE_EVENT_STREAM_LARGE_FILE_TEST_BUCKET_NAME);
AppendUUID(BASE_EVENT_STREAM_ERRORS_IN_EVENT_TEST_BUCKET_NAME);
Aws::Vector<std::reference_wrapper<Aws::String>> TEST_BUCKETS =
{
std::ref(BASE_CREATE_BUCKET_TEST_NAME),
std::ref(BASE_DNS_UNFRIENDLY_TEST_NAME),
std::ref(BASE_LOCATION_BUCKET_TEST_NAME),
std::ref(BASE_OBJECTS_BUCKET_NAME),
std::ref(BASE_OBJECTS_DEFAULT_CTOR_BUCKET_NAME),
std::ref(BASE_PUT_OBJECTS_BUCKET_NAME),
std::ref(BASE_PUT_WEIRD_CHARSETS_OBJECTS_BUCKET_NAME),
std::ref(BASE_PUT_OBJECTS_PRESIGNED_URLS_BUCKET_NAME),
std::ref(BASE_PUT_MULTIPART_BUCKET_NAME),
std::ref(BASE_ERRORS_TESTING_BUCKET),
std::ref(BASE_EVENT_STREAM_TEST_BUCKET_NAME),
std::ref(BASE_EVENT_STREAM_LARGE_FILE_TEST_BUCKET_NAME),
std::ref(BASE_EVENT_STREAM_ERRORS_IN_EVENT_TEST_BUCKET_NAME)
};

for (auto& testBucketName : TEST_BUCKETS)
{
AppendUUID(testBucketName);
SCOPED_TRACE(Aws::String("EnsureUniqueBucketNames: ") + testBucketName.get());
}
}

class RetryFiveTimesRetryStrategy: public Aws::Client::RetryStrategy
Expand Down Expand Up @@ -357,6 +366,7 @@ namespace
static Aws::String PreparePresignedUrlTest()
{
Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_PRESIGNED_URLS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -409,6 +419,7 @@ namespace
static void CleanUpPresignedUrlTest()
{
Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_PRESIGNED_URLS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
Aws::String presignedUrlDelete = Client->GeneratePresignedUrl(fullBucketName, TEST_OBJ_KEY, HttpMethod::HTTP_DELETE);
std::shared_ptr<HttpRequest> deleteRequest = CreateHttpRequest(presignedUrlDelete, HttpMethod::HTTP_DELETE, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
std::shared_ptr<HttpResponse> deleteResponse = m_HttpClient->MakeRequest(deleteRequest);
Expand All @@ -425,6 +436,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestBucketOperationsErrorWithMissingRequiredFields)
{
Aws::String fullBucketName = CalculateBucketName(BASE_CREATE_BUCKET_TEST_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
HeadBucketRequest headBucketRequest;
HeadBucketOutcome headBucketOutcome = Client->HeadBucket(headBucketRequest);
ASSERT_FALSE(headBucketOutcome.IsSuccess());
Expand All @@ -438,8 +450,8 @@ namespace

TEST_F(BucketAndObjectOperationTest, TestBucketCreationAndListing)
{
Aws::String fullBucketName = CalculateBucketName(BASE_CREATE_BUCKET_TEST_NAME.c_str());

const Aws::String fullBucketName = CalculateBucketName(BASE_CREATE_BUCKET_TEST_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -477,6 +489,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestBucketLocation)
{
Aws::String fullBucketName = CalculateBucketName(BASE_LOCATION_BUCKET_TEST_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
CreateBucketConfiguration bucketConfiguration;
Expand Down Expand Up @@ -505,8 +518,8 @@ namespace
// S3 CRT Client could not handle these special characters in key name right now.
TEST_F(BucketAndObjectOperationTest, TestPutWithSpecialCharactersInKeyName)
{
Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());

const Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand All @@ -531,8 +544,8 @@ namespace

TEST_F(BucketAndObjectOperationTest, TestObjectOperations)
{
Aws::String fullBucketName = CalculateBucketName(BASE_OBJECTS_BUCKET_NAME.c_str());

const Aws::String fullBucketName = CalculateBucketName(BASE_OBJECTS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -605,8 +618,8 @@ namespace
//Create Client with default constructor
Client = Aws::MakeShared<S3CrtClient>(ALLOCATION_TAG);

Aws::String fullBucketName = CalculateBucketName(BASE_OBJECTS_DEFAULT_CTOR_BUCKET_NAME);

const Aws::String fullBucketName = CalculateBucketName(BASE_OBJECTS_DEFAULT_CTOR_BUCKET_NAME);
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -675,8 +688,8 @@ namespace

TEST_F(BucketAndObjectOperationTest, TestKeysWithCrazyCharacterSets)
{
Aws::String fullBucketName = CalculateBucketName(BASE_PUT_WEIRD_CHARSETS_OBJECTS_BUCKET_NAME.c_str());

const Aws::String fullBucketName = CalculateBucketName(BASE_PUT_WEIRD_CHARSETS_OBJECTS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -742,6 +755,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestObjectOperationsWithPresignedUrls)
{
Aws::String fullBucketName = PreparePresignedUrlTest();
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
Aws::String presignedUrlPut = Client->GeneratePresignedUrl(fullBucketName, TEST_OBJ_KEY, HttpMethod::HTTP_PUT);
std::shared_ptr<HttpRequest> putRequest = CreateHttpRequest(presignedUrlPut, HttpMethod::HTTP_PUT, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
DoPresignedUrlTest(fullBucketName, putRequest);
Expand All @@ -751,6 +765,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestObjectOperationsWithPresignedUrlsAndCustomizedHeaders)
{
Aws::String fullBucketName = PreparePresignedUrlTest();
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
Aws::Http::HeaderValueCollection collections;
collections.emplace("TestKey1", "TestVal1");
collections.emplace("TestKey2", "TestVal2");
Expand All @@ -768,6 +783,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestObjectOperationsWithPresignedUrlsWithSSES3)
{
Aws::String fullBucketName = PreparePresignedUrlTest();
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
Aws::String presignedUrlPut = Client->GeneratePresignedUrlWithSSES3(fullBucketName, TEST_OBJ_KEY, HttpMethod::HTTP_PUT);
std::shared_ptr<HttpRequest> putRequest = CreateHttpRequest(presignedUrlPut, HttpMethod::HTTP_PUT, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
putRequest->SetHeaderValue(Aws::S3Crt::SSEHeaders::SERVER_SIDE_ENCRYPTION,
Expand All @@ -779,6 +795,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestObjectOperationsWithPresignedUrlsWithSSES3AndCustomizedHeaders)
{
Aws::String fullBucketName = PreparePresignedUrlTest();
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
Aws::Http::HeaderValueCollection collections;
collections.emplace("TestKey1", "TestVal1");
collections.emplace("TestKey2", "TestVal2");
Expand All @@ -798,6 +815,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestObjectOperationsWithPresignedUrlsWithSSEKMS)
{
Aws::String fullBucketName = PreparePresignedUrlTest();
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
Aws::String presignedUrlPut = Client->GeneratePresignedUrlWithSSEKMS(fullBucketName, TEST_OBJ_KEY, HttpMethod::HTTP_PUT); //Using default KMS key in this AWS account
std::shared_ptr<HttpRequest> putRequest = CreateHttpRequest(presignedUrlPut, HttpMethod::HTTP_PUT, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
putRequest->SetHeaderValue(Aws::S3Crt::SSEHeaders::SERVER_SIDE_ENCRYPTION,
Expand All @@ -810,6 +828,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestObjectOperationsWithPresignedUrlsWithSSEKMSAndCustomizedHeaders)
{
Aws::String fullBucketName = PreparePresignedUrlTest();
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
Aws::Http::HeaderValueCollection collections;
collections.emplace("TestKey1", "TestVal1");
collections.emplace("TestKey2", "TestVal2");
Expand All @@ -828,8 +847,8 @@ namespace

TEST_F(BucketAndObjectOperationTest, TestThatErrorsParse)
{
Aws::String fullBucketName = CalculateBucketName(BASE_ERRORS_TESTING_BUCKET.c_str());

const Aws::String fullBucketName = CalculateBucketName(BASE_ERRORS_TESTING_BUCKET.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
ListObjectsRequest listObjectsRequest;
listObjectsRequest.SetBucket("abcdedoikengi");

Expand Down Expand Up @@ -860,6 +879,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestNotModifiedIsSuccess)
{
Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -895,6 +915,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestVirtualAddressingWithUnfriendlyBucketName)
{
Aws::String fullBucketName = CalculateBucketName(BASE_DNS_UNFRIENDLY_TEST_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -928,6 +949,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestCopyingFromKeysWithUnicodeCharacters)
{
Aws::String fullBucketName = CalculateBucketName(BASE_CREATE_BUCKET_TEST_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -962,6 +984,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestObjectOperationWithEventStream)
{
Aws::String fullBucketName = CalculateBucketName(BASE_EVENT_STREAM_TEST_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -1041,6 +1064,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestSelectObjectOperationWithEventStreamFailWithRetry)
{
Aws::String fullBucketName = CalculateBucketName(BASE_EVENT_STREAM_TEST_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -1116,6 +1140,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestEventStreamWithLargeFile)
{
Aws::String fullBucketName = CalculateBucketName(BASE_EVENT_STREAM_LARGE_FILE_TEST_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -1221,6 +1246,7 @@ namespace
TEST_F(BucketAndObjectOperationTest, TestErrorsInEventStream)
{
Aws::String fullBucketName = CalculateBucketName(BASE_EVENT_STREAM_ERRORS_IN_EVENT_TEST_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down Expand Up @@ -1290,8 +1316,8 @@ namespace

TEST_F(BucketAndObjectOperationTest, TestEmptyBody)
{
Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());

const Aws::String fullBucketName = CalculateBucketName(BASE_PUT_OBJECTS_BUCKET_NAME.c_str());
SCOPED_TRACE(Aws::String("FullBucketName ") + fullBucketName);
CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(fullBucketName);
createBucketRequest.SetACL(BucketCannedACL::private_);
Expand Down
Loading

0 comments on commit 1128914

Please sign in to comment.