From 14f1c8a6c6bf3a8daaadf4390b780abcf8314aad Mon Sep 17 00:00:00 2001 From: Scott Babcock Date: Thu, 24 Apr 2025 15:04:54 -0700 Subject: [PATCH] Revise parentage of driver server --- pom.xml | 5 +++-- .../htmlunit/remote/HtmlUnitDriverServer.java | 17 +++++++++++++---- .../selenium/htmlunit/WebDriverTestCase.java | 8 ++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 20c8d26..988926b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.nordstrom.ui-tools htmlunit-remote - 4.29.1-SNAPSHOT + 4.30.1-SNAPSHOT htmlunit-remote This is the remote wrapper for HtmlUnitDriver @@ -34,6 +34,7 @@ 11 4.30.0 4.30.0 + 4.13.2 10.15.0 4.8.4 9.1.0 @@ -91,7 +92,7 @@ junit junit - 4.13.2 + ${junit.version} test diff --git a/src/main/java/org/openqa/selenium/htmlunit/remote/HtmlUnitDriverServer.java b/src/main/java/org/openqa/selenium/htmlunit/remote/HtmlUnitDriverServer.java index f813437..e67c87b 100644 --- a/src/main/java/org/openqa/selenium/htmlunit/remote/HtmlUnitDriverServer.java +++ b/src/main/java/org/openqa/selenium/htmlunit/remote/HtmlUnitDriverServer.java @@ -82,7 +82,7 @@ public class HtmlUnitDriverServer extends NettyServer { * @param options {@link BaseServerOptions} object */ public HtmlUnitDriverServer(BaseServerOptions options) { - super(options, createHandlers().httpHandler); + super(options, HANDLERS.httpHandler); } private static final Type MAP_OF_LONGS = new TypeToken>() {}.getType(); @@ -92,10 +92,20 @@ public HtmlUnitDriverServer(BaseServerOptions options) { private static final Type MAP_OF_ACTIONS = new TypeToken>() {}.getType(); private static final Type MAP_OF_COOKIES = new TypeToken>() {}.getType(); + private static final Handlers HANDLERS = createHandlers(); private static final Logger LOG = Logger.getLogger(HtmlUnitDriverServer.class.getName()); - private static Map driverMap = new ConcurrentHashMap<>(); + static { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + HANDLERS.close(); + LOG.info("HtmlUnitDriverServer handlers have closed"); + } + }); + } + /** * Define the handlers for the routes supported by this server. * @@ -386,7 +396,6 @@ public HttpResponse execute(final HttpRequest req) throws UncheckedIOException { public HttpResponse execute(final HttpRequest req) throws UncheckedIOException { return releaseActions(sessionIdFrom(params)); } - }), post("/session/{sessionId}/alert/dismiss").to(params -> new HttpHandler() { @Override @@ -422,7 +431,7 @@ public HttpResponse execute(final HttpRequest req) throws UncheckedIOException { ) { @Override public void close() { - // TODO: Add implementation + // nothing to do here } }; } diff --git a/src/test/java/org/openqa/selenium/htmlunit/WebDriverTestCase.java b/src/test/java/org/openqa/selenium/htmlunit/WebDriverTestCase.java index 115123c..b607d18 100644 --- a/src/test/java/org/openqa/selenium/htmlunit/WebDriverTestCase.java +++ b/src/test/java/org/openqa/selenium/htmlunit/WebDriverTestCase.java @@ -59,10 +59,10 @@ public abstract class WebDriverTestCase extends WebTestCase { private static final Executor EXECUTOR_POOL = Executors.newFixedThreadPool(4); private static class ServerHolder { - private static final Server INSTANCE; + private static final Handlers HANDLERS = createHandlers(); + private static final Server INSTANCE = new NettyServer(defaultOptions(), HANDLERS.httpHandler); static { - INSTANCE = new NettyServer(defaultOptions(), createHandlers().httpHandler); INSTANCE.start(); Runtime.getRuntime().addShutdownHook( @@ -70,8 +70,12 @@ private static class ServerHolder { @Override public void run() { INSTANCE.stop(); + HANDLERS.close(); + LOG.info("Example site web server has stopped"); } }); + + LOG.info("Example site web server has started"); } private static Handlers createHandlers() {