Search in sources :

Example 26 with NetworkRequestMetric

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

the class FirebasePerfUrlConnectionTest method testOpenStreamHttpConnectionError.

@Test
public void testOpenStreamHttpConnectionError() throws IOException {
    URLWrapper wrapper = mock(URLWrapper.class);
    when(wrapper.toString()).thenReturn("www.google.com");
    when(wrapper.openConnection()).thenThrow(IOException.class);
    try {
        FirebasePerfUrlConnection.openStream(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)

Example 27 with NetworkRequestMetric

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

the class FirebasePerfUrlConnectionTest method testGetContentClasses.

@Test
public void testGetContentClasses() throws IOException {
    @SuppressWarnings("rawtypes") Class[] classes = { TransportManager.class };
    URLWrapper wrapper = mock(URLWrapper.class);
    when(wrapper.toString()).thenReturn("www.google.com");
    when(wrapper.openConnection()).thenThrow(IOException.class);
    try {
        FirebasePerfUrlConnection.getContent(wrapper, classes, 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)

Example 28 with NetworkRequestMetric

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

the class HttpMetricTest method removeAttribute.

@Test
public void removeAttribute() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    metric.putAttribute("attr1", "free");
    Map<String, String> attributes = metric.getAttributes();
    assertThat(attributes.size()).isEqualTo(1);
    metric.removeAttribute("attr1");
    attributes = metric.getAttributes();
    assertThat(attributes.size()).isEqualTo(0);
    metric.stop();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
    NetworkRequestMetric metricValue = networkArgumentCaptor.getValue();
    assertThat(metricValue.getUrl()).isEqualTo("https://www.google.com/");
    assertThat(metricValue.getHttpMethod()).isEqualTo(com.google.firebase.perf.v1.NetworkRequestMetric.HttpMethod.GET);
    assertThat(metricValue.getClientStartTimeUs()).isEqualTo(1000);
    assertThat(metricValue.getTimeToResponseCompletedUs()).isEqualTo(2000);
    assertThat(metricValue.getCustomAttributesCount()).isEqualTo(0);
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 29 with NetworkRequestMetric

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

the class HttpMetricTest method markResponseStart.

@Test
public void markResponseStart() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    metric.markResponseStart();
    metric.stop();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
    NetworkRequestMetric metricValue = networkArgumentCaptor.getValue();
    assertThat(metricValue.getUrl()).isEqualTo("https://www.google.com/");
    assertThat(metricValue.getHttpMethod()).isEqualTo(com.google.firebase.perf.v1.NetworkRequestMetric.HttpMethod.GET);
    assertThat(metricValue.getClientStartTimeUs()).isEqualTo(1000);
    assertThat(metricValue.getTimeToResponseInitiatedUs()).isEqualTo(2000);
    assertThat(metricValue.getTimeToResponseCompletedUs()).isEqualTo(3000);
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 30 with NetworkRequestMetric

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

the class HttpMetricTest method addAttributeWithSameName.

@Test
public void addAttributeWithSameName() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    metric.putAttribute("attr1", "free");
    metric.putAttribute("attr1", "paid");
    metric.stop();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
    NetworkRequestMetric metricValue = networkArgumentCaptor.getValue();
    assertThat(metricValue.getUrl()).isEqualTo("https://www.google.com/");
    assertThat(metricValue.getHttpMethod()).isEqualTo(com.google.firebase.perf.v1.NetworkRequestMetric.HttpMethod.GET);
    assertThat(metricValue.getClientStartTimeUs()).isEqualTo(1000);
    assertThat(metricValue.getTimeToResponseCompletedUs()).isEqualTo(2000);
    assertThat(metricValue.getCustomAttributesCount()).isEqualTo(1);
    assertThat(metricValue.getCustomAttributesMap()).containsEntry("attr1", "paid");
}
Also used : 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