use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class InstrURLConnectionBaseTest method testGetContentClassesThrowsIOException.
@Test
public void testGetContentClassesThrowsIOException() throws IOException {
HttpURLConnection urlConnection = mockHttpUrlConnection();
when(urlConnection.getDoOutput()).thenReturn(true);
@SuppressWarnings("rawtypes") Class[] classes = { TransportManager.class };
doThrow(IOException.class).when(urlConnection).getContent(classes);
assertThrows(IOException.class, () -> new InstrURLConnectionBase(urlConnection, timer, networkMetricBuilder).getContent(classes));
verify(urlConnection).getContent(classes);
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(2000);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class InstrURLConnectionBaseTest method testGetOutputStreamThrowsIOException.
@Test
public void testGetOutputStreamThrowsIOException() throws IOException {
HttpURLConnection urlConnection = mockHttpUrlConnection();
doThrow(IOException.class).when(urlConnection).getOutputStream();
assertThrows(IOException.class, () -> new InstrURLConnectionBase(urlConnection, timer, networkMetricBuilder).getOutputStream());
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(2000);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class InstrURLConnectionBaseTest method testGetResponseCodeThrowsIOException.
@Test
public void testGetResponseCodeThrowsIOException() throws IOException {
HttpURLConnection urlConnection = mockHttpUrlConnection();
doThrow(IOException.class).when(urlConnection).getResponseCode();
assertThrows(IOException.class, () -> new InstrURLConnectionBase(urlConnection, timer, networkMetricBuilder).getResponseCode());
verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
NetworkRequestMetric metric = networkArgumentCaptor.getValue();
assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(2000);
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class InstrumentOkHttpEnqueueCallbackTest method testOnResponse.
@Test
public void testOnResponse() throws IOException {
String urlStr = "www.google.com";
String scheme = "https";
String fullUrlStr = "https://www.google.com/";
String method = "POST";
long requestContentLength = 240;
long responseContentLength = 353;
int responseCode = 300;
String message = "";
long startTimeMicros = 1;
HttpUrl url = new HttpUrl.Builder().scheme(scheme).host(urlStr).build();
RequestBody requestBody = mock(RequestBody.class);
when(requestBody.contentLength()).thenReturn(requestContentLength);
Request request = new Request.Builder().url(url).method(method, requestBody).build();
ResponseBody responseBody = mock(ResponseBody.class);
when(responseBody.contentLength()).thenReturn(responseContentLength);
Response response = new Response.Builder().code(responseCode).message(message).body(responseBody).request(request).protocol(Protocol.HTTP_2).build();
TransportManager transportManager = mock(TransportManager.class);
Callback callback = mock(Callback.class);
Call call = mock(Call.class);
InstrumentOkHttpEnqueueCallback enqueueCallback = new InstrumentOkHttpEnqueueCallback(callback, transportManager, mockTimer(), startTimeMicros);
enqueueCallback.onResponse(call, response);
ArgumentCaptor<NetworkRequestMetric> argument = ArgumentCaptor.forClass(NetworkRequestMetric.class);
verify(transportManager).log(argument.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
verify(callback).onResponse(call, response);
NetworkRequestMetric metric = argument.getValue();
assertEquals(fullUrlStr, metric.getUrl());
assertEquals(HttpMethod.POST, metric.getHttpMethod());
assertEquals(requestContentLength, metric.getRequestPayloadBytes());
assertEquals(responseContentLength, metric.getResponsePayloadBytes());
assertEquals(responseCode, metric.getHttpResponseCode());
assertEquals(startTimeMicros, metric.getClientStartTimeUs());
assertEquals(2000, metric.getTimeToResponseCompletedUs());
}
use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.
the class InstrumentOkHttpEnqueueCallbackTest method testOnFailure.
@Test
public void testOnFailure() throws IOException {
String urlStr = "www.google.com";
String scheme = "https";
String fullUrlStr = "https://www.google.com/";
String method = "POST";
HttpUrl url = new HttpUrl.Builder().scheme(scheme).host(urlStr).build();
RequestBody requestBody = mock(RequestBody.class);
TransportManager transportManager = mock(TransportManager.class);
Callback callback = mock(Callback.class);
Call call = mock(Call.class);
Request request = new Request.Builder().url(url).method(method, requestBody).build();
when(call.request()).thenReturn(request);
IOException e = new IOException();
long startTime = 1;
InstrumentOkHttpEnqueueCallback enqueueCallback = new InstrumentOkHttpEnqueueCallback(callback, transportManager, mockTimer(), startTime);
enqueueCallback.onFailure(call, e);
ArgumentCaptor<NetworkRequestMetric> argument = ArgumentCaptor.forClass(NetworkRequestMetric.class);
verify(transportManager).log(argument.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
verify(callback).onFailure(call, e);
NetworkRequestMetric metric = argument.getValue();
assertEquals(fullUrlStr, metric.getUrl());
assertEquals(HttpMethod.POST, metric.getHttpMethod());
assertEquals(NetworkClientErrorReason.GENERIC_CLIENT_ERROR, metric.getNetworkClientErrorReason());
assertEquals(startTime, metric.getClientStartTimeUs());
assertEquals(2000, metric.getTimeToResponseCompletedUs());
}
Aggregations