use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfHttpClientTest method testExecuteHostRequest.
@Test
public void testExecuteHostRequest() throws IOException, URISyntaxException {
HttpClient client = mock(HttpClient.class);
HttpResponse response = mockHttpResponse();
HttpRequest request = mockHttpRequest();
HttpHost host = mockHttpHost();
when(client.execute(host, request)).thenReturn(response);
HttpResponse httpResponse = FirebasePerfHttpClient.execute(client, host, request, timer, transportManager);
assertSame(httpResponse, response);
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
verify(timer).reset();
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
verifyNetworkRequestMetric(metric);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfHttpClientTest method testHostRequestHandlerContextError.
@Test
public void testHostRequestHandlerContextError() throws IOException, URISyntaxException {
HttpClient client = mock(HttpClient.class);
HttpRequest request = mockHttpRequest();
HttpHost host = mockHttpHost();
HttpContext context = mock(HttpContext.class);
ResponseHandler<HttpResponse> handler = mock(ResponseHandlerInterface.class);
when(client.execute(eq(host), eq(request), ArgumentMatchers.<InstrumentApacheHttpResponseHandler<HttpResponse>>any(), eq(context))).thenThrow(new IOException());
assertThrows(IOException.class, () -> {
FirebasePerfHttpClient.execute(client, host, request, handler, context, timer, transportManager);
});
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
verify(timer).reset();
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
verifyNetworkRequestMetricWithError(metric);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfHttpClientTest method testRequestHandlerError.
@Test
public void testRequestHandlerError() throws IOException, URISyntaxException {
HttpClient client = mock(HttpClient.class);
HttpUriRequest request = mockHttpUriRequest();
ResponseHandler<HttpResponse> handler = mock(ResponseHandlerInterface.class);
when(client.execute(eq(request), ArgumentMatchers.<InstrumentApacheHttpResponseHandler<HttpResponse>>any())).thenThrow(new IOException());
assertThrows(IOException.class, () -> {
FirebasePerfHttpClient.execute(client, request, handler, timer, transportManager);
});
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
verify(timer).reset();
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
verifyNetworkRequestMetricWithError(metric);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfOkHttpClientTest method testSendMetric.
@Test
public void testSendMetric() throws IOException {
long startTimeMicros = 1;
long responseCompletedTimeMicros = 25;
String requestStr = "dummyrequest";
RequestBody requestBody = RequestBody.create(MediaType.parse("text/html"), requestStr);
HttpUrl url = new HttpUrl.Builder().scheme("https").host("www.google.com").build();
Request request = new Request.Builder().url(url).method("POST", requestBody).build();
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
ResponseBody responseBody = ResponseBody.create(MediaType.parse("text/html"), "dummyresponse");
Response response = new Response.Builder().code(300).message("").sentRequestAtMillis(startTimeMicros).receivedResponseAtMillis(responseCompletedTimeMicros).body(responseBody).request(request).protocol(Protocol.HTTP_2).addHeader("Content-Type", "text/html").build();
FirebasePerfOkHttpClient.sendNetworkMetric(response, builder, startTimeMicros, responseCompletedTimeMicros);
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
assertThat(metric.getUrl()).isEqualTo("https://www.google.com/");
assertThat(metric.getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(metric.getRequestPayloadBytes()).isEqualTo(requestStr.length());
assertThat(metric.getResponsePayloadBytes()).isEqualTo("dummyresponse".length());
assertThat(metric.getHttpResponseCode()).isEqualTo(300);
assertThat(metric.getClientStartTimeUs()).isEqualTo(startTimeMicros);
assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(responseCompletedTimeMicros);
assertThat(metric.getResponseContentType()).isEqualTo("text/html; charset=utf-8");
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class InstrHttpOutputStreamTest method testClose.
@Test
public void testClose() throws IOException {
new InstrHttpOutputStream(outputStream, networkMetricBuilder, timer).close();
NetworkRequestMetric metric = networkMetricBuilder.build();
assertThat(metric.getTimeToRequestCompletedUs()).isEqualTo(2000);
verify(outputStream).close();
}
Aggregations