Search in sources :

Example 51 with NetworkRequestMetric

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);
}
Also used : HttpRequest(org.apache.http.HttpRequest) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 52 with NetworkRequestMetric

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);
}
Also used : HttpRequest(org.apache.http.HttpRequest) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 53 with NetworkRequestMetric

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);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) HttpClient(org.apache.http.client.HttpClient) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 54 with NetworkRequestMetric

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");
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

Example 55 with NetworkRequestMetric

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();
}
Also used : NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)81 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)80 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)45 NetworkRequestMetricBuilder (com.google.firebase.perf.metrics.NetworkRequestMetricBuilder)13 IOException (java.io.IOException)13 HttpResponse (org.apache.http.HttpResponse)13 HttpClient (org.apache.http.client.HttpClient)12 HttpURLConnection (java.net.HttpURLConnection)11 PerfMetric (com.google.firebase.perf.v1.PerfMetric)10 HttpHost (org.apache.http.HttpHost)6 HttpRequest (org.apache.http.HttpRequest)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 HttpContext (org.apache.http.protocol.HttpContext)6 HttpUrl (okhttp3.HttpUrl)4 Request (okhttp3.Request)4 RequestBody (okhttp3.RequestBody)4 TransportManager (com.google.firebase.perf.transport.TransportManager)3 URLWrapper (com.google.firebase.perf.util.URLWrapper)3 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)3 Response (okhttp3.Response)3