Skip to content
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

Storage: Use RequestConditions and return exploding responses #8275

Merged
merged 4 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static InvalidOperationException InvalidHttpHeaderLine(string headerLine)
new InvalidOperationException($"Expected an HTTP header line, not {headerLine}");

public static RequestFailedException InvalidResponse(Response response, Exception innerException) =>
StorageRequestFailedExceptionHelpers.CreateException(response, "Invalid response", innerException);
StorageExceptionExtensions.CreateException(response, "Invalid response", innerException);

}
}
40 changes: 20 additions & 20 deletions sdk/storage/Azure.Storage.Blobs.Batching/src/BlobBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void SetBatchOperationType(BlobBatchOperationType operationType)

#region DeleteBlob
/// <summary>
/// The <see cref="DeleteBlob(string, string, DeleteSnapshotsOption, BlobAccessConditions?)"/>
/// The <see cref="DeleteBlob(string, string, DeleteSnapshotsOption, BlobRequestConditions)"/>
/// operation marks the specified blob or snapshot for deletion. The
/// blob is later deleted during garbage collection.
///
Expand All @@ -119,8 +119,8 @@ private void SetBatchOperationType(BlobBatchOperationType operationType)
/// <param name="snapshotsOption">
/// Specifies options for deleting blob snapshots.
/// </param>
/// <param name="accessConditions">
/// Optional <see cref="BlobAccessConditions"/> to add conditions on
/// <param name="conditions">
/// Optional <see cref="BlobRequestConditions"/> to add conditions on
/// deleting this blob.
/// </param>
/// <returns>
Expand All @@ -132,7 +132,7 @@ public virtual Response DeleteBlob(
string blobContainerName,
string blobName,
DeleteSnapshotsOption snapshotsOption = default,
BlobAccessConditions? accessConditions = default)
BlobRequestConditions conditions = default)
{
var blobUri = new BlobUriBuilder(_client.Uri)
{
Expand All @@ -142,11 +142,11 @@ public virtual Response DeleteBlob(
return DeleteBlob(
blobUri.ToUri(),
snapshotsOption,
accessConditions);
conditions);
}

/// <summary>
/// The <see cref="DeleteBlob(Uri, DeleteSnapshotsOption, BlobAccessConditions?)"/>
/// The <see cref="DeleteBlob(Uri, DeleteSnapshotsOption, BlobRequestConditions)"/>
/// operation marks the specified blob or snapshot for deletion. The
/// blob is later deleted during garbage collection.
///
Expand All @@ -163,8 +163,8 @@ public virtual Response DeleteBlob(
/// <param name="snapshotsOption">
/// Specifies options for deleting blob snapshots.
/// </param>
/// <param name="accessConditions">
/// Optional <see cref="BlobAccessConditions"/> to add conditions on
/// <param name="conditions">
/// Optional <see cref="BlobRequestConditions"/> to add conditions on
/// deleting this blob.
/// </param>
/// <returns>
Expand All @@ -175,26 +175,26 @@ public virtual Response DeleteBlob(
public virtual Response DeleteBlob(
Uri blobUri,
DeleteSnapshotsOption snapshotsOption = default,
BlobAccessConditions? accessConditions = default)
BlobRequestConditions conditions = default)
{
SetBatchOperationType(BlobBatchOperationType.Delete);
HttpMessage message = BlobRestClient.Blob.DeleteAsync_CreateMessage(
_client.BatchOperationPipeline,
blobUri,
deleteSnapshots: snapshotsOption == DeleteSnapshotsOption.None ? null : (DeleteSnapshotsOption?)snapshotsOption,
leaseId: accessConditions?.LeaseAccessConditions?.LeaseId,
ifModifiedSince: accessConditions?.HttpAccessConditions?.IfModifiedSince,
ifUnmodifiedSince: accessConditions?.HttpAccessConditions?.IfUnmodifiedSince,
ifMatch: accessConditions?.HttpAccessConditions?.IfMatch,
ifNoneMatch: accessConditions?.HttpAccessConditions?.IfNoneMatch);
leaseId: conditions?.LeaseId,
ifModifiedSince: conditions?.IfModifiedSince,
ifUnmodifiedSince: conditions?.IfUnmodifiedSince,
ifMatch: conditions?.IfMatch,
ifNoneMatch: conditions?.IfNoneMatch);
_messages.Add(message);
return new DelayedResponse(message, BlobRestClient.Blob.DeleteAsync_CreateResponse);
}
#endregion DeleteBlob

#region SetBlobAccessTier
/// <summary>
/// The <see cref="SetBlobAccessTier(string, string, AccessTier, RehydratePriority?, LeaseAccessConditions?)"/>
/// The <see cref="SetBlobAccessTier(string, string, AccessTier, RehydratePriority?, BlobRequestConditions)"/>
/// operation sets the tier on a blob. The operation is allowed on
/// block blobs in a blob storage or general purpose v2 account.
///
Expand All @@ -213,7 +213,7 @@ public virtual Response DeleteBlob(
/// Indicates the tier to be set on the blob.
/// </param>
/// <param name="leaseAccessConditions">
/// Optional <see cref="LeaseAccessConditions"/> to add conditions on
/// Optional <see cref="BlobRequestConditions"/> to add conditions on
/// setting the access tier.
/// </param>
/// <param name="rehydratePriority">
Expand All @@ -230,7 +230,7 @@ public virtual Response SetBlobAccessTier(
string blobName,
AccessTier accessTier,
RehydratePriority? rehydratePriority = default,
LeaseAccessConditions? leaseAccessConditions = default)
BlobRequestConditions leaseAccessConditions = default)
{
var blobUri = new BlobUriBuilder(_client.Uri)
{
Expand All @@ -245,7 +245,7 @@ public virtual Response SetBlobAccessTier(
}

/// <summary>
/// The <see cref="SetBlobAccessTier(Uri, AccessTier, RehydratePriority?, LeaseAccessConditions?)"/>
/// The <see cref="SetBlobAccessTier(Uri, AccessTier, RehydratePriority?, BlobRequestConditions)"/>
/// operation sets the tier on a blob. The operation is allowed on
/// block blobs in a blob storage or general purpose v2 account.
///
Expand All @@ -265,7 +265,7 @@ public virtual Response SetBlobAccessTier(
/// Indicates the priority with which to rehydrate an archived blob.
/// </param>
/// <param name="leaseAccessConditions">
/// Optional <see cref="LeaseAccessConditions"/> to add conditions on
/// Optional <see cref="BlobRequestConditions"/> to add conditions on
/// setting the access tier.
/// </param>
/// <returns>
Expand All @@ -277,7 +277,7 @@ public virtual Response SetBlobAccessTier(
Uri blobUri,
AccessTier accessTier,
RehydratePriority? rehydratePriority = default,
LeaseAccessConditions? leaseAccessConditions = default)
BlobRequestConditions leaseAccessConditions = default)
{
SetBatchOperationType(BlobBatchOperationType.SetAccessTier);
HttpMessage message = BlobRestClient.Blob.SetAccessTierAsync_CreateMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public override string ToString()
// We directly forward the entire Response interface to LiveResponse
#region forward Response members to Live
/// <inheritdoc />
public override int Status => LiveResponse.Status;
public override int Status =>
tg-msft marked this conversation as resolved.
Show resolved Hide resolved
_live == null ?
BatchConstants.NoStatusCode : // Give users a hint that this is an exploding Response
LiveResponse.Status;

/// <inheritdoc />
public override string ReasonPhrase => LiveResponse.ReasonPhrase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ public void Batch_Homogenous_SetTier()
StringAssert.Contains("already being used for SetAccessTier operations", ex.Message);
}

[Test]
public void Batch_StatusIndicatesCannotRead()
{
using TestScenario scenario = Scenario();
Uri uri = scenario.GetInvalidBlobUris(1)[0];

BlobBatchClient client = scenario.GetBlobBatchClient();
BlobBatch batch = client.CreateBatch();
Response response = batch.DeleteBlob(uri);

Assert.AreEqual(0, response.Status);
}

[Test]
public void Batch_CannotReadBeforeSubmit()
{
Expand All @@ -110,7 +123,7 @@ public void Batch_CannotReadBeforeSubmit()
BlobBatch batch = client.CreateBatch();
Response response = batch.DeleteBlob(uri);
InvalidOperationException ex = Assert.Throws<InvalidOperationException>(
() => { int status = response.Status; });
() => { var _ = response.ClientRequestId; });

StringAssert.Contains("Cannot use the Response before calling BlobBatchClient.SubmitBatch", ex.Message);
}
Expand Down
Loading