use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class TransportManagerTest method logNetworkMetric_globalCustomAttributesAreAdded.
@Test
public void logNetworkMetric_globalCustomAttributesAreAdded() {
FirebasePerformance.getInstance().putAttribute("test_key1", "test_value1");
FirebasePerformance.getInstance().putAttribute("test_key2", "test_value2");
NetworkRequestMetric validNetworkRequest = createValidNetworkRequestMetric();
testTransportManager.log(validNetworkRequest);
fakeExecutorService.runAll();
PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
assertThat(loggedPerfMetric.getNetworkRequestMetric()).isEqualTo(validNetworkRequest);
validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
Map<String, String> globalCustomAttributes = loggedPerfMetric.getApplicationInfo().getCustomAttributesMap();
assertThat(globalCustomAttributes).hasSize(2);
assertThat(globalCustomAttributes).containsEntry("test_key1", "test_value1");
assertThat(globalCustomAttributes).containsEntry("test_key2", "test_value2");
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfNetworkValidatorTest method testNullResponsePayloadBytes.
@Test
public void testNullResponsePayloadBytes() {
NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
NetworkRequestMetric metric = metricBuilder.build();
assertFalse(metric.hasResponsePayloadBytes());
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 FirebasePerfNetworkValidatorTest method testAbsenceOfTimeToResponseCompletedUsFailsValidation.
@Test
public void testAbsenceOfTimeToResponseCompletedUsFailsValidation() {
NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
// Set all required fields except timeToResponseCompletedUs
metricBuilder.setUrl("https://www.google.com");
metricBuilder.setHttpMethod("GET");
metricBuilder.setHttpResponseCode(200);
metricBuilder.setRequestStartTimeMicros(System.currentTimeMillis() * 1000L);
NetworkRequestMetric metric = metricBuilder.build();
assertThat(metric.hasTimeToResponseCompletedUs()).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 FirebasePerfHttpClientTest method testHostRequestHandlerError.
@Test
public void testHostRequestHandlerError() throws IOException, URISyntaxException {
HttpClient client = mock(HttpClient.class);
HttpRequest request = mockHttpRequest();
HttpHost host = mockHttpHost();
ResponseHandler<HttpResponse> handler = mock(ResponseHandlerInterface.class);
when(client.execute(eq(host), eq(request), ArgumentMatchers.<InstrumentApacheHttpResponseHandler<HttpResponse>>any())).thenThrow(new IOException());
assertThrows(IOException.class, () -> {
FirebasePerfHttpClient.execute(client, host, request, handler, timer, transportManager);
});
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
verify(timer).reset();
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
verifyNetworkRequestMetricWithError(metric);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfHttpClientTest method testExecuteRequestContext.
@Test
public void testExecuteRequestContext() throws IOException, URISyntaxException {
HttpClient client = mock(HttpClient.class);
HttpResponse response = mockHttpResponse();
HttpUriRequest request = mockHttpUriRequest();
HttpContext context = mock(HttpContext.class);
when(client.execute(request, context)).thenReturn(response);
HttpResponse httpResponse = FirebasePerfHttpClient.execute(client, request, context, timer, transportManager);
assertSame(httpResponse, response);
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
verify(timer).reset();
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
verifyNetworkRequestMetric(metric);
}
Aggregations