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

Batch API: Add support of request options for transactional batch #1569

Merged
merged 10 commits into from
Jul 14, 2020
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/Batch/BatchCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ public override Task<TransactionalBatchResponse> ExecuteAsync(
/// <summary>
/// Executes the batch at the Azure Cosmos service as an asynchronous operation.
/// </summary>
/// <param name="requestOptions">Options that apply to the batch. Used only for EPK routing.</param>
/// <param name="requestOptions">Options that apply to the batch.</param>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>An awaitable <see cref="TransactionalBatchResponse"/> which contains the completion status and results of each operation.</returns>
public virtual Task<TransactionalBatchResponse> ExecuteAsync(
public override Task<TransactionalBatchResponse> ExecuteAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default(CancellationToken))
{
Expand Down
32 changes: 32 additions & 0 deletions Microsoft.Azure.Cosmos/src/Batch/TransactionalBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,37 @@ public abstract TransactionalBatch DeleteItem(
/// </remarks>
public abstract Task<TransactionalBatchResponse> ExecuteAsync(
CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Executes the transactional batch at the Azure Cosmos service as an asynchronous operation.
/// </summary>
/// <param name="requestOptions">Options that apply to the batch.</param>
/// <param name="cancellationToken">(Optional) Cancellation token representing request cancellation.</param>
/// <returns>An awaitable response which contains details of execution of the transactional batch.
/// <para>
/// If the transactional batch executes successfully, the <see cref="TransactionalBatchResponse.StatusCode"/> on the response returned
/// will be set to <see cref="HttpStatusCode.OK"/>.
/// </para>
/// <para>
/// If an operation within the transactional batch fails during execution, no changes from the batch will be committed
/// and the status of the failing operation is made available in the <see cref="TransactionalBatchResponse.StatusCode"/>.
/// To get more details about the operation that failed, the response can be enumerated - this returns <see cref="TransactionalBatchOperationResult" />
/// instances corresponding to each operation in the transactional batch in the order they were added into the transactional batch.
/// For a result corresponding to an operation within the transactional batch, the <see cref="TransactionalBatchOperationResult.StatusCode"/> indicates
/// the status of the operation - if the operation was not executed or it was aborted due to the failure of another operation within the transactional batch,
/// the value of this field will be HTTP 424 (Failed Dependency); for the operation that caused the batch to abort, the value of this field will indicate
/// the cause of failure as a HTTP status code.
/// </para>
/// <para>
/// The <see cref="TransactionalBatchResponse.StatusCode"/> on the response returned may also have values such as HTTP 5xx in case of server errors and HTTP 429 (Too Many Requests).
/// </para>
/// </returns>
/// <remarks>
/// This API only throws on client side exceptions. This is to increase performance and prevent the overhead of throwing exceptions.
/// Use <see cref="TransactionalBatchResponse.IsSuccessStatusCode"/> on the response returned to ensure that the transactional batch succeeded.
/// </remarks>
public abstract Task<TransactionalBatchResponse> ExecuteAsync(
RequestOptions requestOptions,
ealsur marked this conversation as resolved.
Show resolved Hide resolved
j82w marked this conversation as resolved.
Show resolved Hide resolved
rakkuma marked this conversation as resolved.
Show resolved Hide resolved
CancellationToken cancellationToken = default(CancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public async Task BatchOperationDiagnostic(bool disableDiagnostics)
}

RequestOptions requestOptions = disableDiagnostics ? RequestOptionDisableDiagnostic : null;
TransactionalBatchResponse response = await ((BatchCore)batch).ExecuteAsync(requestOptions);
TransactionalBatchResponse response = await batch.ExecuteAsync(requestOptions);

Assert.IsNotNull(response);
CosmosDiagnosticsTests.VerifyPointDiagnostics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private static async Task VerifyExceptionThrownOnExecuteAsync(
{
if (requestOptions != null)
{
await ((BatchCore)batch).ExecuteAsync(requestOptions);
await batch.ExecuteAsync(requestOptions);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7928,6 +7928,11 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.TransactionalBatch UpsertItemStream(System.IO.Stream, Microsoft.Azure.Cosmos.TransactionalBatchItemRequestOptions)"
},
"System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.TransactionalBatchResponse] ExecuteAsync(Microsoft.Azure.Cosmos.RequestOptions, System.Threading.CancellationToken)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.TransactionalBatchResponse] ExecuteAsync(Microsoft.Azure.Cosmos.RequestOptions, System.Threading.CancellationToken)"
},
"System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.TransactionalBatchResponse] ExecuteAsync(System.Threading.CancellationToken)": {
"Type": "Method",
"Attributes": [],
Expand Down