use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfHttpClientTest method testExecuteRequestError.
// go/assertthrows-statements-lsc
@SuppressWarnings("AssertThrowsMultipleStatements")
@Test
public void testExecuteRequestError() throws IOException, URISyntaxException {
HttpClient client = mock(HttpClient.class);
HttpResponse response = mockHttpResponse();
HttpUriRequest request = mockHttpUriRequest();
when(client.execute(request)).thenThrow(new IOException());
assertThrows(IOException.class, () -> {
HttpResponse httpResponse = FirebasePerfHttpClient.execute(client, request, timer, transportManager);
assertSame(httpResponse, response);
});
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 testExecuteHostRequestContext.
@Test
public void testExecuteHostRequestContext() throws IOException, URISyntaxException {
HttpClient client = mock(HttpClient.class);
HttpResponse response = mockHttpResponse();
HttpRequest request = mockHttpRequest();
HttpContext c = mock(HttpContext.class);
HttpHost host = mockHttpHost();
when(client.execute(host, request, c)).thenReturn(response);
HttpResponse httpResponse = FirebasePerfHttpClient.execute(client, host, request, c, 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 testExecuteHostRequestError.
// go/assertthrows-statements-lsc
@SuppressWarnings("AssertThrowsMultipleStatements")
@Test
public void testExecuteHostRequestError() throws IOException, URISyntaxException {
HttpClient client = mock(HttpClient.class);
HttpResponse response = mockHttpResponse();
HttpRequest request = mockHttpRequest();
HttpHost host = mockHttpHost();
when(client.execute(host, request)).thenThrow(new IOException());
assertThrows(IOException.class, () -> {
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();
verifyNetworkRequestMetricWithError(metric);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfOkHttpClientTest method testSendMetricWithQueryURL.
@Test
public void testSendMetricWithQueryURL() throws IOException {
long startTimeMicros = 1;
long responseCompletedTimeMicros = 25;
String requestStr = "dummyrequest";
HttpUrl url = new HttpUrl.Builder().scheme("https").host("www.google.com").query("?").build();
RequestBody requestBody = RequestBody.create(MediaType.parse("text/html"), requestStr);
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 FirebasePerfUrlConnectionTest method testGetContentError.
@Test
public void testGetContentError() throws IOException {
URLWrapper wrapper = mock(URLWrapper.class);
when(wrapper.toString()).thenReturn("www.google.com");
when(wrapper.openConnection()).thenThrow(IOException.class);
try {
FirebasePerfUrlConnection.getContent(wrapper, transportManager, timer);
fail("expected IOException");
} catch (IOException e) {
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
verifyNetworkRequestMetric(metric);
}
}
Aggregations