use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfNetworkValidatorTest method testRequestPayloadBytes.
@Test
public void testRequestPayloadBytes() {
NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
metricBuilder.setRequestPayloadBytes(-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 testClientStartTimeUs.
@Test
public void testClientStartTimeUs() {
NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
// Set all required fields except clientStartTimeUs
metricBuilder.setUrl("https://www.google.com");
metricBuilder.setHttpMethod("GET");
metricBuilder.setHttpResponseCode(200);
metricBuilder.setTimeToResponseCompletedMicros(400L);
assertFalse(metricBuilder.build().hasClientStartTimeUs());
assertFalse(new FirebasePerfNetworkValidator(metricBuilder.build(), ApplicationProvider.getApplicationContext()).isValidPerfMetric());
metricBuilder.setRequestStartTimeMicros(0L);
assertFalse(new FirebasePerfNetworkValidator(metricBuilder.build(), ApplicationProvider.getApplicationContext()).isValidPerfMetric());
metricBuilder.setRequestStartTimeMicros(-1L);
assertFalse(new FirebasePerfNetworkValidator(metricBuilder.build(), ApplicationProvider.getApplicationContext()).isValidPerfMetric());
metricBuilder.setRequestStartTimeMicros(System.currentTimeMillis() * 1000L);
assertTrue(new FirebasePerfNetworkValidator(metricBuilder.build(), ApplicationProvider.getApplicationContext()).isValidPerfMetric());
}
use of com.google.firebase.perf.metrics.NetworkRequestMetricBuilder 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.metrics.NetworkRequestMetricBuilder in project firebase-android-sdk by firebase.
the class FirebasePerfOkHttpClientTest method testSendMetricWithQueryURL.
@Test
public void testSendMetricWithQueryURL() throws IOException {
long startTimeMicros = 1;
long responseCompletedTimeMicros = 25;
String requestStr = "dummyrequest";
HttpUrl url = new HttpUrl.Builder().scheme("https").host("www.google.com").query("?").build();
RequestBody requestBody = RequestBody.create(MediaType.parse("text/html"), requestStr);
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 testNullRequestPayloadBytes.
@Test
public void testNullRequestPayloadBytes() {
NetworkRequestMetricBuilder metricBuilder = createNetworkRequestMetricBuilderWithRequiredValuesPresent();
NetworkRequestMetric metric = metricBuilder.build();
assertFalse(metric.hasRequestPayloadBytes());
FirebasePerfNetworkValidator validator = new FirebasePerfNetworkValidator(metric, ApplicationProvider.getApplicationContext());
assertTrue(validator.isValidPerfMetric());
}
Aggregations