@Test
    void requireThatConnectionIsTrackedInConnectionLog() throws Exception {
        Path privateKeyFile = File.createTempFile("junit", null, tmpFolder).toPath();
        Path certificateFile = File.createTempFile("junit", null, tmpFolder).toPath();
        generatePrivateKeyAndCertificate(privateKeyFile, certificateFile);
        InMemoryConnectionLog connectionLog = new InMemoryConnectionLog();
        Module overrideModule = binder -> binder.bind(ConnectionLog.class).toInstance(connectionLog);
        JettyTestDriver driver = JettyTestDriver.newInstanceWithSsl(new OkRequestHandler(), certificateFile, privateKeyFile, TlsClientAuth.NEED, overrideModule);
        int listenPort = driver.server().getListenPort();
        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();
        assertEquals(1, logEntries.size());
        ConnectionLogEntry logEntry = logEntries.get(0);
        assertEquals(4, UUID.fromString(logEntry.id()).version());
        assertTrue(logEntry.timestamp().isAfter(Instant.EPOCH));
        assertEquals(100L, logEntry.requests().get());
        assertEquals(100L, logEntry.responses().get());
        assertEquals("127.0.0.1", logEntry.peerAddress().get());
        assertEquals("127.0.0.1", logEntry.localAddress().get());
        assertEquals(listenPort, logEntry.localPort().get());
        assertTrue(logEntry.httpBytesReceived().get() > 100000L);
        assertTrue(logEntry.httpBytesSent().get() > 10000L);
        assertTrue(TlsContext.ALLOWED_PROTOCOLS.contains(logEntry.sslProtocol().get()));
        assertEquals("CN=localhost", logEntry.sslPeerSubject().get());
        assertFalse(logEntry.sslCipherSuite().get().isBlank());
        assertEquals(64, logEntry.sslSessionId().get().length());
        assertEquals(Instant.EPOCH, logEntry.sslPeerNotBefore().get());
        assertEquals(Instant.EPOCH.plus(100_000, ChronoUnit.DAYS), logEntry.sslPeerNotAfter().get());
        assertTrue(logEntry.sslBytesReceived().get() > 100000L);
        assertTrue(logEntry.sslBytesSent().get() > 10000L);
    }
@author Oyvind Bakksjo
@author Simon Thoresen Hult
@author bjorncs
container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java