Skip to content

Commit 547ee89

Browse files
committed
fix pr issues
1 parent b1111bb commit 547ee89

File tree

11 files changed

+262
-246
lines changed

11 files changed

+262
-246
lines changed

tests/performance-tests/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ add_project(performance-tests
99
aws-cpp-sdk-dynamodb
1010
)
1111

12+
# Add cxxopts dependency
13+
include(FetchContent)
14+
FetchContent_Declare(
15+
cxxopts
16+
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
17+
GIT_TAG v3.1.1
18+
)
19+
FetchContent_MakeAvailable(cxxopts)
20+
1221
function(add_service_test SERVICE SDK_LIB PERF_TEST_FILE)
1322
add_executable(${SERVICE}-performance-test
1423
src/services/${SERVICE}/main.cpp
@@ -18,8 +27,8 @@ function(add_service_test SERVICE SDK_LIB PERF_TEST_FILE)
1827
set_compiler_flags(${SERVICE}-performance-test)
1928
set_compiler_warnings(${SERVICE}-performance-test)
2029
target_include_directories(${SERVICE}-performance-test PRIVATE include)
21-
target_link_libraries(${SERVICE}-performance-test PRIVATE aws-cpp-sdk-core ${SDK_LIB})
22-
target_compile_options(${SERVICE}-performance-test PRIVATE -std=c++17)
30+
target_link_libraries(${SERVICE}-performance-test PRIVATE aws-cpp-sdk-core ${SDK_LIB} cxxopts::cxxopts)
31+
target_compile_options(${SERVICE}-performance-test PRIVATE -std=c++17 -fexceptions)
2332
endfunction()
2433

2534
add_service_test(s3 aws-cpp-sdk-s3 S3PerformanceTest.cpp)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#pragma once
7+
8+
namespace PerformanceTest {
9+
10+
/**
11+
* Base class for all performance tests.
12+
*/
13+
class PerformanceTestBase {
14+
public:
15+
virtual ~PerformanceTestBase() = default;
16+
17+
/**
18+
* Initialize resources for the test.
19+
*/
20+
virtual void Setup() = 0;
21+
22+
/**
23+
* Run the performance test operations.
24+
*/
25+
virtual void Run() = 0;
26+
27+
/**
28+
* Clean up resources created during setup.
29+
*/
30+
virtual void TearDown() = 0;
31+
};
32+
33+
} // namespace PerformanceTest

tests/performance-tests/include/performance-tests/Utils.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66
#pragma once
77

8-
#include <aws/core/Aws.h>
98
#include <aws/core/utils/StringUtils.h>
109
#include <aws/core/utils/UUID.h>
1110
#include <aws/core/utils/memory/stl/AWSString.h>
1211

1312
#include <algorithm>
1413
#include <cstddef>
1514
#include <cstdlib>
16-
#include <iostream>
17-
#include <random>
18-
#include <string>
1915

2016
namespace PerformanceTest {
2117
namespace Utils {
@@ -37,16 +33,6 @@ static inline Aws::String RandomString(size_t length) {
3733
return str;
3834
}
3935

40-
/**
41-
* Log error messages to stderr.
42-
* @param service The name of the AWS service
43-
* @param operation The name of the operation that failed
44-
* @param message The error message to log
45-
*/
46-
static inline void LogError(const Aws::String& service, const Aws::String& operation, const Aws::String& message) {
47-
std::cerr << "[ERROR] " << service << ":" << operation << " failed: " << message << '\n';
48-
}
49-
5036
/**
5137
* Generate a unique identifier using UUID.
5238
* @return A 10-character lowercase UUID substring
@@ -56,16 +42,5 @@ static inline Aws::String GenerateUniqueId() {
5642
return Aws::Utils::StringUtils::ToLower(rawUUID.c_str()).substr(0, 10);
5743
}
5844

59-
/**
60-
* Get the current SDK version as a formatted string.
61-
* @return SDK version in the format "major.minor.patch" (e.g., "1.11.0")
62-
*/
63-
static inline Aws::String GetSDKVersionString() {
64-
Aws::SDKOptions::SDKVersion const version;
65-
return Aws::Utils::StringUtils::to_string(static_cast<int>(version.major)) + "." +
66-
Aws::Utils::StringUtils::to_string(static_cast<int>(version.minor)) + "." +
67-
Aws::Utils::StringUtils::to_string(static_cast<int>(version.patch));
68-
}
69-
7045
} // namespace Utils
7146
} // namespace PerformanceTest

tests/performance-tests/include/performance-tests/services/dynamodb/DynamoDBPerformanceTest.h

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
#pragma once
77

8+
#include <aws/core/utils/memory/AWSMemory.h>
89
#include <aws/core/utils/memory/stl/AWSString.h>
910
#include <aws/dynamodb/DynamoDBClient.h>
11+
#include <performance-tests/PerformanceTestBase.h>
1012

1113
#include <cstddef>
1214

@@ -17,42 +19,30 @@ namespace DynamoDB {
1719
* Configuration for DynamoDB performance test cases.
1820
*/
1921
struct TestCase {
20-
Aws::String sizeLabel;
22+
const char* sizeLabel;
2123
size_t sizeBytes;
2224
};
2325

2426
/**
25-
* Runs DynamoDB performance test by creating a table, performing PutItem and GetItem operations,
26-
* then cleaning up resources.
27-
* @param dynamodb DynamoDB client instance to use for operations
28-
* @param config Test configuration containing size parameters
29-
* @param iterations Number of put/get operations to perform
27+
* DynamoDB performance test implementation.
28+
* Tests PutItem and GetItem operations with different payload sizes.
3029
*/
31-
void RunTest(Aws::DynamoDB::DynamoDBClient& dynamodb, const TestCase& config, int iterations = 3);
32-
33-
/**
34-
* Create DynamoDB table for testing and wait for it to become active.
35-
* @param dynamodb DynamoDB client instance
36-
* @param config Test configuration
37-
* @return Table name if successful, empty string if failed
38-
*/
39-
Aws::String SetupTable(Aws::DynamoDB::DynamoDBClient& dynamodb, const TestCase& config);
40-
41-
/**
42-
* Run PutItem and GetItem operations.
43-
* @param dynamodb DynamoDB client instance
44-
* @param tableName Name of the table to use
45-
* @param config Test configuration
46-
* @param iterations Number of operations to perform
47-
*/
48-
void RunOperations(Aws::DynamoDB::DynamoDBClient& dynamodb, const Aws::String& tableName, const TestCase& config, int iterations);
30+
class DynamoDBPerformanceTest : public PerformanceTestBase {
31+
public:
32+
DynamoDBPerformanceTest(const Aws::String& region, const TestCase& config, int iterations = 3);
33+
34+
void Setup() override;
35+
void TearDown() override;
36+
void Run() override;
37+
38+
private:
39+
const TestCase& m_config;
40+
const Aws::String m_region;
41+
const int m_iterations;
42+
Aws::UniquePtr<Aws::DynamoDB::DynamoDBClient> m_dynamodb;
43+
Aws::String m_tableName;
44+
};
4945

50-
/**
51-
* Clean up DynamoDB resources (delete table).
52-
* @param dynamodb DynamoDB client instance
53-
* @param tableName Name of the table to delete
54-
*/
55-
void CleanupResources(Aws::DynamoDB::DynamoDBClient& dynamodb, const Aws::String& tableName);
5646
} // namespace DynamoDB
5747
} // namespace Services
5848
} // namespace PerformanceTest

