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");
}
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");
}
Aggregations