Search in sources :

Example 16 with NetworkRequestMetricBuilder

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

the class FirebasePerfNetworkValidatorTest method testInvalidResponsePayloadBytes.

@Test
public void testInvalidResponsePayloadBytes() {
    NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
    metricBuilder.setResponsePayloadBytes(-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 17 with NetworkRequestMetricBuilder

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

the class FirebasePerfNetworkValidatorTest method testNullContentType.

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

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

the class AppStateMonitorTest method testAppStateCallbackWithNetworkRequestMetricBuilder.

@Test
public void testAppStateCallbackWithNetworkRequestMetricBuilder() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    // registerForAppState() is called by NetworkRequestMetricBuilder's constructor.
    NetworkRequestMetricBuilder builder = new NetworkRequestMetricBuilder(mock(TransportManager.class), monitor, mock(GaugeManager.class));
    Assert.assertEquals(ApplicationProcessState.BACKGROUND, builder.getAppState());
    // activity1 comes to foreground.
    currentTime = 1;
    monitor.onActivityResumed(activity1);
    Assert.assertTrue(monitor.isForeground());
    // builder is updated through AppStateCallback.
    Assert.assertEquals(FOREGROUND_BACKGROUND, builder.getAppState());
    verify(transportManager, times(0)).log(argTraceMetric.capture(), nullable(ApplicationProcessState.class));
    // activity1 goes to background.
    currentTime = 2;
    monitor.onActivityStopped(activity1);
    Assert.assertFalse(monitor.isForeground());
    // Foreground session trace.
    verify(transportManager, times(1)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
    // builder is updated again.
    Assert.assertEquals(FOREGROUND_BACKGROUND, builder.getAppState());
    // unregisterForAppState() is called by NetworkRequestMetricBuilder.build().
    builder.build();
    Assert.assertEquals(FOREGROUND_BACKGROUND, builder.getAppState());
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) GaugeManager(com.google.firebase.perf.session.gauges.GaugeManager) TransportManager(com.google.firebase.perf.transport.TransportManager) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) Test(org.junit.Test)

Example 19 with NetworkRequestMetricBuilder

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

the class FirebasePerfNetworkValidatorTest method testAbsenceOfUrlFailsValidation.

// The following tests validate that the absence of required fields in the proto result in failed
// validation.
// The required fields are: url, httpMethod, httpResponseCode, clientStartTimeUs, and
// timeToResponseInitiatedUs.
@Test
public void testAbsenceOfUrlFailsValidation() {
    NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
    // Set all required fields except url
    metricBuilder.setHttpMethod("GET");
    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)

Example 20 with NetworkRequestMetricBuilder

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

the class FirebasePerfNetworkValidatorTest method testAbsenceOfClientStartTimeUsFailsValidation.

@Test
public void testAbsenceOfClientStartTimeUsFailsValidation() {
    NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
    // Set all required fields except httpResponseCode
    metricBuilder.setUrl("https://www.google.com");
    metricBuilder.setHttpMethod("GET");
    metricBuilder.setHttpResponseCode(200);
    metricBuilder.setTimeToResponseCompletedMicros(400L);
    NetworkRequestMetric metric = metricBuilder.build();
    assertThat(metric.hasClientStartTimeUs()).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)

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