Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
10 changes: 10 additions & 0 deletions Microsoft.Azure.Cosmos.Encryption/src/EncryptionDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ public override Task<ThroughputResponse> ReadThroughputAsync(
cancellationToken);
}

#if SDKPROJECTREF
public override Task<ResponseMessage> ReadThroughputStreamAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default)
{
return this.database.ReadThroughputStreamAsync(
requestOptions,
cancellationToken);
}
#endif
public override Task<ThroughputResponse> ReplaceThroughputAsync(
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
Expand Down
14 changes: 14 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public abstract Task<DatabaseResponse> DeleteAsync(
/// </value>
/// <remarks>
/// Null value indicates a database with no throughput provisioned.
/// If requestOptions is set to null on a database with no througput provisioned a 404.0 exception will be thrown
/// </remarks>
/// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units">Request Units</seealso>
/// <seealso href="https://docs.microsoft.com/azure/cosmos-db/set-throughput#set-throughput-on-a-database">Set throughput on a database</seealso>
Expand Down Expand Up @@ -138,6 +139,19 @@ public abstract Task<ThroughputResponse> ReadThroughputAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default);

/// <summary>
/// Gets database throughput in measurement of request units per second in the Azure Cosmos service.
/// </summary>
/// <param name="requestOptions"></param>
/// <param name="cancellationToken"></param>
/// <returns>A <see cref="Task"/> containing a <see cref="ResponseMessage"/> containing the record of retrieving the provisioned throughput for this database .</returns>
/// <exception>https://aka.ms/cosmosdb-dot-net-exceptions</exception>
/// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units">Request Units</seealso>
/// <seealso href="https://docs.microsoft.com/azure/cosmos-db/set-throughput#set-throughput-on-a-database">Set throughput on a database</seealso>
public abstract Task<ResponseMessage> ReadThroughputStreamAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default);

/// <summary>
/// Sets throughput provisioned for a database in measurement of request units per second in the Azure Cosmos service.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ public async Task<ThroughputResponse> ReadThroughputAsync(
cancellationToken: cancellationToken);
}

public async Task<ResponseMessage> ReadThroughputStreamAsync(
RequestOptions requestOptions,
ITrace trace,
CancellationToken cancellationToken)
{
string rid = await this.GetRIDAsync(cancellationToken);
CosmosOffers cosmosOffers = new CosmosOffers(this.ClientContext);
return await cosmosOffers.ReadThroughputStreamAsync(
targetRID: rid,
requestOptions: requestOptions,
cancellationToken: cancellationToken,
uri: this.LinkUri);
}

internal override async Task<ThroughputResponse> ReadThroughputIfExistsAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken)
Expand Down
10 changes: 10 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseInlineCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ public override Task<ThroughputResponse> ReadThroughputAsync(
(response) => new OpenTelemetryResponse<ThroughputProperties>(response));
}

public override Task<ResponseMessage> ReadThroughputStreamAsync(
RequestOptions requestOptions,
CancellationToken cancellation = default)
{
return this.ClientContext.OperationHelperAsync(
nameof(ReadThroughputStreamAsync),
requestOptions,
(trace) => base.ReadThroughputStreamAsync(requestOptions, trace, cancellation),
(response) => new OpenTelemetryResponse(response));
}
public override Task<ThroughputResponse> ReplaceThroughputAsync(
int throughput,
RequestOptions requestOptions = null,
Expand Down
28 changes: 28 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Offer/CosmosOffers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ internal async Task<ThroughputResponse> ReadThroughputAsync(
currentRequestCharge: requestCharge,
requestOptions: requestOptions,
cancellationToken: cancellationToken);

}

internal async Task<ResponseMessage> ReadThroughputStreamAsync(
string targetRID,
RequestOptions requestOptions,
string uri,
CancellationToken cancellationToken = default)
{
(OfferV2 offerV2, double requestCharge) = await this.GetOfferV2Async<OfferV2>(targetRID, failIfNotConfigured: false, cancellationToken: cancellationToken);

string resourceUri = offerV2 != null ? new Uri(offerV2.SelfLink, UriKind.Relative).OriginalString : uri;

ResponseMessage responseMessage = await this.ClientContext.ProcessResourceOperationStreamAsync(
resourceUri: resourceUri,
resourceType: ResourceType.Offer,
operationType: OperationType.Read,
cosmosContainerCore: null,
feedRange: null,
streamPayload: null,
requestOptions: requestOptions,
requestEnricher: null,
trace: NoOpTrace.Singleton,
cancellationToken: cancellationToken);

responseMessage.Headers.RequestCharge += requestCharge;

return responseMessage;
}

internal async Task<ThroughputResponse> ReadThroughputIfExistsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1563,4 +1563,4 @@
</OTelActivities>
</Output>
</Result>
</Results>
</Results>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
{
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -105,7 +106,7 @@ public async Task ContainerRecreateOfferTestAsync()
ThroughputResponse offer = await container.ReadThroughputAsync(requestOptions: null);
Assert.AreEqual(offer.RequestCharge, this.requestChargeHandler.TotalRequestCharges);
Assert.AreEqual(400, offer.Resource.Throughput);

this.requestChargeHandler.TotalRequestCharges = 0;
ThroughputResponse replaceOffer = await container.ReplaceThroughputAsync(2000);
Assert.AreEqual(replaceOffer.RequestCharge, this.requestChargeHandler.TotalRequestCharges);
Expand Down Expand Up @@ -160,6 +161,28 @@ public async Task ContainerRecreateOfferTestAsync()
await db1.DeleteAsync();
}

[TestMethod]
public async Task ReadThroughutNullRequestOptions()
{
Database db1 = await this.cosmosClient.CreateDatabaseAsync(
Guid.NewGuid().ToString(),
throughput: null);

ResponseMessage responseMessage1 = await db1.ReadThroughputStreamAsync(requestOptions: null);

Assert.IsNotNull(responseMessage1);
Assert.AreEqual(HttpStatusCode.BadRequest, responseMessage1.StatusCode);

Database db2 = await this.cosmosClient.CreateDatabaseAsync(
Guid.NewGuid().ToString(),
throughput: 400);

ResponseMessage responseMessage2 = await db2.ReadThroughputStreamAsync(requestOptions: null);

Assert.IsNotNull(responseMessage2);
Assert.AreEqual(HttpStatusCode.OK, responseMessage2.StatusCode);

}
private async Task RecreateContainerUsingDifferentClient(
string databaseId,
string containerId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3622,6 +3622,11 @@
"Attributes": [],
"MethodInfo": "System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.ResponseMessage] ReadStreamAsync(Microsoft.Azure.Cosmos.RequestOptions, System.Threading.CancellationToken);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.ResponseMessage] ReadThroughputStreamAsync(Microsoft.Azure.Cosmos.RequestOptions, System.Threading.CancellationToken)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.ResponseMessage] ReadThroughputStreamAsync(Microsoft.Azure.Cosmos.RequestOptions, System.Threading.CancellationToken);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.ThroughputResponse] ReadThroughputAsync(Microsoft.Azure.Cosmos.RequestOptions, System.Threading.CancellationToken)": {
"Type": "Method",
"Attributes": [],
Expand Down