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 <mharder@microsoft.com>
This commit is contained in:
parent
6012511293
commit
fcf75f80d1
@ -31,6 +31,11 @@ target_include_directories(
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <azure/core/uuid.hpp>
|
||||
#include <azure/perf.hpp>
|
||||
|
||||
#include <azure/storage/blobs.hpp>
|
||||
@ -38,9 +39,15 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test {
|
||||
*/
|
||||
void Setup() override
|
||||
{
|
||||
m_connectionString = m_options.GetMandatoryOption<std::string>("connectionString");
|
||||
m_containerName = m_options.GetMandatoryOption<std::string>("ContainerName");
|
||||
m_blobName = m_options.GetMandatoryOption<std::string>("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>(
|
||||
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<Azure::Perf::TestOption> 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<Azure::Perf::TestOption> GetTestOptions() override { return {}; }
|
||||
};
|
||||
|
||||
}}}} // namespace Azure::Storage::Blobs::Test
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <azure/core/io/body_stream.hpp>
|
||||
#include <azure/perf.hpp>
|
||||
|
||||
#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<std::vector<uint8_t>> 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<long>("Size");
|
||||
|
||||
m_downloadBuffer = std::make_unique<std::vector<uint8_t>>(size);
|
||||
|
||||
auto rawData = std::make_unique<std::vector<uint8_t>>(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<Azure::Perf::TestOption> GetTestOptions() override
|
||||
{
|
||||
return Azure::Storage::Blobs::Test::BlobsTest::GetTestOptions();
|
||||
// TODO: Merge with base options
|
||||
return {{"Size", {"--size"}, "Size of payload (in bytes)", 1, true}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user