diff --git a/sdk/storage/azure-storage-blobs/test/perf/CMakeLists.txt b/sdk/storage/azure-storage-blobs/test/perf/CMakeLists.txt index 99210f33c..3a61e2574 100644 --- a/sdk/storage/azure-storage-blobs/test/perf/CMakeLists.txt +++ b/sdk/storage/azure-storage-blobs/test/perf/CMakeLists.txt @@ -11,6 +11,8 @@ set( AZURE_STORAGE_BLOBS_PERF_TEST_HEADER inc/azure/storage/blobs/test/blob_base_test.hpp inc/azure/storage/blobs/test/download_blob_test.hpp + inc/azure/storage/blobs/test/list_blob_test.hpp + inc/azure/storage/blobs/test/upload_blob_test.hpp ) set( diff --git a/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/list_blob_test.hpp b/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/list_blob_test.hpp new file mode 100644 index 000000000..ecd81c821 --- /dev/null +++ b/sdk/storage/azure-storage-blobs/test/perf/inc/azure/storage/blobs/test/list_blob_test.hpp @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * @brief Test the performance of listing blobs. + * + */ + +#pragma once + +#include +#include +#include + +#include "azure/storage/blobs/test/blob_base_test.hpp" + +#include +#include +#include + +namespace Azure { namespace Storage { namespace Blobs { namespace Test { + + /** + * @brief A test to measure listing a blob. + * + */ + class ListBlob : public Azure::Storage::Blobs::Test::BlobsTest { + public: + /** + * @brief Construct a new ListBlob test. + * + * @param options The test options. + */ + ListBlob(Azure::Perf::TestOptions options) : BlobsTest(options) {} + + /** + * @brief The size to upload on setup is defined by a mandatory parameter. + * + */ + void Setup() override + { + // Call base to create blob client + BlobsTest::Setup(); + long count = m_options.GetMandatoryOption("Count"); + + auto rawData = std::make_unique>(1); + auto content = Azure::Core::IO::MemoryBodyStream(*rawData); + + // Upload the number of blobs to be listed later in the test + for (auto blobCount = 0; blobCount < count; blobCount++) + { + auto blobName = "Azure.Storage.Blobs.Perf.Scenarios.DownloadBlob-" + + Azure::Core::Uuid::CreateUuid().ToString(); + m_containerClient->GetBlockBlobClient(blobName).Upload(content); + } + } + + /** + * @brief Define the test + * + */ + void Run(Azure::Core::Context const& context) override + { + // Loop each page + for (auto page = m_containerClient->ListBlobs({}, context); page.HasPage(); + page.MoveToNextPage(context)) + { + // loop each blob + for (auto blob : page.Blobs) + { + (void)blob; + } + } + } + + /** + * @brief Define the test options for the test. + * + * @return The list of test options. + */ + std::vector GetTestOptions() override + { + // TODO: Merge with base options + return {{"Count", {"--count"}, "Number of blobs to list", 1, true}}; + } + + /** + * @brief Get the static Test Metadata for the test. + * + * @return Azure::Perf::TestMetadata describing the test. + */ + static Azure::Perf::TestMetadata GetTestMetadata() + { + return {"ListBlob", "List blobs.", [](Azure::Perf::TestOptions options) { + return std::make_unique(options); + }}; + } + }; + +}}}} // namespace Azure::Storage::Blobs::Test diff --git a/sdk/storage/azure-storage-blobs/test/perf/src/azure_storage_blobs_perf_test.cpp b/sdk/storage/azure-storage-blobs/test/perf/src/azure_storage_blobs_perf_test.cpp index ee78db23e..cdd8219d0 100644 --- a/sdk/storage/azure-storage-blobs/test/perf/src/azure_storage_blobs_perf_test.cpp +++ b/sdk/storage/azure-storage-blobs/test/perf/src/azure_storage_blobs_perf_test.cpp @@ -4,6 +4,7 @@ #include #include "azure/storage/blobs/test/download_blob_test.hpp" +#include "azure/storage/blobs/test/list_blob_test.hpp" #include "azure/storage/blobs/test/upload_blob_test.hpp" int main(int argc, char** argv) @@ -12,7 +13,8 @@ int main(int argc, char** argv) // Create the test list std::vector tests{ Azure::Storage::Blobs::Test::DownloadBlob::GetTestMetadata(), - Azure::Storage::Blobs::Test::UploadBlob::GetTestMetadata()}; + Azure::Storage::Blobs::Test::UploadBlob::GetTestMetadata(), + Azure::Storage::Blobs::Test::ListBlob::GetTestMetadata()}; Azure::Perf::Program::Run(Azure::Core::Context::ApplicationContext, tests, argc, argv);