From 1de8cf83460b69f4989d9c27d75ea75fe187db98 Mon Sep 17 00:00:00 2001 From: Cedric LE CAM Date: Wed, 11 Sep 2024 15:35:16 +0200 Subject: [PATCH] Fix memory mismatch. --- src/s3plugin.cpp | 182 +++++++++++++++++++++------------------- src/s3plugin_internal.h | 28 +++---- test/basic_test.cpp | 62 +++++++------- 3 files changed, 139 insertions(+), 133 deletions(-) diff --git a/src/s3plugin.cpp b/src/s3plugin.cpp index eab388b..4e5cf82 100644 --- a/src/s3plugin.cpp +++ b/src/s3plugin.cpp @@ -42,15 +42,15 @@ int bIsConnected = false; constexpr const char* S3EndpointProvider = "KHIOPS_ML_S3"; Aws::SDKOptions options; -std::unique_ptr client; +Aws::UniquePtr client; // Global bucket name -std::string globalBucketName = ""; +Aws::String globalBucketName = ""; HandleContainer active_reader_handles; HandleContainer active_writer_handles; -std::string last_error; +Aws::String last_error; constexpr const char* nullptr_msg_stub = "Error passing null pointer to "; @@ -58,6 +58,7 @@ constexpr const char* nullptr_msg_stub = "Error passing null pointer to "; void test_setClient(Aws::S3::S3Client* mock_client) { + client = Aws::MakeUnique("S3_TEST"); client.reset(mock_client); bIsConnected = kTrue; } @@ -93,7 +94,7 @@ void* test_getActiveWriterHandles() #define ERROR_ON_NULL_ARG(arg, err_val) \ if (!(arg)) \ { \ - std::ostringstream os; \ + Aws::OStringStream os; \ os << nullptr_msg_stub << __func__; \ LogError(os.str()); \ return (err_val); \ @@ -138,33 +139,33 @@ void* test_getActiveWriterHandles() ERROR_ON_NAMES(maybe_parsed_names, (err_val)); \ auto& names = maybe_parsed_names.GetResult(); -void LogError(const std::string& msg) +void LogError(const Aws::String& msg) { spdlog::error(msg); last_error = std::move(msg); } -template void LogBadOutcome(const Aws::Utils::Outcome& outcome, const std::string& msg) +template void LogBadOutcome(const Aws::Utils::Outcome& outcome, const Aws::String& msg) { - std::ostringstream os; + Aws::OStringStream os; os << msg << ": " << outcome.GetError().GetMessage(); LogError(os.str()); } -template RequestType MakeBaseRequest(const std::string& bucket, const std::string& object) +template RequestType MakeBaseRequest(const Aws::String& bucket, const Aws::String& object) { RequestType request; request.WithBucket(bucket).WithKey(object); return request; } -Aws::S3::Model::HeadObjectRequest MakeHeadObjectRequest(const std::string& bucket, const std::string& object) +Aws::S3::Model::HeadObjectRequest MakeHeadObjectRequest(const Aws::String& bucket, const Aws::String& object) { return MakeBaseRequest(bucket, object); } -Aws::S3::Model::GetObjectRequest MakeGetObjectRequest(const std::string& bucket, const std::string& object, - std::string&& range = "") +Aws::S3::Model::GetObjectRequest MakeGetObjectRequest(const Aws::String& bucket, const Aws::String& object, + Aws::String&& range = "") { auto request = MakeBaseRequest(bucket, object); if (!range.empty()) @@ -174,13 +175,13 @@ Aws::S3::Model::GetObjectRequest MakeGetObjectRequest(const std::string& bucket, return request; } -Aws::S3::Model::GetObjectOutcome GetObject(const std::string& bucket, const std::string& object, - std::string&& range = "") +Aws::S3::Model::GetObjectOutcome GetObject(const Aws::String& bucket, const Aws::String& object, + Aws::String&& range = "") { return client->GetObject(MakeGetObjectRequest(bucket, object, std::move(range))); } -Aws::S3::Model::HeadObjectOutcome HeadObject(const std::string& bucket, const std::string& object) +Aws::S3::Model::HeadObjectOutcome HeadObject(const Aws::String& bucket, const Aws::String& object) { return client->HeadObject(MakeHeadObjectRequest(bucket, object)); } @@ -199,9 +200,9 @@ template void EraseRemove(HandleContainer& container, HandleIt(err_code), std::move(err_msg)}; } @@ -240,11 +241,11 @@ SimpleError MakeSimpleError(const Aws::S3::S3Error& from) struct ParseUriResult { - std::string bucket_; - std::string object_; + Aws::String bucket_; + Aws::String object_; }; -using ObjectsVec = std::vector; +using ObjectsVec = Aws::Vector; template using SimpleOutcome = Aws::Utils::Outcome; @@ -254,7 +255,7 @@ using FilterOutcome = SimpleOutcome; using UploadOutcome = SimpleOutcome; // R can't be void // Definition of helper functions -SizeOutcome DownloadFileRangeToBuffer(const std::string& bucket, const std::string& object_name, char* buffer, +SizeOutcome DownloadFileRangeToBuffer(const Aws::String& bucket, const Aws::String& object_name, char* buffer, std::int64_t start_range, std::int64_t end_range) { // determine byte range to download from object @@ -290,7 +291,7 @@ SizeOutcome ReadBytesInFile(MultiPartFile& multifile, char* buffer, tOffset to_r // Lookup item containing initial bytes at requested offset const auto& cumul_sizes = multifile.cumulative_sizes_; const tOffset common_header_length = multifile.common_header_length_; - const std::string& bucket_name = multifile.bucketname_; + const Aws::String& bucket_name = multifile.bucketname_; const auto& filenames = multifile.filenames_; char* buffer_pos = buffer; tOffset& offset = multifile.offset_; @@ -301,7 +302,7 @@ SizeOutcome ReadBytesInFile(MultiPartFile& multifile, char* buffer, tOffset to_r spdlog::debug("Use item {} to read @ {} (end = {})", idx, offset, *greater_than_offset_it); - auto read_range_and_update = [&](const std::string& filename, tOffset start, tOffset end) -> SizeOutcome + auto read_range_and_update = [&](const Aws::String& filename, tOffset start, tOffset end) -> SizeOutcome { auto download_outcome = DownloadFileRangeToBuffer( bucket_name, filename, buffer_pos, static_cast(start), static_cast(end)); @@ -358,34 +359,34 @@ SizeOutcome ReadBytesInFile(MultiPartFile& multifile, char* buffer, tOffset to_r return read_outcome; } -bool UploadBuffer(const std::string& bucket_name, const std::string& object_name, const char* buffer, - std::size_t buffer_size) -{ +// bool UploadBuffer(const Aws::String& bucket_name, const Aws::String& object_name, const char* buffer, +// std::size_t buffer_size) +// { - Aws::S3::Model::PutObjectRequest request; - request.SetBucket(bucket_name); - request.SetKey(object_name); +// Aws::S3::Model::PutObjectRequest request; +// request.SetBucket(bucket_name); +// request.SetKey(object_name); - const std::shared_ptr inputData = Aws::MakeShared(""); - std::string data; - data.assign(buffer, buffer_size); - *inputData << data.c_str(); +// const std::shared_ptr inputData = Aws::MakeShared(""); +// std::string data; +// data.assign(buffer, buffer_size); +// *inputData << data.c_str(); - request.SetBody(inputData); +// request.SetBody(inputData); - Aws::S3::Model::PutObjectOutcome outcome = client->PutObject(request); +// Aws::S3::Model::PutObjectOutcome outcome = client->PutObject(request); - if (!outcome.IsSuccess()) - { - spdlog::error("PutObjectBuffer: {}", outcome.GetError().GetMessage()); - } +// if (!outcome.IsSuccess()) +// { +// spdlog::error("PutObjectBuffer: {}", outcome.GetError().GetMessage()); +// } - return outcome.IsSuccess(); -} +// return outcome.IsSuccess(); +// } -ParseURIOutcome ParseS3Uri(const std::string& s3_uri) +ParseURIOutcome ParseS3Uri(const Aws::String& s3_uri) { //, std::string &bucket_name, std::string &object_name) { - const std::string prefix = "s3://"; + const Aws::String prefix = "s3://"; const size_t prefix_size = prefix.size(); if (s3_uri.compare(0, prefix_size, prefix) != 0) { @@ -407,7 +408,7 @@ ParseURIOutcome ParseS3Uri(const std::string& s3_uri) // return false; } - std::string bucket_name = s3_uri.substr(prefix_size, pos - prefix_size); + Aws::String bucket_name = s3_uri.substr(prefix_size, pos - prefix_size); if (bucket_name.empty()) { @@ -419,7 +420,7 @@ ParseURIOutcome ParseS3Uri(const std::string& s3_uri) bucket_name = globalBucketName; } - std::string object_name = s3_uri.substr(pos + 1); + Aws::String object_name = s3_uri.substr(pos + 1); return ParseUriResult{std::move(bucket_name), std::move(object_name)}; } @@ -434,13 +435,13 @@ ParseURIOutcome ParseS3Uri(const std::string& s3_uri) // spdlog::critical("No bucket specified, and GCS_BUCKET_NAME is not set!"); // } -std::string GetEnvironmentVariableOrDefault(const std::string& variable_name, const std::string& default_value) +Aws::String GetEnvironmentVariableOrDefault(const Aws::String& variable_name, const Aws::String& default_value) { const char* value = getenv(variable_name.c_str()); return value ? value : default_value; } -bool IsMultifile(const std::string& pattern, size_t& first_special_char_idx) +bool IsMultifile(const Aws::String& pattern, size_t& first_special_char_idx) { spdlog::debug("Parse multifile pattern {}", pattern); @@ -492,7 +493,7 @@ bool IsMultifile(const std::string& pattern, size_t& first_special_char_idx) // return -1 // } -Aws::S3::Model::ListObjectsV2Outcome ListObjects(const std::string& bucket, const std::string& pattern) +Aws::S3::Model::ListObjectsV2Outcome ListObjects(const Aws::String& bucket, const Aws::String& pattern) { Aws::S3::Model::ListObjectsV2Request request; request.WithBucket(bucket).WithPrefix(pattern).WithDelimiter(""); @@ -502,7 +503,7 @@ Aws::S3::Model::ListObjectsV2Outcome ListObjects(const std::string& bucket, cons // Get from a bucket a list of objects matching a name pattern. // To get a limited list of objects to filter per request, the request includes a well defined // prefix contained in the pattern -FilterOutcome FilterList(const std::string& bucket, const std::string& pattern, size_t pattern_1st_sp_char_pos) +FilterOutcome FilterList(const Aws::String& bucket, const Aws::String& pattern, size_t pattern_1st_sp_char_pos) { ObjectsVec res; @@ -573,9 +574,9 @@ int driver_isReadOnly() int driver_connect() { - auto file_exists = [](const std::string& name) + auto file_exists = [](const Aws::String& name) { - std::ifstream ifile(name); + Aws::IFStream ifile(name); return (ifile.is_open()); }; @@ -592,15 +593,15 @@ int driver_connect() // Configuration: we honor both standard AWS config files and environment // variables If both configuration files and environment variables are set // precedence is given to environment variables - std::string s3endpoint = ""; - std::string s3region = "us-east-1"; + Aws::String s3endpoint = ""; + Aws::String s3region = "us-east-1"; // Load AWS configuration from file Aws::Auth::AWSCredentials configCredentials; - std::string userHome = GetEnvironmentVariableOrDefault("HOME", ""); + Aws::String userHome = GetEnvironmentVariableOrDefault("HOME", ""); if (!userHome.empty()) { - std::ostringstream defaultConfig_os; + Aws::OStringStream defaultConfig_os; defaultConfig_os << userHome << "/.aws/config"; const std::string defaultConfig = defaultConfig_os.str(); @@ -609,17 +610,17 @@ int driver_connect() // .append("config") // .string(); - const std::string configFile = GetEnvironmentVariableOrDefault("AWS_CONFIG_FILE", defaultConfig); + const Aws::String configFile = GetEnvironmentVariableOrDefault("AWS_CONFIG_FILE", defaultConfig); spdlog::debug("Conf file = {}", configFile); if (file_exists(configFile)) { // if (std::filesystem::exists(std::filesystem::path(configFile))) { - const std::string profile = GetEnvironmentVariableOrDefault("AWS_PROFILE", "default"); + const Aws::String profile = GetEnvironmentVariableOrDefault("AWS_PROFILE", "default"); spdlog::debug("Profile = {}", profile); - const std::string profileSection = (profile != "default") ? "profile " + profile : profile; + const Aws::String profileSection = (profile != "default") ? "profile " + profile : profile; Aws::Auth::ProfileConfigFileAWSCredentialsProvider provider(profile.c_str()); configCredentials = provider.GetAWSCredentials(); @@ -627,14 +628,14 @@ int driver_connect() mINI::INIFile file(configFile); mINI::INIStructure ini; file.read(ini); - std::string confEndpoint = ini.get(profileSection).get("endpoint_url"); + Aws::String confEndpoint = ini.get(profileSection).get("endpoint_url"); if (!confEndpoint.empty()) { s3endpoint = std::move(confEndpoint); } spdlog::debug("Endpoint = {}", s3endpoint); - std::string confRegion = ini.get(profileSection).get("region"); + Aws::String confRegion = ini.get(profileSection).get("region"); if (!confRegion.empty()) { s3region = std::move(confRegion); @@ -654,9 +655,9 @@ int driver_connect() s3endpoint = GetEnvironmentVariableOrDefault("S3_ENDPOINT", s3endpoint); s3endpoint = GetEnvironmentVariableOrDefault("AWS_ENDPOINT_URL", s3endpoint); s3region = GetEnvironmentVariableOrDefault("AWS_DEFAULT_REGION", s3region); - std::string s3accessKey = GetEnvironmentVariableOrDefault("S3_ACCESS_KEY", ""); + Aws::String s3accessKey = GetEnvironmentVariableOrDefault("S3_ACCESS_KEY", ""); s3accessKey = GetEnvironmentVariableOrDefault("AWS_ACCESS_KEY_ID", s3accessKey); - std::string s3secretKey = GetEnvironmentVariableOrDefault("S3_SECRET_KEY", ""); + Aws::String s3secretKey = GetEnvironmentVariableOrDefault("S3_SECRET_KEY", ""); s3secretKey = GetEnvironmentVariableOrDefault("AWS_SECRET_ACCESS_KEY", s3secretKey); if ((s3accessKey != "" && s3secretKey == "") || (s3accessKey == "" && s3secretKey != "")) { @@ -684,8 +685,10 @@ int driver_connect() { configCredentials = Aws::Auth::AWSCredentials(s3accessKey, s3secretKey); } - client.reset(new Aws::S3::S3Client( - configCredentials, Aws::MakeShared(S3EndpointProvider), clientConfig)); + + client = Aws::MakeUnique(S3EndpointProvider, configCredentials, + Aws::MakeShared(S3EndpointProvider), + clientConfig); bIsConnected = true; return kSuccess; @@ -774,21 +777,21 @@ int driver_dirExists(const char* sFilePathName) return kTrue; } -SizeOutcome GetOneFileSize(const std::string& bucket, const std::string& object) +SizeOutcome GetOneFileSize(const Aws::String& bucket, const Aws::String& object) { const auto head_object_outcome = HeadObject(bucket, object); RETURN_OUTCOME_ON_ERROR(head_object_outcome); return head_object_outcome.GetResult().GetContentLength(); } -SimpleOutcome ReadHeader(const std::string& bucket, const S3Object& obj) +SimpleOutcome ReadHeader(const Aws::String& bucket, const S3Object& obj) { auto request = MakeGetObjectRequest(bucket, obj.GetKey()); auto outcome = client->GetObject(request); RETURN_OUTCOME_ON_ERROR(outcome); - // Aws::IOStream& read_stream = outcome.GetResultWithOwnership().GetBody(); - Aws::IOStream& read_stream = outcome.GetResult().GetBody(); - std::string line; + auto result = outcome.GetResultWithOwnership(); + Aws::IOStream& read_stream = result.GetBody(); + Aws::String line; std::getline(read_stream, line); if (read_stream.bad()) { @@ -808,9 +811,9 @@ SimpleOutcome ReadHeader(const std::string& bucket, const S3Object& #define KH_S3_READ_HEADER(var, bucket, obj) \ const auto var##_outcome = ReadHeader((bucket), (obj)); \ PASS_OUTCOME_ON_ERROR(var##_outcome); \ - const std::string& var = var##_outcome.GetResult(); + const Aws::String& var = var##_outcome.GetResult(); -SizeOutcome getFileSize(const std::string& bucket_name, const std::string& object_name) +SizeOutcome getFileSize(const Aws::String& bucket_name, const Aws::String& object_name) { // tweak the request for the object. if the object parameter is in fact a pattern, // the pattern could point to a list of objects that constitute a whole file @@ -885,7 +888,7 @@ long long int driver_getFileSize(const char* filename) return maybe_file_size.GetResult(); } -SimpleOutcome MakeReaderPtr(std::string bucketname, std::string objectname) +SimpleOutcome MakeReaderPtr(Aws::String bucketname, Aws::String objectname) { size_t pattern_1st_sp_char_pos = 0; if (!IsMultifile(objectname, pattern_1st_sp_char_pos)) @@ -895,8 +898,11 @@ SimpleOutcome MakeReaderPtr(std::string bucketname, std::string objec PASS_OUTCOME_ON_ERROR(size_outcome); const long long size = size_outcome.GetResult(); - return ReaderPtr( - new MultiPartFile{std::move(bucketname), std::move(objectname), 0, 0, {objectname}, {size}}); + Aws::Vector objectnames(1, objectname); + Aws::Vector sizes(1, size); + + return Aws::MakeUnique(S3EndpointProvider, std::move(bucketname), std::move(objectname), 0, 0, + std::move(objectnames), std::move(sizes)); } // this is a multifile. the reader object needs the list of filenames matching the globbing pattern and their @@ -913,8 +919,8 @@ SimpleOutcome MakeReaderPtr(std::string bucketname, std::string objec KH_S3_EMPTY_LIST(file_list); const size_t file_count = file_list.size(); - std::vector filenames(file_count); - std::vector cumulative_size(file_count); + Aws::Vector filenames(file_count); + Aws::Vector cumulative_size(file_count); // get metadata from the first file const auto& first_file = file_list.front(); @@ -957,22 +963,22 @@ SimpleOutcome MakeReaderPtr(std::string bucketname, std::string objec } // construct the result - return ReaderPtr(new MultiPartFile{std::move(bucketname), std::move(objectname), 0, common_header_length, - std::move(filenames), std::move(cumulative_size)}); + return Aws::MakeUnique(S3EndpointProvider, std::move(bucketname), std::move(objectname), 0, + common_header_length, std::move(filenames), std::move(cumulative_size)); } -SimpleOutcome MakeWriterPtr(std::string bucket, std::string object) +SimpleOutcome MakeWriterPtr(Aws::String bucket, Aws::String object) { Aws::S3::Model::CreateMultipartUploadRequest request; request.SetBucket(std::move(bucket)); request.SetKey(std::move(object)); auto outcome = client->CreateMultipartUpload(request); RETURN_OUTCOME_ON_ERROR(outcome); - return WriterPtr(new WriteFile{outcome.GetResultWithOwnership()}); + return Aws::MakeUnique(S3EndpointProvider, outcome.GetResultWithOwnership()); } // This template is only here to get specialized -template T* PushBackHandle(std::unique_ptr&&) +template T* PushBackHandle(Aws::UniquePtr&&) { return nullptr; } @@ -991,20 +997,20 @@ template <> Writer* PushBackHandle(WriterPtr&& stream_ptr) template SimpleOutcome -RegisterStream(std::function>(std::string, std::string)> MakeStreamPtr, - std::string&& bucket, std::string&& object) +RegisterStream(std::function>(Aws::String, Aws::String)> MakeStreamPtr, + Aws::String&& bucket, Aws::String&& object) { auto outcome = MakeStreamPtr(std::move(bucket), std::move(object)); PASS_OUTCOME_ON_ERROR(outcome); return PushBackHandle(outcome.GetResultWithOwnership()); } -SimpleOutcome RegisterReader(std::string&& bucket, std::string&& object) +SimpleOutcome RegisterReader(Aws::String&& bucket, Aws::String&& object) { return RegisterStream(MakeReaderPtr, std::move(bucket), std::move(object)); } -SimpleOutcome RegisterWriter(std::string&& bucket, std::string&& object) +SimpleOutcome RegisterWriter(Aws::String&& bucket, Aws::String&& object) { return RegisterStream(MakeWriterPtr, std::move(bucket), std::move(object)); } @@ -1018,7 +1024,7 @@ UploadOutcome UploadPart(Writer& writer) { auto& buffer = writer.buffer_; Aws::Utils::Stream::PreallocatedStreamBuf pre_buf(buffer.data(), buffer.size()); - const auto body = std::make_shared(&pre_buf); + const auto body = Aws::MakeShared(S3EndpointProvider, &pre_buf); const auto& w = writer.writer_; Aws::S3::Model::UploadPartRequest request; diff --git a/src/s3plugin_internal.h b/src/s3plugin_internal.h index b77bf1f..bb72aff 100644 --- a/src/s3plugin_internal.h +++ b/src/s3plugin_internal.h @@ -24,18 +24,18 @@ using tOffset = long long; struct MultiPartFile { - std::string bucketname_; - std::string filename_; + Aws::String bucketname_; + Aws::String filename_; tOffset offset_{0}; // Added for multifile support tOffset common_header_length_{0}; - std::vector filenames_; - std::vector cumulative_sizes_; + Aws::Vector filenames_; + Aws::Vector cumulative_sizes_; tOffset total_size_{0}; MultiPartFile() = default; - explicit MultiPartFile(std::string bucket, std::string filename, tOffset offset, tOffset common_header_length, - std::vector filenames, std::vector cumulative_sizes) + explicit MultiPartFile(Aws::String bucket, Aws::String filename, tOffset offset, tOffset common_header_length, + Aws::Vector filenames, Aws::Vector cumulative_sizes) : bucketname_{std::move(bucket)}, filename_{std::move(filename)}, offset_{offset}, common_header_length_{common_header_length}, filenames_{std::move(filenames)}, cumulative_sizes_{std::move(cumulative_sizes)}, total_size_{cumulative_sizes_.back()} @@ -43,7 +43,7 @@ struct MultiPartFile } }; -using Parts = std::vector; +using Parts = Aws::Vector; struct WriteFile { @@ -51,11 +51,11 @@ struct WriteFile static constexpr size_t buff_max_ = buff_min_ * 1024; Aws::S3::Model::CreateMultipartUploadResult writer_; - std::vector buffer_; + Aws::Vector buffer_; Parts parts_; - std::string bucketname_; - std::string filename_; - std::string append_target_; + Aws::String bucketname_; + Aws::String filename_; + Aws::String append_target_; int part_tracker_{1}; WriteFile() = default; @@ -76,10 +76,10 @@ struct WriteFile using Reader = MultiPartFile; using Writer = WriteFile; -using ReaderPtr = std::unique_ptr; -using WriterPtr = std::unique_ptr; +using ReaderPtr = Aws::UniquePtr; +using WriterPtr = Aws::UniquePtr; -template using HandleContainer = std::vector; +template using HandleContainer = Aws::Vector; template using HandleIt = typename HandleContainer::iterator; diff --git a/test/basic_test.cpp b/test/basic_test.cpp index fae85ee..be15857 100644 --- a/test/basic_test.cpp +++ b/test/basic_test.cpp @@ -288,8 +288,8 @@ ListObjectsV2Outcome MakeListObjectOutcome(Aws::Vector &&v, } // Note: the strings inside keys will be moved from -Aws::Vector MakeObjectVector(std::vector &&keys, - std::vector &&sizes) { +Aws::Vector MakeObjectVector(Aws::Vector &&keys, + Aws::Vector &&sizes) { const size_t key_count = keys.size(); Aws::Vector res(key_count); for (size_t i = 0; i < key_count; i++) { @@ -304,9 +304,9 @@ Aws::Vector MakeObjectVector(std::vector &&keys, return res; } -GetObjectOutcome MakeGetObjectOutcome(const std::string &body) { +GetObjectOutcome MakeGetObjectOutcome(const Aws::String &body) { - std::unique_ptr stream{new Aws::StringStream()}; + auto stream = Aws::MakeUnique("S3_TEST"); *stream << body; stream->flush(); @@ -359,7 +359,7 @@ class S3DriverTestFixture : public ::testing::Test { // Setup AWS API Aws::InitAPI(options_); - mock_client_alias_ = new MockS3Client{}; + mock_client_alias_ = Aws::New("S3_TEST"); mock_client_ = dynamic_cast(mock_client_alias_); test_setClient(mock_client_alias_); } @@ -426,7 +426,7 @@ class S3DriverTestFixture : public ::testing::Test { // HandleContainer* GetHandles() { return // reinterpret_cast(test_getActiveHandles()); } - void SetListCall(Aws::Vector &&content, std::string &&token) { + void SetListCall(Aws::Vector &&content, Aws::String &&token) { EXPECT_CALL(*mock_client_, ListObjectsV2) .WillOnce(Return( MakeListObjectOutcome(std::move(content), std::move(token)))); @@ -436,8 +436,8 @@ class S3DriverTestFixture : public ::testing::Test { const char *pattern_ = "s3://bucket/pattern*"; const char *pattern_stub_ = "s3://bucket/pattern"; - std::string MakeKeyFromPatternStub(char c) { - std::string key(pattern_stub_); + Aws::String MakeKeyFromPatternStub(char c) { + Aws::String key(pattern_stub_); key.push_back(c); return key; } @@ -503,7 +503,7 @@ TEST_F(S3DriverTestFixture, FileExists_Globbing_ListObjectError) { TEST_F(S3DriverTestFixture, FileExists_Globbing_EmptyList) { Aws::Vector content; - std::string token; + Aws::String token; SIMPLE_LIST_CALL; @@ -512,7 +512,7 @@ TEST_F(S3DriverTestFixture, FileExists_Globbing_EmptyList) { TEST_F(S3DriverTestFixture, FileExists_Globbing_SomeContent_NoMatch) { auto content = MakeObjectVector({"nomatch0", "nomatch1"}, {}); - std::string token; + Aws::String token; SIMPLE_LIST_CALL; @@ -523,7 +523,7 @@ TEST_F(S3DriverTestFixture, FileExists_Globbing_SomeContent_Match) { auto content = MakeObjectVector({"s3://mock_bucket/i_match/pattern", "s3://mock_bucket/i_match_too/pattern"}, {}); - std::string token; + Aws::String token; SIMPLE_LIST_CALL; @@ -534,8 +534,8 @@ TEST_F(S3DriverTestFixture, FileExists_Globbing_ContinuationToken) { auto content0 = MakeObjectVector({"a"}, {1}); auto content1 = MakeObjectVector({"b"}, {1}); - std::string not_empty = "not_empty_token"; - std::string empty; + Aws::String not_empty = "not_empty_token"; + Aws::String empty; EXPECT_LISTOBJECT LIST_CALL(content0, not_empty) @@ -571,7 +571,7 @@ TEST_F(S3DriverTestFixture, GetFileSize_Pattern_Error) { TEST_F(S3DriverTestFixture, GetFileSize_Pattern_NoMatch) { auto content = MakeObjectVector({"nomatch0", "nomatch1"}, {}); - std::string token; + Aws::String token; SIMPLE_LIST_CALL; @@ -580,7 +580,7 @@ TEST_F(S3DriverTestFixture, GetFileSize_Pattern_NoMatch) { TEST_F(S3DriverTestFixture, GetFileSize_Pattern_OneMatch) { const long long expected_size{1}; - std::string key(pattern_stub_); + Aws::String key(pattern_stub_); key.push_back('0'); auto content = MakeObjectVector({key}, {expected_size}); @@ -592,15 +592,15 @@ TEST_F(S3DriverTestFixture, GetFileSize_Pattern_OneMatch) { } TEST_F(S3DriverTestFixture, GetFileSize_Pattern_MultiMatch_SameHeader_OK) { - const std::string key_0 = MakeKeyFromPatternStub('0'); - const std::string key_1 = MakeKeyFromPatternStub('1'); + const Aws::String key_0 = MakeKeyFromPatternStub('0'); + const Aws::String key_1 = MakeKeyFromPatternStub('1'); - const std::string header = "header\n"; - const std::string content0 = "content"; - const std::string content1 = "more content"; + const Aws::String header = "header\n"; + const Aws::String content0 = "content"; + const Aws::String content1 = "more content"; - const std::string body_0 = header + content0; - const std::string body_1 = header + content1; + const Aws::String body_0 = header + content0; + const Aws::String body_1 = header + content1; const long long expected_size = static_cast(body_0.size() + content1.size()); @@ -608,7 +608,7 @@ TEST_F(S3DriverTestFixture, GetFileSize_Pattern_MultiMatch_SameHeader_OK) { auto content = MakeObjectVector({key_0, key_1}, {static_cast(body_0.size()), static_cast(body_1.size())}); - std::string token; + Aws::String token; // list SIMPLE_LIST_CALL; @@ -623,15 +623,15 @@ TEST_F(S3DriverTestFixture, GetFileSize_Pattern_MultiMatch_SameHeader_OK) { TEST_F(S3DriverTestFixture, GetFileSize_Pattern_MultiMatch_DifferentHeaders_OK) { - const std::string key_0 = MakeKeyFromPatternStub('0'); - const std::string key_1 = MakeKeyFromPatternStub('1'); + const Aws::String key_0 = MakeKeyFromPatternStub('0'); + const Aws::String key_1 = MakeKeyFromPatternStub('1'); - const std::string header = "header\n"; - const std::string content0 = "content"; - const std::string content1 = "more content"; + const Aws::String header = "header\n"; + const Aws::String content0 = "content"; + const Aws::String content1 = "more content"; - const std::string body_0 = header + content0; - const std::string body_1 = content1; + const Aws::String body_0 = header + content0; + const Aws::String body_1 = content1; const long long expected_size = static_cast(body_0.size() + content1.size()); @@ -639,7 +639,7 @@ TEST_F(S3DriverTestFixture, auto content = MakeObjectVector({key_0, key_1}, {static_cast(body_0.size()), static_cast(body_1.size())}); - std::string token; + Aws::String token; // list SIMPLE_LIST_CALL;