Skip to content

Commit

Permalink
Fixed missing diagnostics on find APIs (#14051)
Browse files Browse the repository at this point in the history
* Fixed missing diagnostics on find APIs

* Updated test cases for the fix

* Updated test cases for the fix
  • Loading branch information
kushagraThapar authored Aug 13, 2020
1 parent bf3f713 commit 8df9e17
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public <T> Iterable<T> findAll(PartitionKey partitionKey, final Class<T> domainT
.publishOn(Schedulers.parallel())
.flatMap(cosmosItemFeedResponse -> {
CosmosUtils.fillAndProcessResponseDiagnostics(this.responseDiagnosticsProcessor,
null, cosmosItemFeedResponse);
cosmosItemFeedResponse.getCosmosDiagnostics(), cosmosItemFeedResponse);
return Flux.fromIterable(cosmosItemFeedResponse.getResults());
})
.map(jsonNode -> toDomainObject(domainType, jsonNode))
Expand Down Expand Up @@ -728,7 +728,7 @@ private Long getCountValue(CosmosQuery query, String containerName) {
.onErrorResume(throwable ->
CosmosExceptionUtils.exceptionHandler("Failed to get count value", throwable))
.doOnNext(response -> CosmosUtils.fillAndProcessResponseDiagnostics(this.responseDiagnosticsProcessor,
null, response))
response.getCosmosDiagnostics(), response))
.next()
.map(r -> r.getResults().get(0).asLong())
.block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ private Mono<Long> getCountValue(CosmosQuery query, String containerName) {

return executeQuery(querySpec, containerName, options)
.doOnNext(feedResponse -> CosmosUtils.fillAndProcessResponseDiagnostics(this.responseDiagnosticsProcessor,
null, feedResponse))
feedResponse.getCosmosDiagnostics(), feedResponse))
.onErrorResume(throwable ->
CosmosExceptionUtils.exceptionHandler("Failed to get count value", throwable))
.next()
Expand Down Expand Up @@ -669,7 +669,7 @@ private Flux<JsonNode> findItems(@NonNull CosmosQuery query,
.publishOn(Schedulers.parallel())
.flatMap(cosmosItemFeedResponse -> {
CosmosUtils.fillAndProcessResponseDiagnostics(this.responseDiagnosticsProcessor,
null, cosmosItemFeedResponse);
cosmosItemFeedResponse.getCosmosDiagnostics(), cosmosItemFeedResponse);
return Flux.fromIterable(cosmosItemFeedResponse.getResults());
})
.onErrorResume(throwable ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void testCountByContainer() {
final long prevCount = cosmosTemplate.count(containerName);
assertThat(prevCount).isEqualTo(1);

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);

Expand All @@ -304,7 +304,7 @@ public void testCountByContainer() {
final long newCount = cosmosTemplate.count(containerName);
assertThat(newCount).isEqualTo(2);

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand Down Expand Up @@ -332,7 +332,7 @@ public void testCountByQuery() {
final long countIgnoreCase = cosmosTemplate.count(queryIgnoreCase, containerName);
assertThat(countIgnoreCase).isEqualTo(1);

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand All @@ -351,7 +351,7 @@ public void testFindAllPageableMultiPages() {
assertThat(page1.getContent().size()).isEqualTo(PAGE_SIZE_1);
PageTestUtils.validateNonLastPage(page1, PAGE_SIZE_1);

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);

Expand All @@ -360,7 +360,7 @@ public void testFindAllPageableMultiPages() {
assertThat(page2.getContent().size()).isEqualTo(1);
PageTestUtils.validateLastPage(page2, PAGE_SIZE_1);

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand Down Expand Up @@ -392,7 +392,7 @@ public void testPaginationQuery() {
assertThat(pageIgnoreCase.getContent().size()).isEqualTo(1);
PageTestUtils.validateLastPage(pageIgnoreCase, pageIgnoreCase.getContent().size());

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand All @@ -419,7 +419,7 @@ public void testFindAllWithPageableAndSort() {
assertThat(result.get(1).getFirstName()).isEqualTo(NEW_FIRST_NAME);
assertThat(result.get(2).getFirstName()).isEqualTo(FIRST_NAME);

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);

Expand Down Expand Up @@ -479,7 +479,7 @@ public void testExists() {
final Boolean existsIgnoreCase = cosmosTemplate.exists(queryIgnoreCase, Person.class, containerName);
assertThat(existsIgnoreCase).isTrue();

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void testFindAll() {
Person.class);
StepVerifier.create(flux).expectNextCount(1).verifyComplete();

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand Down Expand Up @@ -331,7 +331,7 @@ public void testDeleteById() {
Flux<Person> flux = cosmosTemplate.findAll(Person.class.getSimpleName(), Person.class);
StepVerifier.create(flux).expectNextCount(2).verifyComplete();

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);

Expand All @@ -348,7 +348,7 @@ public void testDeleteById() {
flux = cosmosTemplate.findAll(Person.class.getSimpleName(), Person.class);
StepVerifier.create(flux).expectNextCount(1).verifyComplete();

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);

Expand Down Expand Up @@ -386,7 +386,7 @@ public void testFind() {
Person.class.getSimpleName());
StepVerifier.create(personFluxIgnoreCase).expectNextCount(1).verifyComplete();

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand All @@ -406,7 +406,7 @@ public void testExists() {
final Mono<Boolean> existsIgnoreCase = cosmosTemplate.exists(queryIgnoreCase, Person.class, containerName);
StepVerifier.create(existsIgnoreCase).expectNext(true).verifyComplete();

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand All @@ -416,7 +416,7 @@ public void testCount() {
final Mono<Long> count = cosmosTemplate.count(containerName);
StepVerifier.create(count).expectNext((long) 1).verifyComplete();

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNull();
assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}
Expand Down

0 comments on commit 8df9e17

Please sign in to comment.