aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_http_service
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2018-04-09 17:17:59 +0200
committerBjørn Christian Seime <bjorncs@oath.com>2018-04-11 11:11:17 +0200
commitf10178fe5823eabbda08483f88420f4edc540a27 (patch)
treeda3f680e10a7eefb2635c6bf0786063c23897df7 /jdisc_http_service
parent35298fbc6a0375566b5b50033c345e361e7249ee (diff)
Add unit test verifying that the access log is invoked for 414
Diffstat (limited to 'jdisc_http_service')
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java35
1 files changed, 33 insertions, 2 deletions
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
index 55dec64e967..824511af79f 100644
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
@@ -1,8 +1,10 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http.server.jetty;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
+import com.yahoo.container.logging.AccessLog;
+import com.yahoo.container.logging.AccessLogEntry;
import com.yahoo.jdisc.References;
import com.yahoo.jdisc.Request;
import com.yahoo.jdisc.Response;
@@ -58,12 +60,13 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author bakksjo
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ * @author Simon Thoresen Hult
*/
public class HttpServerTest {
@@ -120,6 +123,34 @@ public class HttpServerTest {
}
@Test
+ public void requireThatAccessLogIsCalledForRequestRejectedByJetty() throws Exception {
+ AccessLogMock accessLogMock = new AccessLogMock();
+ final TestDriver driver = TestDrivers.newConfiguredInstance(
+ mockRequestHandler(),
+ new ServerConfig.Builder(),
+ new ConnectorConfig.Builder().requestHeaderSize(1),
+ binder -> binder.bind(AccessLog.class).toInstance(accessLogMock));
+ driver.client().get("/status.html")
+ .expectStatusCode(is(REQUEST_URI_TOO_LONG));
+ assertThat(accessLogMock.logEntries.size(), equalTo(1));
+ AccessLogEntry accessLogEntry = accessLogMock.logEntries.get(0);
+ assertThat(accessLogEntry.getStatusCode(), equalTo(414));
+ assertThat(driver.close(), is(true));
+ }
+
+ private static class AccessLogMock extends AccessLog {
+
+ final List<AccessLogEntry> logEntries = new ArrayList<>();
+
+ AccessLogMock() { super(null); }
+
+ @Override
+ public void log(AccessLogEntry accessLogEntry) {
+ logEntries.add(accessLogEntry);
+ }
+ }
+
+ @Test
public void requireThatServerCanEcho() throws Exception {
final TestDriver driver = TestDrivers.newInstance(new EchoRequestHandler());
driver.client().get("/status.html")