use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class NetworkRequestMetricBuilderTest method testSetRequestEndTimeMicros.
@Test
public void testSetRequestEndTimeMicros() {
long time = 2000;
NetworkRequestMetric metric = networkMetricBuilder.setTimeToRequestCompletedMicros(time).build();
assertThat(metric.getTimeToRequestCompletedUs()).isEqualTo(time);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric 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();
}
use of com.google.firebase.perf.v1.NetworkRequestMetric 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());
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfNetworkValidatorTest method testNullTimeToResponseInitiated.
@Test
public void testNullTimeToResponseInitiated() {
NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
NetworkRequestMetric metric = metricBuilder.build();
assertFalse(metric.hasTimeToResponseInitiatedUs());
FirebasePerfNetworkValidator validator = new FirebasePerfNetworkValidator(metric, ApplicationProvider.getApplicationContext());
assertTrue(validator.isValidPerfMetric());
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class InstrHttpURLConnectionTest method testGetContent.
@Test
public void testGetContent() throws IOException {
HttpURLConnection urlConnection = mockHttpUrlConnection();
when(urlConnection.getDoOutput()).thenReturn(true);
Object fakeObject = new Object();
when(urlConnection.getContent()).thenReturn(fakeObject);
Object retObj = new InstrHttpURLConnection(urlConnection, timer, networkMetricBuilder).getContent();
assertEquals(fakeObject, retObj);
verify(urlConnection).getContent();
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
assertEquals(1000, metric.getClientStartTimeUs());
assertEquals(HttpMethod.POST, metric.getHttpMethod());
assertEquals(urlConnection.getResponseCode(), metric.getHttpResponseCode());
assertEquals(urlConnection.getContentLength(), metric.getResponsePayloadBytes());
assertEquals(urlConnection.getContentType(), metric.getResponseContentType());
assertEquals(2000, metric.getTimeToResponseCompletedUs());
}
Aggregations