Search in sources :

Example 21 with NetworkRequestMetricBuilder

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

the class FirebasePerfNetworkValidatorTest method testNullResponseCode.

@Test
public void testNullResponseCode() {
    NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
    // Set all the required fields except response code
    metricBuilder.setUrl("https://www.google.com");
    metricBuilder.setHttpMethod("GET");
    metricBuilder.setRequestStartTimeMicros(System.currentTimeMillis() * 1000L);
    metricBuilder.setTimeToResponseCompletedMicros(400L);
    NetworkRequestMetric metric = metricBuilder.build();
    assertFalse(metric.hasHttpResponseCode());
    FirebasePerfNetworkValidator validator = new FirebasePerfNetworkValidator(metric, ApplicationProvider.getApplicationContext());
    assertFalse(validator.isValidPerfMetric());
}
Also used : NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) Test(org.junit.Test)

Example 22 with NetworkRequestMetricBuilder

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

the class FirebasePerfNetworkValidatorTest method testInvalidResponseCode.

@Test
public void testInvalidResponseCode() {
    NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
    metricBuilder.setHttpResponseCode(-2);
    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 23 with NetworkRequestMetricBuilder

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

the class FirebasePerfNetworkValidatorTest method testNullTimeToRequestCompleted.

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

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

the class FirebasePerfNetworkValidatorTest method testNegativeTimeToRequestCompleted.

@Test
public void testNegativeTimeToRequestCompleted() {
    NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
    metricBuilder.setTimeToRequestCompletedMicros(-1L);
    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 25 with NetworkRequestMetricBuilder

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

the class FirebasePerfNetworkValidatorTest method testAbsenceOfHttpMethodFailsValidation.

@Test
public void testAbsenceOfHttpMethodFailsValidation() {
    NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
    // Set all required fields except httpMethod
    metricBuilder.setUrl("https://www.google.com");
    metricBuilder.setHttpResponseCode(200);
    metricBuilder.setRequestStartTimeMicros(System.currentTimeMillis() * 1000L);
    metricBuilder.setTimeToResponseCompletedMicros(400L);
    FirebasePerfNetworkValidator metricValidator = new FirebasePerfNetworkValidator(metricBuilder.build(), ApplicationProvider.getApplicationContext());
    assertThat(metricValidator.isValidPerfMetric()).isFalse();
}
Also used : 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