Search in sources :

Example 1 with ResponseInfo

use of io.airlift.http.client.jetty.HttpClientLogger.ResponseInfo in project airlift by airlift.

the class TestHttpClientLogger method testClientLogNoResponse.

@Test
public void testClientLogNoResponse() throws Exception {
    String method = "GET";
    URI uri = new URI("http://www.google.com");
    long requestTimestamp = System.currentTimeMillis();
    HttpFields headers = new HttpFields();
    headers.add(TRACETOKEN_HEADER, "test-token");
    Request request = new TestRequest(HTTP_1_1, method, uri, headers);
    DefaultHttpClientLogger logger = new DefaultHttpClientLogger(file.getAbsolutePath(), 1, 256, new DataSize(1, MEGABYTE), Long.MAX_VALUE, false);
    RequestInfo requestInfo = RequestInfo.from(request, requestTimestamp);
    ResponseInfo responseInfo = ResponseInfo.failed(Optional.empty(), Optional.of(new TimeoutException("timeout")));
    logger.log(requestInfo, responseInfo);
    logger.close();
    String actual = Files.toString(file, UTF_8);
    String[] columns = actual.trim().split("\\t");
    assertEquals(columns[0], ISO_FORMATTER.format(Instant.ofEpochMilli(requestTimestamp)));
    assertEquals(columns[1], HTTP_1_1.toString());
    assertEquals(columns[2], method);
    assertEquals(columns[3], uri.toString());
    assertEquals(columns[4], getFailureReason(responseInfo).get());
    assertEquals(columns[5], Integer.toString(NO_RESPONSE));
    assertEquals(columns[6], Long.toString(responseInfo.getResponseTimestampMillis() - requestTimestamp));
    assertEquals(columns[7], "test-token");
}
Also used : ResponseInfo(io.airlift.http.client.jetty.HttpClientLogger.ResponseInfo) HttpFields(org.eclipse.jetty.http.HttpFields) DataSize(io.airlift.units.DataSize) Request(org.eclipse.jetty.client.api.Request) RequestInfo(io.airlift.http.client.jetty.HttpClientLogger.RequestInfo) URI(java.net.URI) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 2 with ResponseInfo

use of io.airlift.http.client.jetty.HttpClientLogger.ResponseInfo in project airlift by airlift.

the class TestHttpClientLogger method testClientLog.

@Test
public void testClientLog() throws Exception {
    String method = "GET";
    URI uri = new URI("http://www.google.com");
    int status = 200;
    long responseSize = 345;
    long requestTimestamp = System.currentTimeMillis();
    HttpFields headers = new HttpFields();
    headers.add(TRACETOKEN_HEADER, "test-token");
    Request request = new TestRequest(HTTP_2, method, uri, headers);
    Response response = new TestResponse(status);
    DefaultHttpClientLogger logger = new DefaultHttpClientLogger(file.getAbsolutePath(), 1, 256, new DataSize(1, MEGABYTE), Long.MAX_VALUE, false);
    RequestInfo requestInfo = RequestInfo.from(request, requestTimestamp);
    ResponseInfo responseInfo = ResponseInfo.from(Optional.of(response), responseSize);
    logger.log(requestInfo, responseInfo);
    logger.close();
    String actual = Files.toString(file, UTF_8);
    String[] columns = actual.trim().split("\\t");
    assertEquals(columns[0], ISO_FORMATTER.format(Instant.ofEpochMilli(requestTimestamp)));
    assertEquals(columns[1], HTTP_2.toString());
    assertEquals(columns[2], method);
    assertEquals(columns[3], uri.toString());
    assertEquals(columns[4], Integer.toString(status));
    assertEquals(columns[5], Long.toString(responseSize));
    assertEquals(columns[6], Long.toString(responseInfo.getResponseTimestampMillis() - requestTimestamp));
    assertEquals(columns[7], "test-token");
}
Also used : ResponseInfo(io.airlift.http.client.jetty.HttpClientLogger.ResponseInfo) Request(org.eclipse.jetty.client.api.Request) RequestInfo(io.airlift.http.client.jetty.HttpClientLogger.RequestInfo) URI(java.net.URI) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Response(org.eclipse.jetty.client.api.Response) HttpFields(org.eclipse.jetty.http.HttpFields) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Aggregations

RequestInfo (io.airlift.http.client.jetty.HttpClientLogger.RequestInfo)2 ResponseInfo (io.airlift.http.client.jetty.HttpClientLogger.ResponseInfo)2 DataSize (io.airlift.units.DataSize)2 URI (java.net.URI)2 Request (org.eclipse.jetty.client.api.Request)2 HttpFields (org.eclipse.jetty.http.HttpFields)2 Test (org.testng.annotations.Test)2 TimeoutException (java.util.concurrent.TimeoutException)1 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)1 Response (org.eclipse.jetty.client.api.Response)1