Search in sources :

Example 26 with NetworkRequestMetricBuilder

use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.

the class FirebasePerfOkHttpClientTest method testSendMetric.

@Test
public void testSendMetric() throws IOException {
    long startTimeMicros = 1;
    long responseCompletedTimeMicros = 25;
    String requestStr = "dummyrequest";
    RequestBody requestBody = RequestBody.create(MediaType.parse("text/html"), requestStr);
    HttpUrl url = new HttpUrl.Builder().scheme("https").host("www.google.com").build();
    Request request = new Request.Builder().url(url).method("POST", requestBody).build();
    NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
    ResponseBody responseBody = ResponseBody.create(MediaType.parse("text/html"), "dummyresponse");
    Response response = new Response.Builder().code(300).message("").sentRequestAtMillis(startTimeMicros).receivedResponseAtMillis(responseCompletedTimeMicros).body(responseBody).request(request).protocol(Protocol.HTTP_2).addHeader("Content-Type", "text/html").build();
    FirebasePerfOkHttpClient.sendNetworkMetric(response, builder, startTimeMicros, responseCompletedTimeMicros);
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
    NetworkRequestMetric metric = networkArgumentCaptor.getValue();
    assertThat(metric.getUrl()).isEqualTo("https://www.google.com/");
    assertThat(metric.getHttpMethod()).isEqualTo(HttpMethod.POST);
    assertThat(metric.getRequestPayloadBytes()).isEqualTo(requestStr.length());
    assertThat(metric.getResponsePayloadBytes()).isEqualTo("dummyresponse".length());
    assertThat(metric.getHttpResponseCode()).isEqualTo(300);
    assertThat(metric.getClientStartTimeUs()).isEqualTo(startTimeMicros);
    assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(responseCompletedTimeMicros);
    assertThat(metric.getResponseContentType()).isEqualTo("text/html; charset=utf-8");
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

Example 27 with NetworkRequestMetricBuilder

use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.

the class FirebasePerfNetworkValidatorTest method testInvalidUrl.

@Test
public void testInvalidUrl() {
    NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
    metricBuilder.setUrl("badurl{??//..}");
    FirebasePerfNetworkValidator validator = new FirebasePerfNetworkValidator(metricBuilder.build(), ApplicationProvider.getApplicationContext());
    assertFalse(validator.isValidPerfMetric());
}
Also used : NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) Test(org.junit.Test)

Example 28 with NetworkRequestMetricBuilder

use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder 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 29 with NetworkRequestMetricBuilder

use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.

the class FirebasePerfNetworkValidatorTest method testEmptyUrl.

@Test
public void testEmptyUrl() {
    NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
    metricBuilder.setUrl("");
    FirebasePerfNetworkValidator validator = new FirebasePerfNetworkValidator(metricBuilder.build(), ApplicationProvider.getApplicationContext());
    assertFalse(validator.isValidPerfMetric());
}
Also used : NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) Test(org.junit.Test)

Example 30 with NetworkRequestMetricBuilder

use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder 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)

Aggregations

NetworkRequestMetricBuilder (com.google.firebase.perf.metrics.NetworkRequestMetricBuilder)40 Test (org.junit.Test)27 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)13 IOException (java.io.IOException)12 HttpResponse (org.apache.http.HttpResponse)5 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)4 HttpURLConnection (java.net.HttpURLConnection)3 URLConnection (java.net.URLConnection)3 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)3 HttpUrl (okhttp3.HttpUrl)3 Request (okhttp3.Request)3 Response (okhttp3.Response)3 TransportManager (com.google.firebase.perf.transport.TransportManager)2 RequestBody (okhttp3.RequestBody)2 ResponseBody (okhttp3.ResponseBody)2 Keep (androidx.annotation.Keep)1 GaugeManager (com.google.firebase.perf.session.gauges.GaugeManager)1 Timer (com.google.firebase.perf.util.Timer)1 ResponseHandler (org.apache.http.client.ResponseHandler)1