diff --git a/sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs b/sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs index c8af2c216006f..e6a63463788a0 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/Generated/BlobRestClient.cs @@ -2501,7 +2501,7 @@ internal static Azure.Core.Pipeline.HttpPipelineMessage RenewLeaseAsync_CreateMe Azure.Core.Pipeline.HttpPipeline pipeline, System.Uri resourceUri, int? timeout = default, - int? breakPeriod = default, + long? breakPeriod = default, System.DateTimeOffset? ifModifiedSince = default, System.DateTimeOffset? ifUnmodifiedSince = default, string requestId = default, @@ -2565,7 +2565,7 @@ internal static Azure.Core.Pipeline.HttpPipelineMessage BreakLeaseAsync_CreateMe Azure.Core.Pipeline.HttpPipeline pipeline, System.Uri resourceUri, int? timeout = default, - int? breakPeriod = default, + long? breakPeriod = default, System.DateTimeOffset? ifModifiedSince = default, System.DateTimeOffset? ifUnmodifiedSince = default, string requestId = default) @@ -6039,7 +6039,7 @@ internal static Azure.Core.Pipeline.HttpPipelineMessage ChangeLeaseAsync_CreateM Azure.Core.Pipeline.HttpPipeline pipeline, System.Uri resourceUri, int? timeout = default, - int? breakPeriod = default, + long? breakPeriod = default, System.DateTimeOffset? ifModifiedSince = default, System.DateTimeOffset? ifUnmodifiedSince = default, Azure.Core.Http.ETag? ifMatch = default, @@ -6109,7 +6109,7 @@ internal static Azure.Core.Pipeline.HttpPipelineMessage BreakLeaseAsync_CreateMe Azure.Core.Pipeline.HttpPipeline pipeline, System.Uri resourceUri, int? timeout = default, - int? breakPeriod = default, + long? breakPeriod = default, System.DateTimeOffset? ifModifiedSince = default, System.DateTimeOffset? ifUnmodifiedSince = default, Azure.Core.Http.ETag? ifMatch = default, diff --git a/sdk/storage/Azure.Storage.Blobs/src/LeaseClient.cs b/sdk/storage/Azure.Storage.Blobs/src/LeaseClient.cs index d4953ced572ff..7d69a6d498abd 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/LeaseClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/LeaseClient.cs @@ -839,7 +839,7 @@ private async Task> ChangeInternal( /// Once a lease is broken, it cannot be renewed. Any authorized /// request can break the lease; the request is not required to /// specify a matching lease ID. When a lease is broken, the lease - /// break is allowed to elapse, + /// break is allowed to elapse, /// during which time no lease operation except /// and can be /// performed on the blob or container. When a lease is successfully @@ -852,7 +852,7 @@ private async Task> ChangeInternal( /// /// For more information, see . /// - /// + /// /// Specifies the proposed duration the lease should continue before /// it is broken, in seconds, between 0 and 60. This break period is /// only used if it is shorter than the time remaining on the lease. @@ -878,11 +878,11 @@ private async Task> ChangeInternal( /// a failure occurs. /// public virtual Response Break( - int? breakPeriodInSeconds = default, + TimeSpan? breakPeriod = default, HttpAccessConditions? httpAccessConditions = default, CancellationToken cancellationToken = default) => BreakInternal( - breakPeriodInSeconds, + breakPeriod, httpAccessConditions, false, // async cancellationToken) @@ -895,7 +895,7 @@ public virtual Response Break( /// Once a lease is broken, it cannot be renewed. Any authorized /// request can break the lease; the request is not required to /// specify a matching lease ID. When a lease is broken, the lease - /// break is allowed to elapse, + /// break is allowed to elapse, /// during which time no lease operation except /// and can be /// performed on the blob or container. When a lease is successfully @@ -908,7 +908,7 @@ public virtual Response Break( /// /// For more information, see . /// - /// + /// /// Specifies the proposed duration the lease should continue before /// it is broken, in seconds, between 0 and 60. This break period is /// only used if it is shorter than the time remaining on the lease. @@ -934,11 +934,11 @@ public virtual Response Break( /// a failure occurs. /// public virtual async Task> BreakAsync( - int? breakPeriodInSeconds = default, + TimeSpan? breakPeriod = default, HttpAccessConditions? httpAccessConditions = default, CancellationToken cancellationToken = default) => await BreakInternal( - breakPeriodInSeconds, + breakPeriod, httpAccessConditions, true, // async cancellationToken) @@ -951,7 +951,7 @@ await BreakInternal( /// Once a lease is broken, it cannot be renewed. Any authorized /// request can break the lease; the request is not required to /// specify a matching lease ID. When a lease is broken, the lease - /// break is allowed to elapse, + /// break is allowed to elapse, /// during which time no lease operation except /// and can be /// performed on the blob or container. When a lease is successfully @@ -964,7 +964,7 @@ await BreakInternal( /// /// For more information, see . /// - /// + /// /// Specifies the proposed duration the lease should continue before /// it is broken, in seconds, between 0 and 60. This break period is /// only used if it is shorter than the time remaining on the lease. @@ -993,19 +993,20 @@ await BreakInternal( /// a failure occurs. /// private async Task> BreakInternal( - int? breakPeriodInSeconds, + TimeSpan? breakPeriod, HttpAccessConditions? httpAccessConditions, bool async, CancellationToken cancellationToken) { EnsureClient(); + long? serviceBreakPeriod = breakPeriod != null ? Convert.ToInt64(breakPeriod.Value.TotalSeconds) : (long?) null; using (Pipeline.BeginLoggingScope(nameof(LeaseClient))) { Pipeline.LogMethodEnter( nameof(LeaseClient), message: $"{nameof(Uri)}: {Uri}\n" + - $"{nameof(breakPeriodInSeconds)}: {breakPeriodInSeconds}\n" + + $"{nameof(breakPeriod)}: {breakPeriod}\n" + $"{nameof(httpAccessConditions)}: {httpAccessConditions}"); try { @@ -1014,7 +1015,7 @@ private async Task> BreakInternal( return (await BlobRestClient.Blob.BreakLeaseAsync( Pipeline, Uri, - breakPeriod: breakPeriodInSeconds, + breakPeriod: serviceBreakPeriod, ifModifiedSince: httpAccessConditions?.IfModifiedSince, ifUnmodifiedSince: httpAccessConditions?.IfUnmodifiedSince, ifMatch: httpAccessConditions?.IfMatch, @@ -1036,7 +1037,7 @@ private async Task> BreakInternal( return (await BlobRestClient.Container.BreakLeaseAsync( Pipeline, Uri, - breakPeriod: breakPeriodInSeconds, + breakPeriod: serviceBreakPeriod, ifModifiedSince: httpAccessConditions?.IfModifiedSince, ifUnmodifiedSince: httpAccessConditions?.IfUnmodifiedSince, async: async, diff --git a/sdk/storage/Azure.Storage.Blobs/swagger/readme.md b/sdk/storage/Azure.Storage.Blobs/swagger/readme.md index f34fe6a27098b..378852bed247a 100644 --- a/sdk/storage/Azure.Storage.Blobs/swagger/readme.md +++ b/sdk/storage/Azure.Storage.Blobs/swagger/readme.md @@ -1063,8 +1063,8 @@ directive: transform: $.required.push("PublicAccess"); ``` -### Make lease duration a long -Lease Duration is represented as a TimeSpan in the .NET client libraries, but TimeSpan.MaxValue would overflow an int. Because of this, we are changing the +### Make lease duration/break period a long +Lease Duration/Break Period are represented as a TimeSpan in the .NET client libraries, but TimeSpan.MaxValue would overflow an int. Because of this, we are changing the type used in the BlobRestClient from an int to a long. This will allow values larger than int.MaxValue (e.g. TimeSpan.MaxValue) to be successfully passed on to the service layer. ``` yaml directive: @@ -1072,6 +1072,10 @@ directive: where: $.parameters.LeaseDuration transform: > $.format = "int64"; +- from: swagger-document + where: $.parameters.LeaseBreakPeriod + transform: > + $.format = "int64"; ``` ### Merge the PageBlob AccessTier type diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs index 349c0d84f2bf3..c8e70e4ffccef 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs @@ -2104,13 +2104,13 @@ public async Task BreakLeaseAsync_BreakPeriod() var leaseId = Recording.Random.NewGuid().ToString(); var duration = TimeSpan.FromSeconds(15); - var breakPeriod = 5; + TimeSpan breakPeriod = TimeSpan.FromSeconds(5); LeaseClient lease = InstrumentClient(blob.GetLeaseClient(leaseId)); await lease.AcquireAsync(duration); // Act - Response response = await lease.BreakAsync(breakPeriodInSeconds: breakPeriod); + Response response = await lease.BreakAsync(breakPeriod: breakPeriod); // Assert Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); diff --git a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs index a3e4e42d7e668..20cedaddda27e 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs @@ -947,7 +947,7 @@ public async Task BreakLeaseAsync() var id = Recording.Random.NewGuid().ToString(); var duration = TimeSpan.FromSeconds(15); await InstrumentClient(container.GetLeaseClient(id)).AcquireAsync(duration); - var breakPeriod = 0; + TimeSpan breakPeriod = TimeSpan.FromSeconds(0); // Act Response breakResponse = await InstrumentClient(container.GetLeaseClient()).BreakAsync(breakPeriod);