Search in sources :

Example 31 with NetworkRequestMetric

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

the class HttpMetricTest method putAttributeAfterHttpMetricIsStopped.

@Test
public void putAttributeAfterHttpMetricIsStopped() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    metric.stop();
    metric.putAttribute("attr1", "free");
    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 32 with NetworkRequestMetric

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

the class HttpMetricTest method testMaxAttributes.

@Test
public void testMaxAttributes() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    for (int i = 0; i <= Constants.MAX_TRACE_CUSTOM_ATTRIBUTES; i++) {
        metric.putAttribute("dim" + i, "value" + i);
    }
    for (int i = 0; i <= Constants.MAX_TRACE_CUSTOM_ATTRIBUTES; i++) {
        metric.putAttribute("dim" + i, "value" + (i + 1));
    }
    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(Constants.MAX_TRACE_CUSTOM_ATTRIBUTES);
    for (int i = 0; i < Constants.MAX_TRACE_CUSTOM_ATTRIBUTES; i++) {
        String attributeValue = "value" + (i + 1);
        String attributeKey = "dim" + i;
        assertThat(metric.getAttribute(attributeKey)).isEqualTo(attributeValue);
    }
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 33 with NetworkRequestMetric

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

the class HttpMetricTest method setResponseContentType.

@Test
public void setResponseContentType() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    metric.setResponseContentType("text/html");
    metric.stop();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
    NetworkRequestMetric metricValue = networkArgumentCaptor.getValue();
    verifyMetric(metricValue);
    assertThat(metricValue.getResponseContentType()).isEqualTo("text/html");
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 34 with NetworkRequestMetric

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

the class NetworkRequestMetricBuilderTest method testSetRequestPayloadBytes.

@Test
public void testSetRequestPayloadBytes() {
    long bytes = 256;
    NetworkRequestMetric metric = networkMetricBuilder.setRequestPayloadBytes(bytes).build();
    assertThat(metric.getRequestPayloadBytes()).isEqualTo(bytes);
}
Also used : NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 35 with NetworkRequestMetric

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

the class NetworkRequestMetricBuilderTest method testSetResponseContentType.

@Test
public void testSetResponseContentType() {
    String contentType = "text/html";
    NetworkRequestMetric metric = networkMetricBuilder.setResponseContentType(contentType).build();
    assertThat(metric.getResponseContentType()).isEqualTo(contentType);
}
Also used : 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