Search in sources :

Example 16 with NetworkRequestMetric

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

the class TransportManagerTest method logNetworkMetric_globalCustomAttributesAreAdded.

@Test
public void logNetworkMetric_globalCustomAttributesAreAdded() {
    FirebasePerformance.getInstance().putAttribute("test_key1", "test_value1");
    FirebasePerformance.getInstance().putAttribute("test_key2", "test_value2");
    NetworkRequestMetric validNetworkRequest = createValidNetworkRequestMetric();
    testTransportManager.log(validNetworkRequest);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getNetworkRequestMetric()).isEqualTo(validNetworkRequest);
    validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
    Map<String, String> globalCustomAttributes = loggedPerfMetric.getApplicationInfo().getCustomAttributesMap();
    assertThat(globalCustomAttributes).hasSize(2);
    assertThat(globalCustomAttributes).containsEntry("test_key1", "test_value1");
    assertThat(globalCustomAttributes).containsEntry("test_key2", "test_value2");
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 17 with NetworkRequestMetric

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

the class FirebasePerfNetworkValidatorTest method testNullResponsePayloadBytes.

@Test
public void testNullResponsePayloadBytes() {
    NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
    NetworkRequestMetric metric = metricBuilder.build();
    assertFalse(metric.hasResponsePayloadBytes());
    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 18 with NetworkRequestMetric

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

the class FirebasePerfNetworkValidatorTest method testAbsenceOfTimeToResponseCompletedUsFailsValidation.

@Test
public void testAbsenceOfTimeToResponseCompletedUsFailsValidation() {
    NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
    // Set all required fields except timeToResponseCompletedUs
    metricBuilder.setUrl("https://www.google.com");
    metricBuilder.setHttpMethod("GET");
    metricBuilder.setHttpResponseCode(200);
    metricBuilder.setRequestStartTimeMicros(System.currentTimeMillis() * 1000L);
    NetworkRequestMetric metric = metricBuilder.build();
    assertThat(metric.hasTimeToResponseCompletedUs()).isFalse();
    FirebasePerfNetworkValidator metricValidator = new FirebasePerfNetworkValidator(metric, ApplicationProvider.getApplicationContext());
    assertThat(metricValidator.isValidPerfMetric()).isFalse();
}
Also used : NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) Test(org.junit.Test)

Example 19 with NetworkRequestMetric

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

the class FirebasePerfHttpClientTest method testHostRequestHandlerError.

@Test
public void testHostRequestHandlerError() throws IOException, URISyntaxException {
    HttpClient client = mock(HttpClient.class);
    HttpRequest request = mockHttpRequest();
    HttpHost host = mockHttpHost();
    ResponseHandler<HttpResponse> handler = mock(ResponseHandlerInterface.class);
    when(client.execute(eq(host), eq(request), ArgumentMatchers.<InstrumentApacheHttpResponseHandler<HttpResponse>>any())).thenThrow(new IOException());
    assertThrows(IOException.class, () -> {
        FirebasePerfHttpClient.execute(client, host, request, handler, 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) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with NetworkRequestMetric

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

the class FirebasePerfHttpClientTest method testExecuteRequestContext.

@Test
public void testExecuteRequestContext() throws IOException, URISyntaxException {
    HttpClient client = mock(HttpClient.class);
    HttpResponse response = mockHttpResponse();
    HttpUriRequest request = mockHttpUriRequest();
    HttpContext context = mock(HttpContext.class);
    when(client.execute(request, context)).thenReturn(response);
    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();
    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) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) 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