Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test mailserver logging #327

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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);