Skip to content

Commit

Permalink
Throughput fix for throwing on not found and using custom serializer (#…
Browse files Browse the repository at this point in the history
…772)

* Throughput operations no longer throw on not found, and custom serializer is not applied to any throughput operation.

* Fixed tests and replace with no throughput

* Fixed changelog

* Fixed test

* Update changelog.md

Co-Authored-By: kirankumarkolli <kirankk@microsoft.com>

* Added additional info to error  message.

* Removing duplicate test.
  • Loading branch information
j82w authored and kirankumarkolli committed Sep 10, 2019
1 parent 77a31f3 commit d235751
Show file tree
Hide file tree
Showing 11 changed files with 804 additions and 738 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override Task<ContainerResponse> DeleteContainerAsync(
public async override Task<int?> ReadThroughputAsync(
CancellationToken cancellationToken = default(CancellationToken))
{
ThroughputResponse response = await this.ReadThroughputAsync(null, cancellationToken);
ThroughputResponse response = await this.ReadThroughputIfExistsAsync(null, cancellationToken);
return response.Resource?.Throughput;
}

Expand Down
30 changes: 27 additions & 3 deletions Microsoft.Azure.Cosmos/src/Resource/CosmosResponseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,44 @@ internal CosmosResponseFactory(
this.cosmosSerializer = userJsonSerializer;
}

internal FeedResponse<T> CreateQueryFeedResponseWithPropertySerializer<T>(
ResponseMessage cosmosResponseMessage)
{
return this.CreateQueryFeedResponseHelper<T>(
cosmosResponseMessage,
true);
}

internal FeedResponse<T> CreateQueryFeedResponse<T>(
ResponseMessage cosmosResponseMessage)
{
return this.CreateQueryFeedResponseHelper<T>(
cosmosResponseMessage,
false);
}

private FeedResponse<T> CreateQueryFeedResponseHelper<T>(
ResponseMessage cosmosResponseMessage,
bool usePropertySerializer)
{
//Throw the exception
cosmosResponseMessage.EnsureSuccessStatusCode();

// The property serializer should be used for internal
// query operations like throughput since user serializer can break the logic
CosmosSerializer serializer = usePropertySerializer ? this.propertiesSerializer : this.cosmosSerializer;

QueryResponse queryResponse = cosmosResponseMessage as QueryResponse;
if (queryResponse != null)
{
return QueryResponse<T>.CreateResponse<T>(
cosmosQueryResponse: queryResponse,
jsonSerializer: this.cosmosSerializer);
jsonSerializer: serializer);
}

return ReadFeedResponse<T>.CreateResponse<T>(
cosmosResponseMessage,
this.cosmosSerializer);
serializer);
}

internal Task<ItemResponse<T>> CreateItemResponseAsync<T>(
Expand Down Expand Up @@ -112,7 +133,10 @@ internal Task<DatabaseResponse> CreateDatabaseResponseAsync(
{
return this.ProcessMessageAsync(cosmosResponseMessageTask, (cosmosResponseMessage) =>
{
DatabaseProperties databaseProperties = this.ToObjectInternal<DatabaseProperties>(cosmosResponseMessage, this.propertiesSerializer);
DatabaseProperties databaseProperties = this.ToObjectInternal<DatabaseProperties>(
cosmosResponseMessage,
this.propertiesSerializer);
return new DatabaseResponse(
cosmosResponseMessage.StatusCode,
cosmosResponseMessage.Headers,
Expand Down
Loading

0 comments on commit d235751

Please sign in to comment.