Search in sources :

Example 56 with NetworkRequestMetric

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

the class HttpMetricTest method setResponseSize.

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

Example 57 with NetworkRequestMetric

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

the class HttpMetricTest method putAttribute.

@Test
public void putAttribute() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    metric.putAttribute("attr1", "free");
    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", "free");
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 58 with NetworkRequestMetric

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

the class HttpMetricTest method markRequestComplete.

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

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

the class HttpMetricTest method removeAttributeAfterStopped.

@Test
public void removeAttributeAfterStopped() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    metric.putAttribute("attr1", "free");
    metric.stop();
    metric.removeAttribute("attr1");
    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", "free");
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 60 with NetworkRequestMetric

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

the class HttpMetricTest method setHttpResponseCode.

@Test
public void setHttpResponseCode() {
    HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
    metric.start();
    metric.setHttpResponseCode(200);
    metric.stop();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
    NetworkRequestMetric metricValue = networkArgumentCaptor.getValue();
    verifyMetric(metricValue);
    assertThat(metricValue.getHttpResponseCode()).isEqualTo(200);
}
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