Search in sources :

Example 46 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class FirebasePerfNetworkValidatorTest method testNullTimeToRequestCompleted.

@Test
public void testNullTimeToRequestCompleted() {
    NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
    NetworkRequestMetric metric = metricBuilder.build();
    assertFalse(metric.hasTimeToRequestCompletedUs());
    FirebasePerfNetworkValidator validator = new FirebasePerfNetworkValidator(metric, ApplicationProvider.getApplicationContext());
    assertTrue(validator.isValidPerfMetric());
}
Also used : NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) Test(org.junit.Test)

Example 47 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class FirebasePerfHttpClientTest method testExecuteHostRequestContextError.

// go/assertthrows-statements-lsc
@SuppressWarnings("AssertThrowsMultipleStatements")
@Test
public void testExecuteHostRequestContextError() 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)).thenThrow(new IOException());
    assertThrows(IOException.class, () -> {
        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();
    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 48 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class FirebasePerfHttpClientTest method testExecuteRequest.

@Test
public void testExecuteRequest() throws IOException, URISyntaxException {
    HttpClient client = mock(HttpClient.class);
    HttpResponse response = mockHttpResponse();
    HttpUriRequest request = mockHttpUriRequest();
    when(client.execute(request)).thenReturn(response);
    HttpResponse httpResponse = FirebasePerfHttpClient.execute(client, request, timer, transportManager);
    assertSame(httpResponse, response);
    verify(timer).reset();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
    NetworkRequestMetric metric = networkArgumentCaptor.getValue();
    verifyNetworkRequestMetric(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) Test(org.junit.Test)

Example 49 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class FirebasePerfHttpClientTest method testRequestHandlerContextError.

@Test
public void testRequestHandlerContextError() throws IOException, URISyntaxException {
    HttpClient client = mock(HttpClient.class);
    HttpUriRequest request = mockHttpUriRequest();
    HttpContext context = mock(HttpContext.class);
    ResponseHandler<HttpResponse> handler = mock(ResponseHandlerInterface.class);
    when(client.execute(eq(request), ArgumentMatchers.<InstrumentApacheHttpResponseHandler<HttpResponse>>any(), eq(context))).thenThrow(new IOException());
    assertThrows(IOException.class, () -> {
        FirebasePerfHttpClient.execute(client, 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 : 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) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 50 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class FirebasePerfHttpClientTest method testExecuteRequestContextError.

// go/assertthrows-statements-lsc
@SuppressWarnings("AssertThrowsMultipleStatements")
@Test
public void testExecuteRequestContextError() throws IOException, URISyntaxException {
    HttpClient client = mock(HttpClient.class);
    HttpResponse response = mockHttpResponse();
    HttpUriRequest request = mockHttpUriRequest();
    HttpContext context = mock(HttpContext.class);
    when(client.execute(request, context)).thenThrow(new IOException());
    assertThrows(IOException.class, () -> {
        HttpResponse httpResponse = FirebasePerfHttpClient.execute(client, request, context, 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) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) 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