From fcf75f80d1765a1111356feefc1e38593c53cd9f Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Fri, 21 May 2021 17:00:38 -0700 Subject: [PATCH] update storage download perf test - Take connection string from env (#2247) * update storage download perf test * format * allow getEnv() for msvc * Add size option * format * Download to buffer * Apply suggestions from code review * use member for the buffer Co-authored-by: Mike Harder --- .../test/perf/CMakeLists.txt | 5 ++++ .../storage/blobs/test/blob_base_test.hpp | 28 +++++++++--------- .../storage/blobs/test/download_blob.hpp | 29 +++++++++++++++++-- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/sdk/storage/azure-storage-blobs/test/perf/CMakeLists.txt b/sdk/storage/azure-storage-blobs/test/perf/CMakeLists.txt index 9687e4057..33384dbc6 100644 --- a/sdk/storage/azure-storage-blobs/test/perf/CMakeLists.txt +++ b/sdk/storage/azure-storage-blobs/test/perf/CMakeLists.txt @@ -31,6 +31,11 @@ target_include_directories( $ ) +if (MSVC) + # allow msvc to use getenv() + target_compile_options(azure-storage-blobs-perf PUBLIC /wd4996) +endif() + # link the `azure-perf` lib together with any other library which will be used for the tests. target_link_libraries(azure-storage-blobs-perf PRIVATE azure-storage-blobs azure-perf) # Make sure the project will appear in the test folder for Visual Studio CMake view diff --git a/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/blob_base_test.hpp b/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/blob_base_test.hpp index 86960c60c..9efd913d8 100644 --- a/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/blob_base_test.hpp +++ b/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/blob_base_test.hpp @@ -9,6 +9,7 @@ #pragma once +#include #include #include @@ -38,9 +39,15 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test { */ void Setup() override { - m_connectionString = m_options.GetMandatoryOption("connectionString"); - m_containerName = m_options.GetMandatoryOption("ContainerName"); - m_blobName = m_options.GetMandatoryOption("BlobName"); + // Get connection string from env + const static std::string envConnectionString = std::getenv("STORAGE_CONNECTION_STRING"); + m_connectionString = envConnectionString; + + // Generate random container and blob names. + m_containerName = "container" + Azure::Core::Uuid::CreateUuid().ToString(); + m_blobName = "blob" + Azure::Core::Uuid::CreateUuid().ToString(); + + // Create client, container and blobClient m_containerClient = std::make_unique( Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString( m_connectionString, m_containerName)); @@ -49,6 +56,8 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test { m_containerClient->GetBlockBlobClient(m_blobName)); } + void Cleanup() override { m_containerClient->DeleteIfExists(); }; + /** * @brief Construct a new BlobsTest test. * @@ -61,18 +70,7 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test { * * @return The list of test options. */ - std::vector GetTestOptions() override - { - return { - {"connectionString", - {"--connectionString"}, - "The Storage account connection string.", - 1, - true, - true}, - {"ContainerName", {"--containerName"}, "The name of a blob container", 1, true}, - {"BlobName", {"--blobName"}, "The name of a blob.", 1, true}}; - } + std::vector GetTestOptions() override { return {}; } }; }}}} // namespace Azure::Storage::Blobs::Test diff --git a/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/download_blob.hpp b/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/download_blob.hpp index 96ed55480..524ae82a3 100644 --- a/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/download_blob.hpp +++ b/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/download_blob.hpp @@ -9,6 +9,7 @@ #pragma once +#include #include #include "azure/storage/blobs/test/blob_base_test.hpp" @@ -24,6 +25,8 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test { * */ class DownloadBlob : public Azure::Storage::Blobs::Test::BlobsTest { + private: + std::unique_ptr> m_downloadBuffer; public: /** @@ -33,11 +36,32 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test { */ DownloadBlob(Azure::Perf::TestOptions options) : BlobsTest(options) {} + /** + * @brief Upload 5Mb to be downloaded in the test + * + */ + void Setup() override + { + // Call base to create blob client + BlobsTest::Setup(); + + long size = m_options.GetMandatoryOption("Size"); + + m_downloadBuffer = std::make_unique>(size); + + auto rawData = std::make_unique>(size); + auto content = Azure::Core::IO::MemoryBodyStream(*rawData); + m_blobClient->Upload(content); + } + /** * @brief Define the test * */ - void Run(Azure::Core::Context const&) override { auto blob = m_blobClient->Download(); } + void Run(Azure::Core::Context const&) override + { + m_blobClient->DownloadTo(m_downloadBuffer->data(), m_downloadBuffer->size()); + } /** * @brief Define the test options for the test. @@ -46,7 +70,8 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test { */ std::vector GetTestOptions() override { - return Azure::Storage::Blobs::Test::BlobsTest::GetTestOptions(); + // TODO: Merge with base options + return {{"Size", {"--size"}, "Size of payload (in bytes)", 1, true}}; } /**