summaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/jdisc/http/server
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-03-25 13:00:57 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-03-25 13:23:51 +0100
commite799cdfb389991997927bbe08f32c22fdc0cb53c (patch)
tree1b442964f58100be4c154a8f7145bc0b7a278d25 /container-core/src/test/java/com/yahoo/jdisc/http/server
parent8b38acb71853662d6f2cb96bf8c4c2a982b4cbef (diff)
Extend connection log unit test to include multiple requests
Diffstat (limited to 'container-core/src/test/java/com/yahoo/jdisc/http/server')
-rw-r--r--container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java30
1 files changed, 24 insertions, 6 deletions
diff --git a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
index c00525a3ddc..cb7e3ef347f 100644
--- a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
+++ b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
@@ -16,6 +16,7 @@ import com.yahoo.jdisc.application.MetricConsumer;
import com.yahoo.jdisc.handler.AbstractRequestHandler;
import com.yahoo.jdisc.handler.CompletionHandler;
import com.yahoo.jdisc.handler.ContentChannel;
+import com.yahoo.jdisc.handler.NullContent;
import com.yahoo.jdisc.handler.RequestHandler;
import com.yahoo.jdisc.handler.ResponseDispatch;
import com.yahoo.jdisc.handler.ResponseHandler;
@@ -834,22 +835,30 @@ public class HttpServerTest {
generatePrivateKeyAndCertificate(privateKeyFile, certificateFile);
InMemoryConnectionLog connectionLog = new InMemoryConnectionLog();
Module overrideModule = binder -> binder.bind(ConnectionLog.class).toInstance(connectionLog);
- TestDriver driver = TestDrivers.newInstanceWithSsl(new EchoRequestHandler(), certificateFile, privateKeyFile, TlsClientAuth.NEED, overrideModule);
+ TestDriver driver = TestDrivers.newInstanceWithSsl(new OkRequestHandler(), certificateFile, privateKeyFile, TlsClientAuth.NEED, overrideModule);
int listenPort = driver.server().getListenPort();
- driver.client().get("/status.html");
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 1000; i++) {
+ builder.append(i);
+ }
+ byte[] content = builder.toString().getBytes();
+ for (int i = 0; i < 100; i++) {
+ driver.client().newPost("/status.html").setBinaryContent(content).execute()
+ .expectStatusCode(is(OK));
+ }
assertTrue(driver.close());
List<ConnectionLogEntry> logEntries = connectionLog.logEntries();
Assertions.assertThat(logEntries).hasSize(1);
ConnectionLogEntry logEntry = logEntries.get(0);
assertEquals(4, UUID.fromString(logEntry.id()).version());
Assertions.assertThat(logEntry.timestamp()).isAfter(Instant.EPOCH);
- Assertions.assertThat(logEntry.requests()).hasValue(1L);
- Assertions.assertThat(logEntry.responses()).hasValue(1L);
+ Assertions.assertThat(logEntry.requests()).hasValue(100L);
+ Assertions.assertThat(logEntry.responses()).hasValue(100L);
Assertions.assertThat(logEntry.peerAddress()).hasValue("127.0.0.1");
Assertions.assertThat(logEntry.localAddress()).hasValue("127.0.0.1");
Assertions.assertThat(logEntry.localPort()).hasValue(listenPort);
- Assertions.assertThat(logEntry.httpBytesReceived()).hasValueSatisfying(value -> Assertions.assertThat(value).isPositive());
- Assertions.assertThat(logEntry.httpBytesSent()).hasValueSatisfying(value -> Assertions.assertThat(value).isPositive());
+ Assertions.assertThat(logEntry.httpBytesReceived()).hasValueSatisfying(value -> Assertions.assertThat(value).isGreaterThan(100000L));
+ Assertions.assertThat(logEntry.httpBytesSent()).hasValueSatisfying(value -> Assertions.assertThat(value).isGreaterThan(10000L));
Assertions.assertThat(logEntry.sslProtocol()).hasValueSatisfying(TlsContext.ALLOWED_PROTOCOLS::contains);
Assertions.assertThat(logEntry.sslPeerSubject()).hasValue("CN=localhost");
Assertions.assertThat(logEntry.sslCipherSuite()).hasValueSatisfying(cipher -> Assertions.assertThat(cipher).isNotBlank());
@@ -1156,6 +1165,15 @@ public class HttpServerTest {
}
}
+ private static class OkRequestHandler extends AbstractRequestHandler {
+ @Override
+ public ContentChannel handleRequest(Request request, ResponseHandler handler) {
+ Response response = new Response(OK);
+ handler.handleResponse(response).close(null);
+ return NullContent.INSTANCE;
+ }
+ }
+
private static class EchoWithHeaderRequestHandler extends AbstractRequestHandler {
final String headerName;