use of io.undertow.util.CompletionLatchHandler in project undertow by undertow-io.
the class JDBCLogDatabaseTestCase method testSingleLogMessageToDatabase.
@Test
public void testSingleLogMessageToDatabase() throws IOException, InterruptedException, SQLException {
JDBCLogHandler logHandler = new JDBCLogHandler(HELLO_HANDLER, DefaultServer.getWorker(), "common", ds);
CompletionLatchHandler latchHandler;
DefaultServer.setRootHandler(latchHandler = new CompletionLatchHandler(logHandler));
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
HttpResponse result = client.execute(get);
latchHandler.await();
logHandler.awaitWrittenForTest();
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("Hello", HttpClientUtils.readResponse(result));
} finally {
Connection conn = null;
Statement statement = null;
try {
conn = ds.getConnection();
statement = conn.createStatement();
ResultSet resultDatabase = statement.executeQuery("SELECT * FROM PUBLIC.ACCESS;");
resultDatabase.next();
Assert.assertEquals(DefaultServer.getDefaultServerAddress().getAddress().getHostAddress(), resultDatabase.getString(logHandler.getRemoteHostField()));
Assert.assertEquals("5", resultDatabase.getString(logHandler.getBytesField()));
Assert.assertEquals("200", resultDatabase.getString(logHandler.getStatusField()));
client.getConnectionManager().shutdown();
} finally {
if (statement != null) {
statement.close();
}
if (conn != null) {
conn.close();
}
}
}
}
use of io.undertow.util.CompletionLatchHandler in project undertow by undertow-io.
the class ExtendedAccessLogFileTestCase method verifySingleLogMessageToFile.
private void verifySingleLogMessageToFile(Path logFileName, DefaultAccessLogReceiver logReceiver) throws IOException, InterruptedException {
CompletionLatchHandler latchHandler;
DefaultServer.setRootHandler(latchHandler = new CompletionLatchHandler(new AccessLogHandler(HELLO_HANDLER, logReceiver, PATTERN, new ExtendedAccessLogParser(ExtendedAccessLogFileTestCase.class.getClassLoader()).parse(PATTERN))));
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
get.addHeader("test-header", "single-val");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("Hello", HttpClientUtils.readResponse(result));
latchHandler.await();
logReceiver.awaitWrittenForTest();
String data = new String(Files.readAllBytes(logFileName));
String[] lines = data.split("\n");
Assert.assertEquals("#Fields: " + PATTERN, lines[0]);
Assert.assertEquals("#Version: 2.0", lines[1]);
Assert.assertEquals("#Software: " + Version.getFullVersionString(), lines[2]);
Assert.assertEquals("", lines[3]);
Assert.assertEquals("/path 'single-val'", lines[4]);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.util.CompletionLatchHandler in project undertow by undertow-io.
the class AccessLogFileTestCase method verifySingleLogMessageToFile.
private void verifySingleLogMessageToFile(Path logFileName, DefaultAccessLogReceiver logReceiver) throws IOException, InterruptedException {
CompletionLatchHandler latchHandler;
DefaultServer.setRootHandler(latchHandler = new CompletionLatchHandler(new AccessLogHandler(HELLO_HANDLER, logReceiver, "Remote address %a Code %s test-header %{i,test-header} %{i,non-existent}", AccessLogFileTestCase.class.getClassLoader())));
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
get.addHeader("test-header", "single-val");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("Hello", HttpClientUtils.readResponse(result));
latchHandler.await();
logReceiver.awaitWrittenForTest();
Assert.assertEquals("Remote address " + DefaultServer.getDefaultServerAddress().getAddress().getHostAddress() + " Code 200 test-header single-val -\n", new String(Files.readAllBytes(logFileName)));
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations