Skip to content

Storage test cases improvements #4819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 27, 2023
Merged
2 changes: 1 addition & 1 deletion sdk/storage/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/storage",
"Tag": "cpp/storage_17c4a656fc"
"Tag": "cpp/storage_c0d4e90195"
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,48 @@ namespace Azure { namespace Storage { namespace Test {

TEST_F(BlockBlobClientTest, SoftDelete)
{
const std::string blobName = m_blobName;
auto blobClient = *m_blockBlobClient;

std::vector<uint8_t> emptyContent;
auto blobContent = Azure::Core::IO::MemoryBodyStream(emptyContent.data(), emptyContent.size());
blobClient.Upload(blobContent);
auto clientOptions = InitStorageClientOptions<Blobs::BlobClientOptions>();
auto blobContainerClient
= Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
AdlsGen2ConnectionString(), LowercaseRandomString(), clientOptions);
blobContainerClient.CreateIfNotExists();
auto blobName = RandomString();
auto blobClient = blobContainerClient.GetBlockBlobClient(blobName);

blobClient.UploadFrom(nullptr, 0);

auto getBlobItem = [&]() {
Blobs::ListBlobsOptions options;
options.Prefix = blobName;
options.Include = Blobs::Models::ListBlobsIncludeFlags::Deleted;
for (auto page = blobContainerClient.ListBlobs(options); page.HasPage();
page.MoveToNextPage())
{
for (auto& blob : page.Blobs)
{
if (blob.Name == blobName)
{
return std::move(blob);
}
}
}
std::abort();
};

auto blobItem = GetBlobItem(blobName);
auto blobItem = getBlobItem();
EXPECT_FALSE(blobItem.IsDeleted);
EXPECT_FALSE(blobItem.Details.DeletedOn.HasValue());
EXPECT_FALSE(blobItem.Details.RemainingRetentionDays.HasValue());

blobClient.Delete();

/*
// Soft delete doesn't work in storage account with versioning enabled.
blobItem = GetBlobItem(blobName, Blobs::Models::ListBlobsIncludeFlags::Deleted);
blobItem = getBlobItem();
EXPECT_TRUE(blobItem.IsDeleted);
ASSERT_TRUE(blobItem.Details.DeletedOn.HasValue());
EXPECT_TRUE(IsValidTime(blobItem.Details.DeletedOn.Value()));
EXPECT_TRUE(blobItem.Details.RemainingRetentionDays.HasValue());
*/

blobContainerClient.Delete();
}

TEST_F(BlockBlobClientTest, SmallUploadDownload)
Expand Down Expand Up @@ -798,7 +818,7 @@ namespace Azure { namespace Storage { namespace Test {
blobItem.Details.RehydratePriority.Value(), Blobs::Models::RehydratePriority::Standard);
}

TEST_F(BlockBlobClientTest, DISABLED_SetTierCold)
TEST_F(BlockBlobClientTest, SetTierCold)
{
m_blockBlobClient->SetAccessTier(Blobs::Models::AccessTier::Cold);
auto properties = m_blockBlobClient->GetProperties().Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Azure { namespace Storage { namespace Test {

// If connection is reused, the requests with the same connection should hit the same sever. So
// this test verifies whether a series of requests hit the same server.
TEST_F(BlockBlobClientTest, IsConnectionReused_LIVEONLY_)
TEST_F(BlockBlobClientTest, IsConnectionReused)
{
const std::string containerName = LowercaseRandomString();
const std::string blobName = LowercaseRandomString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,37 @@ namespace Azure { namespace Storage { namespace Test {
options2.TransactionalContentHash.Value().Value = contentMd5;
EXPECT_NO_THROW(pageBlobClient2.UploadPagesFromUri(
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2));
options2.TransactionalContentHash.Value().Algorithm = HashAlgorithm::Crc64;
options2.TransactionalContentHash.Value().Value
= Azure::Core::Convert::Base64Decode(DummyCrc64);
// EXPECT_THROW(
// pageBlobClient2.UploadPagesFromUri(
// 0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2),
// StorageException);
options2.TransactionalContentHash.Value().Value = contentCrc64;
}

TEST_F(PageBlobClientTest, DISABLED_UploadPagesFromUriCrc64AccessCondition)
{
auto pageBlobClient = *m_pageBlobClient;

std::vector<uint8_t> blobContent = RandomBuffer(static_cast<size_t>(4_KB));
const std::vector<uint8_t> contentCrc64
= Azure::Storage::Crc64Hash().Final(blobContent.data(), blobContent.size());

pageBlobClient.Create(blobContent.size());
auto contentStream = Azure::Core::IO::MemoryBodyStream(blobContent.data(), blobContent.size());
pageBlobClient.UploadPages(0, contentStream);

auto pageBlobClient2 = GetPageBlobClientTestForTest(RandomString());
pageBlobClient2.Create(blobContent.size());

Blobs::UploadPagesFromUriOptions options;
Azure::Core::Http::HttpRange sourceRange;
sourceRange.Offset = 0;
sourceRange.Length = blobContent.size();
options.TransactionalContentHash = ContentHash();
options.TransactionalContentHash.Value().Algorithm = HashAlgorithm::Crc64;
options.TransactionalContentHash.Value().Value = Azure::Core::Convert::Base64Decode(DummyCrc64);
EXPECT_THROW(
pageBlobClient2.UploadPagesFromUri(
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options),
StorageException);
options.TransactionalContentHash.Value().Value = contentCrc64;
EXPECT_NO_THROW(pageBlobClient2.UploadPagesFromUri(
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2));
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options));
}

TEST_F(PageBlobClientTest, CreateIfNotExists)
Expand Down