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());
}
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());
}
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());
}
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();
}
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();
}
Aggregations