Search in sources :

Example 66 with NetworkRequestMetric

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

the class NetworkRequestMetricBuilderTest method testSetRequestEndTimeMicros.

@Test
public void testSetRequestEndTimeMicros() {
    long time = 2000;
    NetworkRequestMetric metric = networkMetricBuilder.setTimeToRequestCompletedMicros(time).build();
    assertThat(metric.getTimeToRequestCompletedUs()).isEqualTo(time);
}
Also used : NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 67 with NetworkRequestMetric

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

the class FirebasePerfNetworkValidatorTest method testAbsenceOfHttpResponseCodeFailsValidation.

@Test
public void testAbsenceOfHttpResponseCodeFailsValidation() {
    NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
    // Set all required fields except httpResponseCode
    metricBuilder.setUrl("https://www.google.com");
    metricBuilder.setHttpMethod("GET");
    metricBuilder.setRequestStartTimeMicros(System.currentTimeMillis() * 1000L);
    metricBuilder.setTimeToResponseCompletedMicros(400L);
    NetworkRequestMetric metric = metricBuilder.build();
    assertThat(metric.hasHttpResponseCode()).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 68 with NetworkRequestMetric

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

the class FirebasePerfNetworkValidatorTest method testInvalidContentType.

@Test
public void testInvalidContentType() {
    NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
    // invalid content
    metricBuilder.setResponseContentType("badcontenttype&&&&aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    NetworkRequestMetric metric = metricBuilder.build();
    FirebasePerfNetworkValidator validator = new FirebasePerfNetworkValidator(metric, ApplicationProvider.getApplicationContext());
    assertTrue(validator.isValidPerfMetric());
    assertFalse(metric.hasResponseContentType());
}
Also used : NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) Test(org.junit.Test)

Example 69 with NetworkRequestMetric

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

the class FirebasePerfNetworkValidatorTest method testNullTimeToResponseInitiated.

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

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

the class InstrHttpURLConnectionTest method testGetContent.

@Test
public void testGetContent() throws IOException {
    HttpURLConnection urlConnection = mockHttpUrlConnection();
    when(urlConnection.getDoOutput()).thenReturn(true);
    Object fakeObject = new Object();
    when(urlConnection.getContent()).thenReturn(fakeObject);
    Object retObj = new InstrHttpURLConnection(urlConnection, timer, networkMetricBuilder).getContent();
    assertEquals(fakeObject, retObj);
    verify(urlConnection).getContent();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
    NetworkRequestMetric metric = networkArgumentCaptor.getValue();
    assertEquals(1000, metric.getClientStartTimeUs());
    assertEquals(HttpMethod.POST, metric.getHttpMethod());
    assertEquals(urlConnection.getResponseCode(), metric.getHttpResponseCode());
    assertEquals(urlConnection.getContentLength(), metric.getResponsePayloadBytes());
    assertEquals(urlConnection.getContentType(), metric.getResponseContentType());
    assertEquals(2000, metric.getTimeToResponseCompletedUs());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) 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