Skip to content

Commit

Permalink
Use TimeSpan for break period (#7842)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLove-msft authored Oct 2, 2019
1 parent 5eead6d commit 66b584a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 15 additions & 14 deletions sdk/storage/Azure.Storage.Blobs/src/LeaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ private async Task<Response<Lease>> 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 <paramref name="breakPeriodInSeconds"/> is allowed to elapse,
/// break <paramref name="breakPeriod"/> is allowed to elapse,
/// during which time no lease operation except
/// <see cref="Break"/> and <see cref="Release"/> can be
/// performed on the blob or container. When a lease is successfully
Expand All @@ -852,7 +852,7 @@ private async Task<Response<Lease>> ChangeInternal(
///
/// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container" />.
/// </summary>
/// <param name="breakPeriodInSeconds">
/// <param name="breakPeriod">
/// 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.
Expand All @@ -878,11 +878,11 @@ private async Task<Response<Lease>> ChangeInternal(
/// a failure occurs.
/// </remarks>
public virtual Response<Lease> Break(
int? breakPeriodInSeconds = default,
TimeSpan? breakPeriod = default,
HttpAccessConditions? httpAccessConditions = default,
CancellationToken cancellationToken = default) =>
BreakInternal(
breakPeriodInSeconds,
breakPeriod,
httpAccessConditions,
false, // async
cancellationToken)
Expand All @@ -895,7 +895,7 @@ public virtual Response<Lease> 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 <paramref name="breakPeriodInSeconds"/> is allowed to elapse,
/// break <paramref name="breakPeriod"/> is allowed to elapse,
/// during which time no lease operation except
/// <see cref="BreakAsync"/> and <see cref="ReleaseAsync"/> can be
/// performed on the blob or container. When a lease is successfully
Expand All @@ -908,7 +908,7 @@ public virtual Response<Lease> Break(
///
/// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container" />.
/// </summary>
/// <param name="breakPeriodInSeconds">
/// <param name="breakPeriod">
/// 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.
Expand All @@ -934,11 +934,11 @@ public virtual Response<Lease> Break(
/// a failure occurs.
/// </remarks>
public virtual async Task<Response<Lease>> BreakAsync(
int? breakPeriodInSeconds = default,
TimeSpan? breakPeriod = default,
HttpAccessConditions? httpAccessConditions = default,
CancellationToken cancellationToken = default) =>
await BreakInternal(
breakPeriodInSeconds,
breakPeriod,
httpAccessConditions,
true, // async
cancellationToken)
Expand All @@ -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 <paramref name="breakPeriodInSeconds"/> is allowed to elapse,
/// break <paramref name="breakPeriod"/> is allowed to elapse,
/// during which time no lease operation except
/// <see cref="BreakAsync"/> and <see cref="ReleaseAsync"/> can be
/// performed on the blob or container. When a lease is successfully
Expand All @@ -964,7 +964,7 @@ await BreakInternal(
///
/// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container" />.
/// </summary>
/// <param name="breakPeriodInSeconds">
/// <param name="breakPeriod">
/// 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.
Expand Down Expand Up @@ -993,19 +993,20 @@ await BreakInternal(
/// a failure occurs.
/// </remarks>
private async Task<Response<Lease>> 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
{
Expand All @@ -1014,7 +1015,7 @@ private async Task<Response<Lease>> BreakInternal(
return (await BlobRestClient.Blob.BreakLeaseAsync(
Pipeline,
Uri,
breakPeriod: breakPeriodInSeconds,
breakPeriod: serviceBreakPeriod,
ifModifiedSince: httpAccessConditions?.IfModifiedSince,
ifUnmodifiedSince: httpAccessConditions?.IfUnmodifiedSince,
ifMatch: httpAccessConditions?.IfMatch,
Expand All @@ -1036,7 +1037,7 @@ private async Task<Response<Lease>> BreakInternal(
return (await BlobRestClient.Container.BreakLeaseAsync(
Pipeline,
Uri,
breakPeriod: breakPeriodInSeconds,
breakPeriod: serviceBreakPeriod,
ifModifiedSince: httpAccessConditions?.IfModifiedSince,
ifUnmodifiedSince: httpAccessConditions?.IfUnmodifiedSince,
async: async,
Expand Down
8 changes: 6 additions & 2 deletions sdk/storage/Azure.Storage.Blobs/swagger/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1063,15 +1063,19 @@ 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:
- from: swagger-document
where: $.parameters.LeaseDuration
transform: >
$.format = "int64";
- from: swagger-document
where: $.parameters.LeaseBreakPeriod
transform: >
$.format = "int64";
```
### Merge the PageBlob AccessTier type
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lease> response = await lease.BreakAsync(breakPeriodInSeconds: breakPeriod);
Response<Lease> response = await lease.BreakAsync(breakPeriod: breakPeriod);

// Assert
Assert.IsNotNull(response.GetRawResponse().Headers.RequestId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lease> breakResponse = await InstrumentClient(container.GetLeaseClient()).BreakAsync(breakPeriod);
Expand Down

0 comments on commit 66b584a

Please sign in to comment.