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

Throughput fix for throwing on not found and using custom serializer #772

Merged
merged 9 commits into from
Sep 10, 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 @@ -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