From c8da53d54471664bb0310568c41e029aed0d8a9c Mon Sep 17 00:00:00 2001 From: JinmingHu Date: Wed, 3 Feb 2021 14:49:24 +0800 Subject: [PATCH] Change ChangeLease return type (#1573) * ChangeLease return type * file client * Add comment * return Result rather than Client * fix * fix --- .../azure/storage/blobs/blob_lease_client.hpp | 15 ++++++++------- .../src/blob_lease_client.cpp | 16 +++++----------- .../test/blob_container_client_test.cpp | 1 + .../test/page_blob_client_test.cpp | 1 + .../files/datalake/datalake_lease_client.hpp | 15 ++++++++------- .../storage/files/shares/share_lease_client.hpp | 15 ++++++++------- .../src/share_lease_client.cpp | 15 +++++---------- .../test/share_file_client_test.cpp | 2 ++ 8 files changed, 38 insertions(+), 42 deletions(-) diff --git a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_lease_client.hpp b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_lease_client.hpp index dd33ccd4b..abe5276b4 100644 --- a/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_lease_client.hpp +++ b/sdk/storage/azure-storage-blobs/inc/azure/storage/blobs/blob_lease_client.hpp @@ -70,7 +70,7 @@ namespace Azure { namespace Storage { namespace Blobs { */ Azure::Core::Response Acquire( std::chrono::seconds duration, - const AcquireBlobLeaseOptions& options = AcquireBlobLeaseOptions()); + const AcquireBlobLeaseOptions& options = AcquireBlobLeaseOptions()) const; /** * @brief Renews the blob or blob container's previously-acquired lease. @@ -80,17 +80,17 @@ namespace Azure { namespace Storage { namespace Blobs { * @return A RenewBlobLeaseResult describing the lease. */ Azure::Core::Response Renew( - const RenewBlobLeaseOptions& options = RenewBlobLeaseOptions()); + const RenewBlobLeaseOptions& options = RenewBlobLeaseOptions()) const; /** * @brief Releases the blob or blob container's previously-acquired lease. * * @param leaseId ID of the previously-acquired lease. * @param options Optional parameters to execute this function. - * @return A ReleaseBlobLeaseResult describing the updated container. + * @return A ReleaseBlobLeaseResult describing the updated container or blob. */ Azure::Core::Response Release( - const ReleaseBlobLeaseOptions& options = ReleaseBlobLeaseOptions()); + const ReleaseBlobLeaseOptions& options = ReleaseBlobLeaseOptions()) const; /** * @brief Changes the lease of an active lease. @@ -98,11 +98,12 @@ namespace Azure { namespace Storage { namespace Blobs { * @param leaseId ID of the previously-acquired lease. * @param proposedLeaseId Proposed lease ID, in a GUID string format. * @param options Optional parameters to execute this function. - * @return A ChangeBlobLeaseResult describing the lease. + * @return A ChangeBlobLeaseResult describing the changed lease. + * @remarks The current BlobLeaseClient becomes invalid if this operation succeeds. */ Azure::Core::Response Change( const std::string& proposedLeaseId, - const ChangeBlobLeaseOptions& options = ChangeBlobLeaseOptions()); + const ChangeBlobLeaseOptions& options = ChangeBlobLeaseOptions()) const; /** * @brief Breaks the previously-acquired lease. @@ -111,7 +112,7 @@ namespace Azure { namespace Storage { namespace Blobs { * @return A BreakBlobLeaseResult describing the broken lease. */ Azure::Core::Response Break( - const BreakBlobLeaseOptions& options = BreakBlobLeaseOptions()); + const BreakBlobLeaseOptions& options = BreakBlobLeaseOptions()) const; private: Azure::Core::Nullable m_blobClient; diff --git a/sdk/storage/azure-storage-blobs/src/blob_lease_client.cpp b/sdk/storage/azure-storage-blobs/src/blob_lease_client.cpp index f448cca8e..75a2c21b1 100644 --- a/sdk/storage/azure-storage-blobs/src/blob_lease_client.cpp +++ b/sdk/storage/azure-storage-blobs/src/blob_lease_client.cpp @@ -16,7 +16,7 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Response BlobLeaseClient::Acquire( std::chrono::seconds duration, - const AcquireBlobLeaseOptions& options) + const AcquireBlobLeaseOptions& options) const { if (m_blobClient.HasValue()) { @@ -40,7 +40,6 @@ namespace Azure { namespace Storage { namespace Blobs { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -70,7 +69,6 @@ namespace Azure { namespace Storage { namespace Blobs { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -82,7 +80,7 @@ namespace Azure { namespace Storage { namespace Blobs { } Azure::Core::Response BlobLeaseClient::Renew( - const RenewBlobLeaseOptions& options) + const RenewBlobLeaseOptions& options) const { if (m_blobClient.HasValue()) { @@ -105,7 +103,6 @@ namespace Azure { namespace Storage { namespace Blobs { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -135,7 +132,6 @@ namespace Azure { namespace Storage { namespace Blobs { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -147,7 +143,7 @@ namespace Azure { namespace Storage { namespace Blobs { } Azure::Core::Response BlobLeaseClient::Release( - const ReleaseBlobLeaseOptions& options) + const ReleaseBlobLeaseOptions& options) const { if (m_blobClient.HasValue()) { @@ -209,7 +205,7 @@ namespace Azure { namespace Storage { namespace Blobs { Azure::Core::Response BlobLeaseClient::Change( const std::string& proposedLeaseId, - const ChangeBlobLeaseOptions& options) + const ChangeBlobLeaseOptions& options) const { if (m_blobClient.HasValue()) { @@ -233,7 +229,6 @@ namespace Azure { namespace Storage { namespace Blobs { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -264,7 +259,6 @@ namespace Azure { namespace Storage { namespace Blobs { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -276,7 +270,7 @@ namespace Azure { namespace Storage { namespace Blobs { } Azure::Core::Response BlobLeaseClient::Break( - const BreakBlobLeaseOptions& options) + const BreakBlobLeaseOptions& options) const { if (m_blobClient.HasValue()) { diff --git a/sdk/storage/azure-storage-blobs/test/blob_container_client_test.cpp b/sdk/storage/azure-storage-blobs/test/blob_container_client_test.cpp index 09f95925a..e97b8faef 100644 --- a/sdk/storage/azure-storage-blobs/test/blob_container_client_test.cpp +++ b/sdk/storage/azure-storage-blobs/test/blob_container_client_test.cpp @@ -452,6 +452,7 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_TRUE(cLease.ETag.HasValue()); EXPECT_TRUE(IsValidTime(cLease.LastModified)); EXPECT_EQ(cLease.LeaseId, leaseId2); + leaseClient = Blobs::BlobLeaseClient(containerClient, cLease.LeaseId); EXPECT_EQ(leaseClient.GetLeaseId(), leaseId2); auto containerInfo = *leaseClient.Release(); diff --git a/sdk/storage/azure-storage-blobs/test/page_blob_client_test.cpp b/sdk/storage/azure-storage-blobs/test/page_blob_client_test.cpp index 4a683d5cf..6ef433422 100644 --- a/sdk/storage/azure-storage-blobs/test/page_blob_client_test.cpp +++ b/sdk/storage/azure-storage-blobs/test/page_blob_client_test.cpp @@ -208,6 +208,7 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_TRUE(cLease.ETag.HasValue()); EXPECT_TRUE(IsValidTime(cLease.LastModified)); EXPECT_EQ(cLease.LeaseId, leaseId2); + leaseClient = Blobs::BlobLeaseClient(*m_pageBlobClient, cLease.LeaseId); EXPECT_EQ(leaseClient.GetLeaseId(), leaseId2); auto blobInfo = *leaseClient.Release(); diff --git a/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_lease_client.hpp b/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_lease_client.hpp index e98cb2ef9..e4fb47159 100644 --- a/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_lease_client.hpp +++ b/sdk/storage/azure-storage-files-datalake/inc/azure/storage/files/datalake/datalake_lease_client.hpp @@ -75,7 +75,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { */ Azure::Core::Response Acquire( std::chrono::seconds duration, - const AcquireDataLakeLeaseOptions& options = AcquireDataLakeLeaseOptions()) + const AcquireDataLakeLeaseOptions& options = AcquireDataLakeLeaseOptions()) const { return m_blobLeaseClient.Acquire(duration, options); } @@ -88,7 +88,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { * @return A RenewDataLakeLeaseResult describing the lease. */ Azure::Core::Response Renew( - const RenewDataLakeLeaseOptions& options = RenewDataLakeLeaseOptions()) + const RenewDataLakeLeaseOptions& options = RenewDataLakeLeaseOptions()) const { return m_blobLeaseClient.Renew(options); } @@ -98,10 +98,10 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { * * @param leaseId ID of the previously-acquired lease. * @param options Optional parameters to execute this function. - * @return A ReleaseDataLakeLeaseResult describing the updated container. + * @return A ReleaseDataLakeLeaseResult describing the updated container or blob. */ Azure::Core::Response Release( - const ReleaseDataLakeLeaseOptions& options = ReleaseDataLakeLeaseOptions()) + const ReleaseDataLakeLeaseOptions& options = ReleaseDataLakeLeaseOptions()) const { return m_blobLeaseClient.Release(options); } @@ -112,11 +112,12 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { * @param leaseId ID of the previously-acquired lease. * @param proposedLeaseId Proposed lease ID, in a GUID string format. * @param options Optional parameters to execute this function. - * @return A ChangeDataLakeLeaseResult describing the lease. + * @return A ChangeDataLakeLeaseResult describing the changed lease. + * @remarks The current DataLakeLeaseClient becomes invalid if this operation succeeds. */ Azure::Core::Response Change( const std::string& proposedLeaseId, - const ChangeDataLakeLeaseOptions& options = ChangeDataLakeLeaseOptions()) + const ChangeDataLakeLeaseOptions& options = ChangeDataLakeLeaseOptions()) const { return m_blobLeaseClient.Change(proposedLeaseId, options); } @@ -128,7 +129,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { * @return A BreakDataLakeLeaseResult describing the broken lease. */ Azure::Core::Response Break( - const BreakDataLakeLeaseOptions& options = BreakDataLakeLeaseOptions()) + const BreakDataLakeLeaseOptions& options = BreakDataLakeLeaseOptions()) const { return m_blobLeaseClient.Break(options); } diff --git a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_lease_client.hpp b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_lease_client.hpp index 95040dddd..4bc0b1719 100644 --- a/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_lease_client.hpp +++ b/sdk/storage/azure-storage-files-shares/inc/azure/storage/files/shares/share_lease_client.hpp @@ -57,17 +57,17 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { */ Azure::Core::Response Acquire( std::chrono::seconds duration, - const AcquireShareLeaseOptions& options = AcquireShareLeaseOptions()); + const AcquireShareLeaseOptions& options = AcquireShareLeaseOptions()) const; /** * @brief Releases the file or share's previously-acquired lease. * * @param leaseId ID of the previously-acquired lease. * @param options Optional parameters to execute this function. - * @return A ReleaseShareLeaseResult describing the updated container. + * @return A ReleaseShareLeaseResult describing the updated share or file. */ Azure::Core::Response Release( - const ReleaseShareLeaseOptions& options = ReleaseShareLeaseOptions()); + const ReleaseShareLeaseOptions& options = ReleaseShareLeaseOptions()) const; /** * @brief Changes the lease of an active lease. @@ -75,11 +75,12 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { * @param leaseId ID of the previously-acquired lease. * @param proposedLeaseId Proposed lease ID, in a GUID string format. * @param options Optional parameters to execute this function. - * @return A ChangeShareLeaseResult describing the lease. + * @return A ChangeShareLeaseResult describing the updated lease. + * @remarks The current ShareLeaseClient becomes invalid if this operation succeeds. */ Azure::Core::Response Change( const std::string& proposedLeaseId, - const ChangeShareLeaseOptions& options = ChangeShareLeaseOptions()); + const ChangeShareLeaseOptions& options = ChangeShareLeaseOptions()) const; /** * @brief Breaks the previously-acquired lease. @@ -88,7 +89,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { * @return A BreakShareLeaseResult describing the broken lease. */ Azure::Core::Response Break( - const BreakShareLeaseOptions& options = BreakShareLeaseOptions()); + const BreakShareLeaseOptions& options = BreakShareLeaseOptions()) const; private: /** @@ -110,7 +111,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { * @return A RenewShareLeaseResult describing the lease. */ Azure::Core::Response Renew( - const RenewShareLeaseOptions& options = RenewShareLeaseOptions()); + const RenewShareLeaseOptions& options = RenewShareLeaseOptions()) const; Azure::Core::Nullable m_fileClient; Azure::Core::Nullable m_shareClient; diff --git a/sdk/storage/azure-storage-files-shares/src/share_lease_client.cpp b/sdk/storage/azure-storage-files-shares/src/share_lease_client.cpp index 719ab66e4..27bcd7946 100644 --- a/sdk/storage/azure-storage-files-shares/src/share_lease_client.cpp +++ b/sdk/storage/azure-storage-files-shares/src/share_lease_client.cpp @@ -16,7 +16,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { Azure::Core::Response ShareLeaseClient::Acquire( std::chrono::seconds duration, - const AcquireShareLeaseOptions& options) + const AcquireShareLeaseOptions& options) const { if (m_fileClient.HasValue()) { @@ -34,7 +34,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -55,7 +54,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -67,7 +65,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } Azure::Core::Response ShareLeaseClient::Renew( - const RenewShareLeaseOptions& options) + const RenewShareLeaseOptions& options) const { if (m_fileClient.HasValue()) { @@ -89,7 +87,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -101,7 +98,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } Azure::Core::Response ShareLeaseClient::Release( - const ReleaseShareLeaseOptions& options) + const ReleaseShareLeaseOptions& options) const { if (m_fileClient.HasValue()) { @@ -147,7 +144,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { Azure::Core::Response ShareLeaseClient::Change( const std::string& proposedLeaseId, - const ChangeShareLeaseOptions& options) + const ChangeShareLeaseOptions& options) const { if (m_fileClient.HasValue()) { @@ -165,7 +162,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -186,7 +182,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { ret.ETag = std::move(response->ETag); ret.LastModified = std::move(response->LastModified); ret.LeaseId = std::move(response->LeaseId); - m_leaseId = ret.LeaseId; return Azure::Core::Response( std::move(ret), response.ExtractRawResponse()); @@ -198,7 +193,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares { } Azure::Core::Response ShareLeaseClient::Break( - const BreakShareLeaseOptions& options) + const BreakShareLeaseOptions& options) const { if (m_fileClient.HasValue()) { diff --git a/sdk/storage/azure-storage-files-shares/test/share_file_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/share_file_client_test.cpp index e5ce65191..dcf0c9aac 100644 --- a/sdk/storage/azure-storage-files-shares/test/share_file_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/share_file_client_test.cpp @@ -272,6 +272,8 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_TRUE(cLease.ETag.HasValue()); EXPECT_TRUE(cLease.LastModified >= lastModified); EXPECT_EQ(cLease.LeaseId, leaseId2); + leaseClient = Files::Shares::ShareLeaseClient(*m_fileClient, cLease.LeaseId); + EXPECT_EQ(leaseClient.GetLeaseId(), leaseId2); lastModified = m_fileClient->GetProperties()->LastModified; auto fileInfo = *leaseClient.Release();