### Question:
RequestsLogger implements Runnable, Closeable { public void start() { if (started) { throw new IllegalStateException("Already started"); } thread.start(); started = true; } RequestsLogger(RuntimeServerConfiguration currentConfiguration); void reloadConfiguration(RuntimeServerConfiguration newConfiguration); void logRequest(RequestHandler request); @Override void close(); void start(); void stop(); @Override void run(); public long lastFlush; }### Answer:
@Test public void testWithServer() throws Exception { stubFor(get(urlEqualTo("/index.html")) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/html") .withHeader("Content-Length", "it <b>works</b> !!".length() + "") .withBody("it <b>works</b> !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); ConnectionsManagerStats stats; try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.getCurrentConfiguration().setAccessLogPath(tmpDir.getRoot().getAbsolutePath()+"/access.log"); server.start(); int port = server.getLocalPort(); try (RawHttpClient client = new RawHttpClient("localhost", port)) { RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); String s = resp.toString(); assertTrue(s.endsWith("it <b>works</b> !!")); assertFalse(resp.getHeaderLines().stream().anyMatch(h -> h.contains("X-Cached"))); } try (RawHttpClient client = new RawHttpClient("localhost", port)) { { RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n"); String s = resp.toString(); assertTrue(s.endsWith("it <b>works</b> !!")); assertTrue(resp.getHeaderLines().stream().anyMatch(h -> h.contains("X-Cached"))); } { RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n"); String s = resp.toString(); assertTrue(s.endsWith("it <b>works</b> !!")); assertTrue(resp.getHeaderLines().stream().anyMatch(h -> h.contains("X-Cached"))); } } stats = server.getConnectionsManager().getStats(); } List<String> content = readFile(accessLogFilePath); TestUtils.waitForCondition(() -> { EndpointStats epstats = stats.getEndpointStats(key); return epstats.getTotalConnections().intValue() == 1 && epstats.getActiveConnections().intValue() == 0 && epstats.getOpenConnections().intValue() == 0; }, 100); TestUtils.waitForCondition(TestUtils.ALL_CONNECTIONS_CLOSED(stats), 100); }