package io.undertow.server.handlers.accesslog;

import java.io.IOException;

import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.testutils.DefaultServer;
import io.undertow.testutils.HttpClientUtils;
import io.undertow.testutils.TestHttpClient;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * @author Stuart Douglas
 */
@RunWith(DefaultServer.class)
public class AccessLogTestCase {

    private static volatile String message;

    private static final AccessLogReceiver RECIEVER = new AccessLogReceiver() {
        @Override
        public void logMessage(final String msg) {
            message = msg;
        }
    };

    private static final HttpHandler HELLO_HANDLER = new HttpHandler() {
        @Override
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            exchange.getResponseSender().send("Hello");
        }
    };

    @Test
    public void testRemoteAddress() throws IOException {
        DefaultServer.setRootHandler(new AccessLogHandler(HELLO_HANDLER, RECIEVER, "Remote address %a Code %s test-header %{test-header}i", DefaultAccessLogTokens.INSTANCE));
        TestHttpClient client = new TestHttpClient();
        try {
            HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
            get.addHeader("test-header", "test-value");
            HttpResponse result = client.execute(get);
            Assert.assertEquals(200, result.getStatusLine().getStatusCode());
            Assert.assertEquals("Hello", HttpClientUtils.readResponse(result));
            Assert.assertEquals(message, "Remote address 127.0.0.1 Code 200 test-header test-value");
        } finally {
            client.getConnectionManager().shutdown();
        }
    }

}

@@ -68,16 +68,98 @@
 ception;
+%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;
 %0A%0Aimport
@@ -689,30 +689,68 @@
     private 
-static
+volatile CountDownLatch latch;%0A%0A%0A    private
  final Acces
@@ -795,24 +795,26 @@
 eceiver() %7B%0A
+%0A%0A
         @Ove
@@ -897,16 +897,47 @@
  = msg;%0A
+            latch.countDown();%0A
         
@@ -1255,34 +1255,95 @@
 rows IOException
- %7B
+, InterruptedException %7B%0A        latch = new CountDownLatch(1);
 %0A        Default
@@ -1921,24 +1921,71 @@
 e(result));%0A
+            latch.await(10, TimeUnit.SECONDS);%0A
             
@@ -2008,17 +2008,8 @@
 als(
-message, 
 %22Rem
@@ -2054,32 +2054,41 @@
 ader test-value%22
+, message
 );%0A        %7D fin

Fix test