tests/performance-tests/include/performance-tests/services/dynamodb/DynamoDBTestConfig.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55

66
#pragma once
77

8-
#include <aws/core/utils/memory/stl/AWSSet.h>
9-
#include <aws/core/utils/memory/stl/AWSString.h>
10-
#include <aws/core/utils/memory/stl/AWSVector.h>
8+
#include <performance-tests/services/dynamodb/DynamoDBPerformanceTest.h>
9+
10+
#include <array>
11+
#include <set>
1112

1213
namespace PerformanceTest {
1314
namespace Services {
1415
namespace DynamoDB {
1516
namespace TestConfig {
16-
const Aws::Set<Aws::String> TestOperations = {"PutItem", "GetItem"};
17+
const std::set<const char*> TestOperations = {"PutItem", "GetItem"};
1718

18-
const Aws::Vector<TestCase> TestMatrix = {{"8KB", 8 * 1024}, {"64KB", 64 * 1024}, {"392KB", 392 * 1024}};
19+
const std::array<TestCase, 3> TestMatrix = {{{"8KB", 8 * 1024}, {"64KB", 64 * 1024}, {"392KB", 392 * 1024}}};
1920

20-
const Aws::String OutputFilename = "dynamodb-performance-test-results.json";
21+
const char* OutputFilename = "dynamodb-performance-test-results.json";
2122
} // namespace TestConfig
2223
} // namespace DynamoDB
2324
} // namespace Services

tests/performance-tests/include/performance-tests/services/s3/S3PerformanceTest.h

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
#pragma once
77

8+
#include <aws/core/utils/memory/AWSMemory.h>
89
#include <aws/core/utils/memory/stl/AWSString.h>
910
#include <aws/s3/S3Client.h>
11+
#include <performance-tests/PerformanceTestBase.h>
1012

1113
#include <cstddef>
1214

@@ -17,46 +19,32 @@ namespace S3 {
1719
* Configuration for S3 performance test cases.
1820
*/
1921
struct TestCase {
20-
Aws::String sizeLabel;
22+
const char* sizeLabel;
2123
size_t sizeBytes;
22-
Aws::String bucketTypeLabel;
24+
const char* bucketTypeLabel;
2325
};
2426

2527
/**
26-
* Runs S3 performance test by creating a bucket, performing PutObject and GetObject operations,
27-
* then cleaning up resources.
28-
* @param s3 S3 client instance to use for operations
29-
* @param config Test configuration containing object size and bucket type parameters
30-
* @param availabilityZoneId Availability zone ID for S3 Express buckets
31-
* @param iterations Number of put/get operations to perform
28+
* S3 performance test implementation.
29+
* Tests PutObject and GetObject operations with different payload sizes and bucket types.
3230
*/
33-
void RunTest(Aws::S3::S3Client& s3, const TestCase& config, const Aws::String& availabilityZoneId, int iterations = 3);
34-
35-
/**
36-
* Create S3 bucket for testing.
37-
* @param s3 S3 client instance
38-
* @param config Test configuration
39-
* @param availabilityZoneId Availability zone ID for S3 Express buckets
40-
* @return Bucket name if successful, empty string if failed
41-
*/
42-
Aws::String SetupBucket(Aws::S3::S3Client& s3, const TestCase& config, const Aws::String& availabilityZoneId);
43-
44-
/**
45-
* Run PutObject and GetObject operations.
46-
* @param s3 S3 client instance
47-
* @param bucketName Name of the bucket to use
48-
* @param config Test configuration
49-
* @param iterations Number of operations to perform
50-
*/
51-
void RunOperations(Aws::S3::S3Client& s3, const Aws::String& bucketName, const TestCase& config, int iterations);
31+
class S3PerformanceTest : public PerformanceTestBase {
32+
public:
33+
S3PerformanceTest(const Aws::String& region, const TestCase& config, const Aws::String& availabilityZoneId, int iterations = 3);
34+
35+
void Setup() override;
36+
void TearDown() override;
37+
void Run() override;
38+
39+
private:
40+
const TestCase& m_config;
41+
const Aws::String m_region;
42+
const Aws::String m_availabilityZoneId;
43+
const int m_iterations;
44+
Aws::UniquePtr<Aws::S3::S3Client> m_s3;
45+
Aws::String m_bucketName;
46+
};
5247

53-
/**
54-
* Clean up S3 resources (objects and bucket).
55-
* @param s3 S3 client instance
56-
* @param bucketName Name of the bucket to clean up
57-
* @param iterations Number of objects to delete
58-
*/
59-
void CleanupResources(Aws::S3::S3Client& s3, const Aws::String& bucketName, int iterations);
6048
} // namespace S3
6149
} // namespace Services
6250
} // namespace PerformanceTest

