Search in sources :

Example 71 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class InstrHttpURLConnectionTest method testDisconnect.

@Test
public void testDisconnect() throws IOException {
    HttpURLConnection urlConnection = mockHttpUrlConnection();
    new InstrHttpURLConnection(urlConnection, timer, networkMetricBuilder).disconnect();
    verify(urlConnection).disconnect();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
    NetworkRequestMetric metric = networkArgumentCaptor.getValue();
    assertEquals(2000, metric.getTimeToResponseCompletedUs());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 72 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class InstrHttpURLConnectionTest method testGetContentIOException.

@SuppressWarnings("TestExceptionChecker")
@Test(expected = IOException.class)
public void testGetContentIOException() throws IOException {
    HttpURLConnection urlConnection = mockHttpUrlConnection();
    when(urlConnection.getDoOutput()).thenReturn(true);
    when(urlConnection.getContent()).thenThrow(new IOException());
    new InstrHttpURLConnection(urlConnection, timer, networkMetricBuilder).getContent();
    verify(urlConnection).getContent();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
    NetworkRequestMetric metric = networkArgumentCaptor.getValue();
    assertEquals(1000, metric.getClientStartTimeUs());
    assertEquals(HttpMethod.POST, metric.getHttpMethod());
    assertEquals(urlConnection.getResponseCode(), metric.getHttpResponseCode());
    assertEquals(urlConnection.getContentLength(), null);
    assertEquals(urlConnection.getContentType(), null);
    assertEquals(2000, metric.getTimeToResponseCompletedUs());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) IOException(java.io.IOException) Test(org.junit.Test)

Example 73 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class InstrHttpsURLConnectionTest method testDisconnect.

@Test
public void testDisconnect() throws IOException {
    HttpsURLConnection urlConnection = mockHttpsUrlConnection();
    new InstrHttpsURLConnection(urlConnection, timer, networkMetricBuilder).disconnect();
    verify(urlConnection).disconnect();
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
    NetworkRequestMetric metric = networkArgumentCaptor.getValue();
    assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(2000);
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Test(org.junit.Test)

Example 74 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class InstrURLConnectionBaseTest method testGetResponseMessageThrowsIOException.

@Test
public void testGetResponseMessageThrowsIOException() throws IOException {
    HttpURLConnection urlConnection = mockHttpUrlConnection();
    doThrow(IOException.class).when(urlConnection).getResponseMessage();
    assertThrows(IOException.class, () -> new InstrURLConnectionBase(urlConnection, timer, networkMetricBuilder).getResponseMessage());
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
    NetworkRequestMetric metric = networkArgumentCaptor.getValue();
    assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(2000);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 75 with NetworkRequestMetric

use of com.google.firebase.perf.v1.NetworkRequestMetric in project firebase-android-sdk by firebase.

the class InstrURLConnectionBaseTest method testGetInputStreamThrowsIOException.

@Test
public void testGetInputStreamThrowsIOException() throws IOException {
    HttpURLConnection urlConnection = mockHttpUrlConnection();
    doThrow(IOException.class).when(urlConnection).getInputStream();
    assertThrows(IOException.class, () -> new InstrURLConnectionBase(urlConnection, timer, networkMetricBuilder).getInputStream());
    verify(transportManager).log(networkArgumentCaptor.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
    NetworkRequestMetric metric = networkArgumentCaptor.getValue();
    assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(2000);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)81 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)80 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)45 NetworkRequestMetricBuilder (com.google.firebase.perf.metrics.NetworkRequestMetricBuilder)13 IOException (java.io.IOException)13 HttpResponse (org.apache.http.HttpResponse)13 HttpClient (org.apache.http.client.HttpClient)12 HttpURLConnection (java.net.HttpURLConnection)11 PerfMetric (com.google.firebase.perf.v1.PerfMetric)10 HttpHost (org.apache.http.HttpHost)6 HttpRequest (org.apache.http.HttpRequest)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 HttpContext (org.apache.http.protocol.HttpContext)6 HttpUrl (okhttp3.HttpUrl)4 Request (okhttp3.Request)4 RequestBody (okhttp3.RequestBody)4 TransportManager (com.google.firebase.perf.transport.TransportManager)3 URLWrapper (com.google.firebase.perf.util.URLWrapper)3 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)3 Response (okhttp3.Response)3