use of com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2Test method uploadFinishedHitsCorrectUrl.
@Test
void uploadFinishedHitsCorrectUrl() throws IOException {
AtomicReference<HttpRequest> requestHolder = new AtomicReference<>();
HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> {
requestHolder.set(request);
return Mono.just(mockResponse(request, 201, "{\"acceptedTime\":\"a-time\",\"blobUri\":\"a-blob-uri\",\"correlationId\":\"a-correlation-id\",\"stampId\":\"a-stamp\"}"));
}).build();
ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URL("http://a-host"), "a-instrumentation-key", httpPipeline);
UUID id = UUID.randomUUID();
ArtifactAcceptedResponse artifactAcceptedResponse = profilerFrontendClientV2.reportUploadFinish(id, "an-etag").block();
HttpRequest request = requestHolder.get();
String url = request.getUrl().toString();
assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(url.contains("/api/apps/a-instrumentation-key/artifactkinds/profile/artifacts/" + id)).isTrue();
assertThat(url.contains("action=commit")).isTrue();
assertThat(artifactAcceptedResponse.getAcceptedTime()).isEqualTo("a-time");
assertThat(artifactAcceptedResponse.getBlobUri()).isEqualTo("a-blob-uri");
assertThat(artifactAcceptedResponse.getCorrelationId()).isEqualTo("a-correlation-id");
assertThat(artifactAcceptedResponse.getStampId()).isEqualTo("a-stamp");
}
use of com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2 method reportUploadFinish.
/**
* Report to Service Profiler that the profile upload has been completed.
*/
@Override
public Mono<ArtifactAcceptedResponse> reportUploadFinish(UUID profileId, String etag) {
URL requestUrl = uploadFinishedRequestUrl(profileId, etag);
return executePostWithRedirect(requestUrl).flatMap(response -> {
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
return Mono.error(new AssertionError("http response mono returned empty"));
}
int statusCode = response.getStatusCode();
if (statusCode != 201 && statusCode != 202) {
LOGGER.error("Trace upload failed: {}", statusCode);
consumeResponseBody(response);
return Mono.error(new AssertionError("http request failed"));
}
return response.getBodyAsString();
}).flatMap(json -> {
if (json == null) {
// this shouldn't happen, the mono should complete with a response or a failure
return Mono.error(new AssertionError("response body mono returned empty"));
}
try {
JsonAdapter<ArtifactAcceptedResponse> builder = new Builder().build().adapter(ArtifactAcceptedResponse.class);
ArtifactAcceptedResponse data = builder.fromJson(json);
if (data == null) {
return Mono.error(new IllegalStateException("Failed to deserialize response"));
}
return Mono.just(data);
} catch (IOException e) {
return Mono.error(new IllegalStateException("Failed to deserialize response", e));
}
});
}
Aggregations