Search in sources :

Example 21 with NetworkRequestMetric

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);
}
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 22 with NetworkRequestMetric

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);
}
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) Test(org.junit.Test)

Example 23 with NetworkRequestMetric

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);
}
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) IOException(java.io.IOException) Test(org.junit.Test)

Example 24 with NetworkRequestMetric

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");
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) 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 25 with NetworkRequestMetric

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);
    }
}
Also used : NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) IOException(java.io.IOException) URLWrapper(com.google.firebase.perf.util.URLWrapper) 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