use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class HttpMetricTest method testMoreThanMaxAttributes.
@Test
public void testMoreThanMaxAttributes() {
HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
metric.start();
for (int i = 0; i <= Constants.MAX_TRACE_CUSTOM_ATTRIBUTES; i++) {
metric.putAttribute("dim" + i, "value" + i);
}
metric.stop();
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
NetworkRequestMetric metricValue = networkArgumentCaptor.getValue();
assertThat(metricValue.getUrl()).isEqualTo("https://www.google.com/");
assertThat(metricValue.getHttpMethod()).isEqualTo(com.google.firebase.perf.v1.NetworkRequestMetric.HttpMethod.GET);
assertThat(metricValue.getClientStartTimeUs()).isEqualTo(1000);
assertThat(metricValue.getTimeToResponseCompletedUs()).isEqualTo(2000);
assertThat(metricValue.getCustomAttributesCount()).isEqualTo(Constants.MAX_TRACE_CUSTOM_ATTRIBUTES);
for (int i = 0; i < Constants.MAX_TRACE_CUSTOM_ATTRIBUTES; i++) {
String attributeValue = "value" + i;
String attributeKey = "dim" + i;
assertThat(metric.getAttribute(attributeKey)).isEqualTo(attributeValue);
}
assertThat(metricValue.getCustomAttributesMap()).doesNotContainKey("attr6");
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class HttpMetricTest method setRequestSize.
@Test
public void setRequestSize() {
HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
metric.start();
metric.setRequestPayloadSize(256);
metric.stop();
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
NetworkRequestMetric metricValue = networkArgumentCaptor.getValue();
verifyMetric(metricValue);
assertThat(metricValue.getRequestPayloadBytes()).isEqualTo(256);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class HttpMetricTest method putInvalidAttribute.
@Test
public void putInvalidAttribute() {
HttpMetric metric = new HttpMetric("https://www.google.com/", HttpMethod.GET, transportManager, timer);
metric.start();
metric.putAttribute("_invalidattr1", "free");
metric.stop();
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
NetworkRequestMetric metricValue = networkArgumentCaptor.getValue();
assertThat(metricValue.getUrl()).isEqualTo("https://www.google.com/");
assertThat(metricValue.getHttpMethod()).isEqualTo(com.google.firebase.perf.v1.NetworkRequestMetric.HttpMethod.GET);
assertThat(metricValue.getClientStartTimeUs()).isEqualTo(1000);
assertThat(metricValue.getTimeToResponseCompletedUs()).isEqualTo(2000);
assertThat(metricValue.getCustomAttributesCount()).isEqualTo(0);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric 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();
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class FirebasePerfNetworkValidatorTest method testNullResponseCode.
@Test
public void testNullResponseCode() {
NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(TransportManager.getInstance());
// Set all the required fields except response code
metricBuilder.setUrl("https://www.google.com");
metricBuilder.setHttpMethod("GET");
metricBuilder.setRequestStartTimeMicros(System.currentTimeMillis() * 1000L);
metricBuilder.setTimeToResponseCompletedMicros(400L);
NetworkRequestMetric metric = metricBuilder.build();
assertFalse(metric.hasHttpResponseCode());
FirebasePerfNetworkValidator validator = new FirebasePerfNetworkValidator(metric, ApplicationProvider.getApplicationContext());
assertFalse(validator.isValidPerfMetric());
}
Aggregations