tests/performance-tests/include/performance-tests/services/s3/S3TestConfig.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55

66
#pragma once
77

8-
#include <aws/core/utils/memory/stl/AWSSet.h>
9-
#include <aws/core/utils/memory/stl/AWSString.h>
10-
#include <aws/core/utils/memory/stl/AWSVector.h>
8+
#include <performance-tests/services/s3/S3PerformanceTest.h>
9+
10+
#include <array>
11+
#include <set>
1112

1213
namespace PerformanceTest {
1314
namespace Services {
1415
namespace S3 {
1516
namespace TestConfig {
16-
const Aws::Set<Aws::String> TestOperations = {"PutObject", "GetObject"};
17+
const std::set<const char*> TestOperations = {"PutObject", "GetObject"};
1718

18-
const Aws::Vector<TestCase> TestMatrix = {{"8KB", 8 * 1024, "s3-standard"}, {"64KB", 64 * 1024, "s3-standard"},
19-
{"1MB", 1024 * 1024, "s3-standard"}, {"8KB", 8 * 1024, "s3-express"},
20-
{"64KB", 64 * 1024, "s3-express"}, {"1MB", 1024 * 1024, "s3-express"}};
19+
const std::array<TestCase, 6> TestMatrix = {{{"8KB", 8 * 1024, "s3-standard"},
20+
{"64KB", 64 * 1024, "s3-standard"},
21+
{"1MB", 1024 * 1024, "s3-standard"},
22+
{"8KB", 8 * 1024, "s3-express"},
23+
{"64KB", 64 * 1024, "s3-express"},
24+
{"1MB", 1024 * 1024, "s3-express"}}};
2125

22-
const Aws::String OutputFilename = "s3-performance-test-results.json";
26+
const char* OutputFilename = "s3-performance-test-results.json";
2327
} // namespace TestConfig
2428
} // namespace S3
2529
} // namespace Services

0 commit comments

Comments
 (0)