/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #pragma once #include #include #include #include #include #include #include #if defined(GetMessage) #undef GetMessage #endif #define AWS_ASSERT_SUCCESS(awsCppSdkOutcome) \ ASSERT_TRUE(awsCppSdkOutcome.IsSuccess()) << "Error details: " << awsCppSdkOutcome.GetError() \ << "\nNow timestamp: " << Aws::Utils::DateTime::Now().ToGmtString(Aws::Utils::DateFormat::ISO_8601_BASIC) #define AWS_EXPECT_SUCCESS(awsCppSdkOutcome) \ EXPECT_TRUE(awsCppSdkOutcome.IsSuccess()) << "Error details: " << awsCppSdkOutcome.GetError() \ << "\nNow timestamp: " << Aws::Utils::DateTime::Now().ToGmtString(Aws::Utils::DateFormat::ISO_8601_BASIC) /** * AWS-CPP-SDK test utility helper function to un-conditionally retry not succeeded operation call. * This is just to simplify testing, not to re-create and re-configure clients. * Please use retry strategies in a real production code: * https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html * @tparam OutcomeT * @param funcToCall * @param retries * @param sleepBetween * @return OutcomeT */ template OutcomeT CallOperationWithUnconditionalRetry(std::function funcToCall, const size_t retries = 5, const std::chrono::seconds sleepBetween = std::chrono::seconds (1)) { OutcomeT outcome = funcToCall(); size_t attempt = 0; while(!outcome.IsSuccess() && attempt < retries) { outcome = funcToCall(); attempt++; std::this_thread::sleep_for(sleepBetween); }; return outcome; } template OutcomeT CallOperationWithUnconditionalRetry(const ClientT* client, OutcomeT (ClientT::*OperationFunc)(const RequestT&) const, const RequestT& request, const size_t retries = 5, const std::chrono::seconds sleepBetween = std::chrono::seconds (1)) { if(!client) { return OutcomeT(Aws::Client::AWSError( Aws::Client::CoreErrors::VALIDATION, "", "CallOperationWithUnconditionalRetry: client is a nullptr", false/*retryable*/)); } std::function func = std::bind(OperationFunc, client, request); return CallOperationWithUnconditionalRetry(func, retries, sleepBetween); }