Skip to content
Permalink
Browse files
Add test mailserver logging
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Jan 15, 2020
1 parent 0d1c64f commit 85526580247360a2d41562878f3b3844f98e93a5
Showing 1 changed file with 10 additions and 1 deletion.
@@ -24,8 +24,8 @@

import com.sun.net.httpserver.*;
import org.openjdk.skara.email.EmailAddress;
import org.openjdk.skara.network.URIBuilder;
import org.openjdk.skara.mailinglist.Mbox;
import org.openjdk.skara.network.URIBuilder;

import java.io.*;
import java.net.*;
@@ -34,12 +34,15 @@
import java.security.*;
import java.time.Duration;
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Pattern;

public class TestMailmanServer implements AutoCloseable {
private final HttpServer httpServer;
private final SMTPServer smtpServer;
private final Map<String, Path> lists = new HashMap<>();
private final Logger log = Logger.getLogger("org.openjdk.skara.test");

private boolean lastResponseCached;

static private final Pattern listPathPattern = Pattern.compile("^/test/(.*?)/.*");
@@ -55,6 +58,7 @@ public void handle(HttpExchange exchange) throws IOException {
var response = Files.readString(list);
lastResponseCached = false;

log.warning("Read " + response.length() + " chars");
try {
var digest = MessageDigest.getInstance("SHA-256");
digest.update(response.getBytes(StandardCharsets.UTF_8));
@@ -65,8 +69,13 @@ public void handle(HttpExchange exchange) throws IOException {
if (exchange.getRequestHeaders().getFirst("If-None-Match").equals(etag)) {
exchange.sendResponseHeaders(304, 0);
lastResponseCached = true;
log.warning("Cache hit!");
return;
} else {
log.warning("Cache mismatch");
}
} else {
log.warning("No If-None-Match tag");
}

var responseBytes = response.getBytes(StandardCharsets.UTF_8);

0 comments on commit 8552658

Please sign in to comment.