Skip to content

Commit 7d9a438

Browse files
Volkan Yazicijaikiran
Volkan Yazici
authored andcommitted
8355370: Include server name in HTTP test server thread names to improve diagnostics
Reviewed-by: dfuchs, jpai
1 parent 375ac6d commit 7d9a438

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ public static abstract class HttpTestContext {
765765
/**
766766
* A version agnostic adapter class for HTTP Servers.
767767
*/
768-
public static abstract class HttpTestServer {
768+
abstract class HttpTestServer implements AutoCloseable {
769769
private static final class ServerLogging {
770770
private static final Logger logger = Logger.getLogger("com.sun.net.httpserver");
771771
static void enableLogging() {
@@ -782,6 +782,11 @@ static void enableLogging() {
782782
public abstract Version getVersion();
783783
public abstract void setRequestApprover(final Predicate<String> approver);
784784

785+
@Override
786+
public void close() throws Exception {
787+
stop();
788+
}
789+
785790
public String serverAuthority() {
786791
InetSocketAddress address = getAddress();
787792
String hostString = address.getHostString();
@@ -971,6 +976,13 @@ public void stop() {
971976
System.out.println("Http2TestServerImpl: stop");
972977
impl.stop();
973978
}
979+
980+
@Override
981+
public void close() throws Exception {
982+
System.out.println("Http2TestServerImpl: close");
983+
impl.close();
984+
}
985+
974986
@Override
975987
public HttpTestContext addHandler(HttpTestHandler handler, String path) {
976988
System.out.println("Http2TestServerImpl[" + getAddress()

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/http2/Http2TestServer.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,6 +38,7 @@
3838
import javax.net.ssl.SSLContext;
3939
import javax.net.ssl.SSLParameters;
4040
import javax.net.ssl.SSLServerSocket;
41+
4142
import jdk.internal.net.http.frame.ErrorFrame;
4243

4344
/**
@@ -64,24 +65,18 @@ public class Http2TestServer implements AutoCloseable {
6465
// request approver which takes the server connection key as the input
6566
private volatile Predicate<String> newRequestApprover;
6667

67-
private static ThreadFactory defaultThreadFac =
68-
(Runnable r) -> {
69-
Thread t = new Thread(r);
70-
t.setName("Test-server-pool");
71-
return t;
72-
};
73-
74-
75-
private static ExecutorService getDefaultExecutor() {
76-
return Executors.newCachedThreadPool(defaultThreadFac);
68+
private static ExecutorService createExecutor(String name) {
69+
String threadNamePrefix = "%s-pool".formatted(name);
70+
ThreadFactory threadFactory = Thread.ofPlatform().name(threadNamePrefix, 0).factory();
71+
return Executors.newCachedThreadPool(threadFactory);
7772
}
7873

7974
public Http2TestServer(String serverName, boolean secure, int port) throws Exception {
80-
this(serverName, secure, port, getDefaultExecutor(), 50, null, null);
75+
this(serverName, secure, port, null, 50, null, null);
8176
}
8277

8378
public Http2TestServer(boolean secure, int port) throws Exception {
84-
this(null, secure, port, getDefaultExecutor(), 50, null, null);
79+
this(null, secure, port, null, 50, null, null);
8580
}
8681

8782
public InetSocketAddress getAddress() {
@@ -197,7 +192,7 @@ public Http2TestServer(InetAddress localAddr,
197192
server = initPlaintext(port, backlog);
198193
}
199194
this.secure = secure;
200-
this.exec = exec == null ? getDefaultExecutor() : exec;
195+
this.exec = exec == null ? createExecutor(name) : exec;
201196
this.handlers = Collections.synchronizedMap(new HashMap<>());
202197
this.properties = properties == null ? new Properties() : properties;
203198
this.connections = ConcurrentHashMap.newKeySet();

0 commit comments

Comments
 (0)