use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfOkHttpClientTest method testSendMetric.
@Test
public void testSendMetric() throws IOException {
long startTimeMicros = 1;
long responseCompletedTimeMicros = 25;
String requestStr = "dummyrequest";
RequestBody requestBody = RequestBody.create(MediaType.parse("text/html"), requestStr);
HttpUrl url = new HttpUrl.Builder().scheme("https").host("www.google.com").build();
Request request = new Request.Builder().url(url).method("POST", requestBody).build();
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
ResponseBody responseBody = ResponseBody.create(MediaType.parse("text/html"), "dummyresponse");
Response response = new Response.Builder().code(300).message("").sentRequestAtMillis(startTimeMicros).receivedResponseAtMillis(responseCompletedTimeMicros).body(responseBody).request(request).protocol(Protocol.HTTP_2).addHeader("Content-Type", "text/html").build();
FirebasePerfOkHttpClient.sendNetworkMetric(response, builder, startTimeMicros, responseCompletedTimeMicros);
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
assertThat(metric.getUrl()).isEqualTo("https://www.google.com/");
assertThat(metric.getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(metric.getRequestPayloadBytes()).isEqualTo(requestStr.length());
assertThat(metric.getResponsePayloadBytes()).isEqualTo("dummyresponse".length());
assertThat(metric.getHttpResponseCode()).isEqualTo(300);
assertThat(metric.getClientStartTimeUs()).isEqualTo(startTimeMicros);
assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(responseCompletedTimeMicros);
assertThat(metric.getResponseContentType()).isEqualTo("text/html; charset=utf-8");
}
use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfNetworkValidatorTest method testInvalidUrl.
@Test
public void testInvalidUrl() {
NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
metricBuilder.setUrl("badurl{??//..}");
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 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.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfNetworkValidatorTest method testEmptyUrl.
@Test
public void testEmptyUrl() {
NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
metricBuilder.setUrl("");
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 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());
}
Aggregations