33 * SPDX-License-Identifier: Apache-2.0.
44 */
55
6+ #include < aws/core/client/ClientConfiguration.h>
67#include < aws/core/utils/StringUtils.h>
8+ #include < aws/core/utils/logging/LogMacros.h>
9+ #include < aws/core/utils/memory/AWSMemory.h>
710#include < aws/core/utils/memory/stl/AWSAllocator.h>
811#include < aws/core/utils/memory/stl/AWSString.h>
912#include < aws/core/utils/memory/stl/AWSStringStream.h>
2124#include < performance-tests/Utils.h>
2225#include < performance-tests/services/s3/S3PerformanceTest.h>
2326
24- void PerformanceTest::Services::S3::RunTest (Aws::S3::S3Client& s3, const TestCase& config, const Aws::String& availabilityZoneId,
25- int iterations) {
26- auto bucketName = SetupBucket (s3, config, availabilityZoneId);
27- if (bucketName.empty ()) {
28- return ;
29- }
27+ #include < cstring>
3028
31- RunOperations (s3, bucketName, config, iterations);
32- CleanupResources (s3, bucketName, iterations);
33- }
29+ PerformanceTest::Services::S3::S3PerformanceTest::S3PerformanceTest (const Aws::String& region, const TestCase& config,
30+ const Aws::String& availabilityZoneId, int iterations)
31+ : m_config(config), m_region(region), m_availabilityZoneId(availabilityZoneId), m_iterations(iterations) {}
32+
33+ void PerformanceTest::Services::S3::S3PerformanceTest::Setup () {
34+ Aws::Client::ClientConfiguration cfg;
35+ cfg.region = m_region;
36+ m_s3 = Aws::MakeUnique<Aws::S3::S3Client>(" S3PerformanceTest" , cfg);
3437
35- Aws::String PerformanceTest::Services::S3::SetupBucket (Aws::S3::S3Client& s3, const TestCase& config,
36- const Aws::String& availabilityZoneId) {
37- Aws::String bucketName;
3838 Aws::S3::Model::CreateBucketRequest cbr;
3939 Aws::String const bucketId = PerformanceTest::Utils::GenerateUniqueId ();
4040
41- if (config .bucketTypeLabel == " s3-express" ) {
42- bucketName = " perf-express-" + bucketId + " --" + availabilityZoneId + " --x-s3" ;
43- cbr.SetBucket (bucketName );
41+ if (strcmp (m_config .bucketTypeLabel , " s3-express" ) == 0 ) {
42+ m_bucketName = " perf-express-" + bucketId + " --" + m_availabilityZoneId + " --x-s3" ;
43+ cbr.SetBucket (m_bucketName );
4444 Aws::S3::Model::CreateBucketConfiguration bucketConfig;
4545 bucketConfig.SetLocation (
46- Aws::S3::Model::LocationInfo ().WithType (Aws::S3::Model::LocationType::AvailabilityZone).WithName (availabilityZoneId ));
46+ Aws::S3::Model::LocationInfo ().WithType (Aws::S3::Model::LocationType::AvailabilityZone).WithName (m_availabilityZoneId ));
4747
4848 bucketConfig.SetBucket (Aws::S3::Model::BucketInfo ()
4949 .WithType (Aws::S3::Model::BucketType::Directory)
5050 .WithDataRedundancy (Aws::S3::Model::DataRedundancy::SingleAvailabilityZone));
5151
5252 cbr.SetCreateBucketConfiguration (bucketConfig);
5353 } else {
54- bucketName = " perf-standard-" + bucketId;
55- cbr.SetBucket (bucketName );
54+ m_bucketName = " perf-standard-" + bucketId;
55+ cbr.SetBucket (m_bucketName );
5656 }
5757
58- auto createOutcome = s3. CreateBucket (cbr);
58+ auto createOutcome = m_s3-> CreateBucket (cbr);
5959 if (!createOutcome.IsSuccess ()) {
60- PerformanceTest::Utils::LogError ( " S3 " , " CreateBucket" , createOutcome.GetError ().GetMessage ());
61- return " " ;
60+ AWS_LOG_ERROR ( " PerformanceTest " , ( " S3: CreateBucket failed: " + createOutcome.GetError ().GetMessage ()). c_str ());
61+ m_bucketName. clear () ;
6262 }
63-
64- return bucketName;
6563}
6664
67- void PerformanceTest::Services::S3::RunOperations (Aws::S3::S3Client& s3, const Aws::String& bucketName, const TestCase& config,
68- int iterations) {
69- const auto randomPayload = PerformanceTest::Utils::RandomString (config.sizeBytes );
65+ void PerformanceTest::Services::S3::S3PerformanceTest::Run () {
66+ if (m_bucketName.empty ()) {
67+ AWS_LOG_ERROR (" PerformanceTest" , " S3:Run - Bucket setup failed, skipping test" );
68+ return ;
69+ }
70+
71+ const auto randomPayload = PerformanceTest::Utils::RandomString (m_config.sizeBytes );
7072
7173 // Run PutObject multiple times
72- for (int i = 0 ; i < iterations ; i++) {
74+ for (int i = 0 ; i < m_iterations ; i++) {
7375 auto stream = Aws::MakeShared<Aws::StringStream>(" PerfStream" );
7476 *stream << randomPayload;
7577
7678 Aws::S3::Model::PutObjectRequest por;
77- por.WithBucket (bucketName ).WithKey (" test-object-" + Aws::Utils::StringUtils::to_string (i)).SetBody (stream);
78- por.SetAdditionalCustomHeaderValue (" test-dimension-size" , config .sizeLabel );
79- por.SetAdditionalCustomHeaderValue (" test-dimension-bucket-type" , config .bucketTypeLabel );
80- auto putOutcome = s3. PutObject (por);
79+ por.WithBucket (m_bucketName ).WithKey (" test-object-" + Aws::Utils::StringUtils::to_string (i)).SetBody (stream);
80+ por.SetAdditionalCustomHeaderValue (" test-dimension-size" , m_config .sizeLabel );
81+ por.SetAdditionalCustomHeaderValue (" test-dimension-bucket-type" , m_config .bucketTypeLabel );
82+ auto putOutcome = m_s3-> PutObject (por);
8183 if (!putOutcome.IsSuccess ()) {
82- PerformanceTest::Utils::LogError ( " S3 " , " PutObject" , putOutcome.GetError ().GetMessage ());
84+ AWS_LOG_ERROR ( " PerformanceTest " , ( " S3: PutObject failed: " + putOutcome.GetError ().GetMessage ()). c_str ());
8385 }
8486 }
8587
8688 // Run GetObject multiple times
87- for (int i = 0 ; i < iterations ; i++) {
89+ for (int i = 0 ; i < m_iterations ; i++) {
8890 Aws::S3::Model::GetObjectRequest gor;
89- gor.WithBucket (bucketName ).WithKey (" test-object-" + Aws::Utils::StringUtils::to_string (i));
90- gor.SetAdditionalCustomHeaderValue (" test-dimension-size" , config .sizeLabel );
91- gor.SetAdditionalCustomHeaderValue (" test-dimension-bucket-type" , config .bucketTypeLabel );
92- auto getOutcome = s3. GetObject (gor);
91+ gor.WithBucket (m_bucketName ).WithKey (" test-object-" + Aws::Utils::StringUtils::to_string (i));
92+ gor.SetAdditionalCustomHeaderValue (" test-dimension-size" , m_config .sizeLabel );
93+ gor.SetAdditionalCustomHeaderValue (" test-dimension-bucket-type" , m_config .bucketTypeLabel );
94+ auto getOutcome = m_s3-> GetObject (gor);
9395 if (!getOutcome.IsSuccess ()) {
94- PerformanceTest::Utils::LogError ( " S3 " , " GetObject" , getOutcome.GetError ().GetMessage ());
96+ AWS_LOG_ERROR ( " PerformanceTest " , ( " S3: GetObject failed: " + getOutcome.GetError ().GetMessage ()). c_str ());
9597 }
9698 }
9799}
98100
99- void PerformanceTest::Services::S3::CleanupResources (Aws::S3::S3Client& s3, const Aws::String& bucketName, int iterations) {
100- for (int i = 0 ; i < iterations; i++) {
101- auto deleteObjectOutcome = s3.DeleteObject (
102- Aws::S3::Model::DeleteObjectRequest ().WithBucket (bucketName).WithKey (" test-object-" + Aws::Utils::StringUtils::to_string (i)));
101+ void PerformanceTest::Services::S3::S3PerformanceTest::TearDown () {
102+ if (m_bucketName.empty ()) {
103+ AWS_LOG_ERROR (" PerformanceTest" , " S3:TearDown - No bucket to clean up, setup likely failed" );
104+ return ;
105+ }
106+
107+ for (int i = 0 ; i < m_iterations; i++) {
108+ auto deleteObjectOutcome = m_s3->DeleteObject (
109+ Aws::S3::Model::DeleteObjectRequest ().WithBucket (m_bucketName).WithKey (" test-object-" + Aws::Utils::StringUtils::to_string (i)));
103110 if (!deleteObjectOutcome.IsSuccess ()) {
104- PerformanceTest::Utils::LogError ( " S3 " , " DeleteObject" , deleteObjectOutcome.GetError ().GetMessage ());
111+ AWS_LOG_ERROR ( " PerformanceTest " , ( " S3: DeleteObject failed: " + deleteObjectOutcome.GetError ().GetMessage ()). c_str ());
105112 }
106113 }
107114
108- auto deleteBucketOutcome = s3. DeleteBucket (Aws::S3::Model::DeleteBucketRequest ().WithBucket (bucketName ));
115+ auto deleteBucketOutcome = m_s3-> DeleteBucket (Aws::S3::Model::DeleteBucketRequest ().WithBucket (m_bucketName ));
109116 if (!deleteBucketOutcome.IsSuccess ()) {
110- PerformanceTest::Utils::LogError ( " S3 " , " DeleteBucket" , deleteBucketOutcome.GetError ().GetMessage ());
117+ AWS_LOG_ERROR ( " PerformanceTest " , ( " S3: DeleteBucket failed: " + deleteBucketOutcome.GetError ().GetMessage ()). c_str ());
111118 }
112119}
0 commit comments