Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
792c909
Fixes to ReadThroughputAsync for databases with no provisioned throug…
NaluTripician Oct 10, 2022
fbd6aee
Merge branch 'master' into users/nalutripician/ReadThroughputAsyncNoP…
NaluTripician Oct 10, 2022
87b3663
fixed failure to ReadReplaceThroughputResponseTests
NaluTripician Oct 10, 2022
92fdeb0
Merge branch 'users/nalutripician/ReadThroughputAsyncNoProvisionedThr…
NaluTripician Oct 10, 2022
f49f8f9
Added Stream Method
NaluTripician Oct 17, 2022
0144e57
Merge branch 'master' into users/nalutripician/ReadThroughputAsyncNoP…
NaluTripician Oct 17, 2022
bfd3cb9
Ran UpdateContract.ps1
NaluTripician Oct 17, 2022
624344a
Encryption implemtation
NaluTripician Oct 17, 2022
939e721
Fixed spelling error
NaluTripician Oct 17, 2022
c9407d9
Update Microsoft.Azure.Cosmos.Encryption/src/EncryptionDatabase.cs
NaluTripician Oct 18, 2022
51539b0
Variable name change
NaluTripician Oct 18, 2022
701c975
Update Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs
NaluTripician Oct 19, 2022
72e6df7
Suggested Changes and fixes
NaluTripician Oct 19, 2022
29778f4
Removed manufactured ResponseMessage + nits
NaluTripician Oct 20, 2022
dc5593f
Simplified PR
NaluTripician Oct 21, 2022
2298107
nits
NaluTripician Oct 21, 2022
33f664f
nits
NaluTripician Oct 21, 2022
eafafc1
initial changes TODO: Update tests
NaluTripician Nov 3, 2022
242e6bd
updated tests
NaluTripician Nov 9, 2022
735186c
nits'
NaluTripician Nov 9, 2022
190bf04
Merge branch 'master' into users/nalutripician/HttpTimeoutsThrow503
NaluTripician Nov 9, 2022
409b25d
Ran UpdateContracts.ps1
NaluTripician Nov 9, 2022
38ecc60
Merge branch 'users/nalutripician/HttpTimeoutsThrow503' of https://gi…
NaluTripician Nov 9, 2022
9801ed2
nits + requested changes
NaluTripician Nov 11, 2022
ce3bd91
Delete NuGet.Config
NaluTripician Nov 11, 2022
33d3ed7
Merge branch 'master' into users/nalutripician/HttpTimeoutsThrow503
NaluTripician Nov 11, 2022
a0017d5
Update Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs
NaluTripician Nov 11, 2022
3d78a50
Update Microsoft.Azure.Cosmos/src/HttpClient/HttpTimeoutPolicy.cs
NaluTripician Nov 11, 2022
3383da2
Update Microsoft.Azure.Cosmos/src/HttpClient/HttpTimeoutPolicy.cs
NaluTripician Nov 11, 2022
396e717
Update Microsoft.Azure.Cosmos/src/HttpClient/HttpTimeoutPolicy.cs
NaluTripician Nov 11, 2022
7d6c307
Use Cosmos Exception Factory, Simplified Tests
NaluTripician Nov 11, 2022
9056324
removed unused code
NaluTripician Nov 15, 2022
24e106b
nits: removed unused code
NaluTripician Nov 15, 2022
6d4ae74
removed unused code
NaluTripician Nov 15, 2022
c696c71
Merge branch 'master' into users/nalutripician/HttpTimeoutsThrow503
NaluTripician Nov 16, 2022
a1bba57
Merge branch 'master' into users/nalutripician/HttpTimeoutsThrow503
ealsur Nov 18, 2022
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
Prev Previous commit
Next Next commit
Added Stream Method
  • Loading branch information
NaluTripician committed Oct 17, 2022
commit f49f8f9525740fef3d7f37a67e37e5a8d96f900b
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
36 changes: 27 additions & 9 deletions Microsoft.Azure.Cosmos/src/Resource/Offer/CosmosOffers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ internal async Task<ThroughputResponse> ReadThroughputAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default)
{
if (requestOptions == null)
{
(OfferV2 nullOfferV2, _) = await this.GetOfferV2Async<OfferV2>(targetRID, failIfNotConfigured: false, cancellationToken: cancellationToken);
if (nullOfferV2 == null)
{
return new ThroughputResponse(HttpStatusCode.NoContent, null, null, null, null);
}
}

(OfferV2 offerV2, double requestCharge) = await this.GetOfferV2Async<OfferV2>(targetRID, failIfNotConfigured: true, cancellationToken: cancellationToken);

return await this.GetThroughputResponseAsync(
Expand All @@ -52,6 +43,33 @@ internal async Task<ThroughputResponse> ReadThroughputAsync(

}

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(
string targetRID,
RequestOptions requestOptions,
Expand Down
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 @@ -166,15 +167,21 @@ public async Task ReadThroughutNullRequestOptions()
Database db1 = await this.cosmosClient.CreateDatabaseAsync(
Guid.NewGuid().ToString(),
throughput: null);
try
{
await db1.ReadThroughputAsync(requestOptions: null);
}
catch
{
await db1.DeleteAsync();
Assert.Fail();
}

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,
Expand Down