Skip to content

Commit 1b1e373

Browse files
committed
take 8: new readiness check layout
1 parent 04c1ec1 commit 1b1e373

6 files changed

Lines changed: 41 additions & 88 deletions

File tree

exist-core/src/main/java/org/exist/TestUtils.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ public class TestUtils {
8282

8383
private static final int WEBAPP_READY_POLL_DELAY_MS = 500;
8484
private static final int WEBAPP_READY_TIMEOUT_WINDOWS_MS = 120_000;
85+
private static final int WEBAPP_READY_TIMEOUT_WINDOWS_CI_MS = 300_000;
8586
private static final int WEBAPP_READY_TIMEOUT_CI_MS = 180_000;
8687
private static final int WEBAPP_READY_TIMEOUT_DEFAULT_MS = 45_000;
8788
private static final int TCP_CONNECT_TIMEOUT_MS = 1_000;
8889
private static final int TCP_READY_POLL_DELAY_MS = 500;
8990
private static final int TCP_READY_TIMEOUT_WINDOWS_MS = 60_000;
9091
private static final int TCP_READY_TIMEOUT_DEFAULT_MS = 30_000;
91-
private static final int HTTP_PROBE_CONNECT_TIMEOUT_MS = 2_000;
92-
private static final int HTTP_PROBE_READ_TIMEOUT_MS = 2_000;
92+
private static final int HTTP_PROBE_CONNECT_TIMEOUT_MS = 5_000;
93+
private static final int HTTP_PROBE_READ_TIMEOUT_MS = 30_000;
9394

9495
/**
9596
* Removes all sub-collections of /db
@@ -241,8 +242,9 @@ public static void awaitTcpPortReady(final int port, final int timeoutMs) throws
241242
* <p>
242243
* Does not probe HTTP ({@code /rest}, {@code /xmlrpc}): on Jetty 12 / Windows CI those requests can
243244
* return {@code 503} through {@code XQueryURLRewrite} long after the in-process broker is ready.
244-
* {@link org.exist.jetty.JettyStart} blocks until webapp contexts are started; this method polls
245-
* direct servlet paths where {@code isAvailable()} can lag on Windows CI.
245+
* {@link org.exist.jetty.JettyStart} blocks until webapp contexts are {@code isAvailable()}.
246+
* When integration test webapps omit {@code load-on-startup}, this method warms direct servlet
247+
* mappings via the optional HTTP probe path.
246248
*
247249
* @param port unused; kept for callers
248250
* @param jettyStandaloneMode unused; kept for callers
@@ -333,7 +335,7 @@ private static int httpGetStatus(final String url, final boolean withAdminBasicA
333335
private static int webAppReadyTimeoutMs() {
334336
if (isWindowsHost()) {
335337
return System.getenv("CI") != null
336-
? WEBAPP_READY_TIMEOUT_CI_MS
338+
? WEBAPP_READY_TIMEOUT_WINDOWS_CI_MS
337339
: WEBAPP_READY_TIMEOUT_WINDOWS_MS;
338340
}
339341
if (System.getenv("CI") != null) {
@@ -345,7 +347,7 @@ private static int webAppReadyTimeoutMs() {
345347
private static int tcpReadyTimeoutMs() {
346348
if (isWindowsHost()) {
347349
return System.getenv("CI") != null
348-
? WEBAPP_READY_TIMEOUT_CI_MS
350+
? WEBAPP_READY_TIMEOUT_WINDOWS_CI_MS
349351
: TCP_READY_TIMEOUT_WINDOWS_MS;
350352
}
351353
return TCP_READY_TIMEOUT_DEFAULT_MS;

exist-core/src/main/java/org/exist/jetty/JettyStart.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,12 @@ private Optional<Server> startJetty(final List<Object> configuredObjects) throws
517517
/**
518518
* Block until deployed webapps reach the readiness level required for tests.
519519
* <p>
520-
* Standalone mode deploys a single context at {@code /}; distribution mode deploys {@code /exist}
521-
* plus an optional portal at {@code /}. Only {@code /exist} must be {@code isAvailable()} before
522-
* rewrite-based HTTP tests run. Standalone integration tests (webdav, restxq, file) use direct
523-
* servlet mappings and rely on {@link org.exist.TestUtils#awaitJettyWebAppReady} HTTP probes
524-
* after {@code isStarted()}. The portal redirect webapp is non-gating (see Option C in test docs).
520+
* Every context except the distribution portal at {@code /} must be
521+
* {@link org.eclipse.jetty.server.handler.ContextHandler#isAvailable()} — Jetty returns
522+
* {@code 503} on all paths while unavailable. The portal coexists with {@code /exist} and is
523+
* non-gating. Integration test webapps defer servlet {@code load-on-startup} so the context
524+
* can become available before Milton/REST init; {@link org.exist.TestUtils} HTTP probes then
525+
* warm direct servlet mappings.
525526
*/
526527
private void awaitWebAppContextsStarted(final List<Handler> handlers) throws InterruptedException {
527528
final List<WebAppContext> webApps = new ArrayList<>();
@@ -534,6 +535,7 @@ private void awaitWebAppContextsStarted(final List<Handler> handlers) throws Int
534535
return;
535536
}
536537

538+
final boolean distributionLayout = isDistributionLayout(webApps);
537539
final long timeoutMs = slowEnvironmentStartupDeadlineMs();
538540
final long deadline = System.currentTimeMillis() + timeoutMs;
539541
while (System.currentTimeMillis() < deadline) {
@@ -543,7 +545,7 @@ private void awaitWebAppContextsStarted(final List<Handler> handlers) throws Int
543545
throw new IllegalStateException(
544546
"Web application failed to start: " + webApp.getContextPath());
545547
}
546-
if (!isWebAppContextReady(webApp)) {
548+
if (!isWebAppContextReady(webApp, distributionLayout)) {
547549
allReady = false;
548550
break;
549551
}
@@ -556,43 +558,53 @@ private void awaitWebAppContextsStarted(final List<Handler> handlers) throws Int
556558
}
557559
throw new IllegalStateException(
558560
"Web application context did not become ready within " + timeoutMs + "ms: "
559-
+ describePendingWebApps(webApps));
561+
+ describePendingWebApps(webApps, distributionLayout));
562+
}
563+
564+
private static boolean isDistributionLayout(final List<WebAppContext> webApps) {
565+
return webApps.stream().anyMatch(webApp -> "/exist".equals(webApp.getContextPath()));
560566
}
561567

562568
/**
563-
* {@code /exist} (distribution) must be {@code isAvailable()} for rewrite-based HTTP tests.
564-
* Standalone {@code /} and the distribution portal only need {@code isStarted()}; module HTTP
565-
* probes or the in-process broker cover the rest.
569+
* Distribution portal {@code /} only needs {@code isStarted()}. Standalone {@code /} and
570+
* {@code /exist} must be {@code isAvailable()} or HTTP clients see {@code 503}.
566571
*/
567-
private static boolean isWebAppContextReady(final WebAppContext webApp) {
572+
private static boolean isWebAppContextReady(final WebAppContext webApp, final boolean distributionLayout) {
568573
if (!webApp.isStarted()) {
569574
return false;
570575
}
571-
return !"/exist".equals(webApp.getContextPath()) || webApp.isAvailable();
576+
if (distributionLayout && "/".equals(webApp.getContextPath())) {
577+
return true;
578+
}
579+
return webApp.isAvailable();
572580
}
573581

574-
private static String describePendingWebApps(final List<WebAppContext> webApps) {
582+
private static String describePendingWebApps(final List<WebAppContext> webApps, final boolean distributionLayout) {
575583
final StringBuilder details = new StringBuilder();
576584
for (final WebAppContext webApp : webApps) {
577585
if (webApp.isFailed()) {
578586
continue;
579587
}
580-
if (!isWebAppContextReady(webApp)) {
588+
if (!isWebAppContextReady(webApp, distributionLayout)) {
581589
if (!details.isEmpty()) {
582590
details.append("; ");
583591
}
584592
details.append(webApp.getContextPath())
585593
.append(" started=").append(webApp.isStarted())
586594
.append(" available=").append(webApp.isAvailable())
587-
.append(" requireAvailable=").append("/exist".equals(webApp.getContextPath()));
595+
.append(" requireAvailable=").append(requiresAvailability(webApp, distributionLayout));
588596
}
589597
}
590598
return details.isEmpty() ? "unknown" : details.toString();
591599
}
592600

601+
private static boolean requiresAvailability(final WebAppContext webApp, final boolean distributionLayout) {
602+
return !(distributionLayout && "/".equals(webApp.getContextPath()));
603+
}
604+
593605
private static long slowEnvironmentStartupDeadlineMs() {
594606
if (isWindowsHost()) {
595-
return System.getenv("CI") != null ? 180_000L : 120_000L;
607+
return System.getenv("CI") != null ? 300_000L : 120_000L;
596608
}
597609
if (System.getenv("CI") != null) {
598610
return 180_000L;

exist-core/src/main/java/org/exist/test/ExistWebServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ public void restart() {
150150
}
151151
} catch (final InterruptedException e) {
152152
Thread.currentThread().interrupt();
153-
throw new RuntimeException(e);
153+
throw new IllegalStateException("Failed to restart ExistWebServer", e);
154154
} catch (final Exception e) {
155-
throw new RuntimeException(e);
155+
throw new IllegalStateException("Failed to restart ExistWebServer", e);
156156
}
157157
} else {
158158
throw new IllegalStateException("ExistWebServer already stopped");

extensions/exquery/restxq/src/test/resources/standalone-webapp/WEB-INF/web.xml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</init-param>
5151
<init-param>
5252
<param-name>start</param-name>
53-
<param-value>true</param-value>
53+
<param-value>false</param-value>
5454
</init-param>
5555
<init-param>
5656
<param-name>hidden</param-name>
@@ -64,20 +64,6 @@
6464
<param-name>xupdate-submission</param-name>
6565
<param-value>enabled</param-value>
6666
</init-param>
67-
<load-on-startup>2</load-on-startup>
68-
</servlet>
69-
70-
<servlet>
71-
<servlet-name>XQueryURLRewrite</servlet-name>
72-
<servlet-class>org.exist.http.urlrewrite.XQueryURLRewrite</servlet-class>
73-
<init-param>
74-
<param-name>config</param-name>
75-
<param-value>WEB-INF/controller-config.xml</param-value>
76-
</init-param>
77-
<init-param>
78-
<param-name>send-challenge</param-name>
79-
<param-value>true</param-value>
80-
</init-param>
8167
</servlet>
8268

8369
<servlet>
@@ -109,12 +95,6 @@
10995
<url-pattern>/restxq/*</url-pattern>
11096
</servlet-mapping>
11197

112-
<!-- XQuery URL rewriter -->
113-
<servlet-mapping>
114-
<servlet-name>XQueryURLRewrite</servlet-name>
115-
<url-pattern>/*</url-pattern>
116-
</servlet-mapping>
117-
11898
<!--
11999
==================== various MIME type mappings ==================
120100
-->

extensions/modules/file/src/test/resources/standalone-webapp/WEB-INF/web.xml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,8 @@
5454
</init-param>
5555
<init-param>
5656
<param-name>start</param-name>
57-
<param-value>true</param-value>
57+
<param-value>false</param-value>
5858
</init-param>
59-
<load-on-startup>2</load-on-startup>
60-
</servlet>
61-
62-
<servlet>
63-
<servlet-name>XQueryURLRewrite</servlet-name>
64-
<servlet-class>org.exist.http.urlrewrite.XQueryURLRewrite</servlet-class>
65-
<init-param>
66-
<param-name>config</param-name>
67-
<param-value>WEB-INF/controller-config.xml</param-value>
68-
</init-param>
69-
</servlet>
70-
71-
<servlet>
72-
<servlet-name>XSLTServlet</servlet-name>
73-
<servlet-class>org.exist.http.servlets.XSLTServlet</servlet-class>
7459
</servlet>
7560

7661
<servlet-mapping>
@@ -85,9 +70,4 @@
8570
<servlet-name>EXistServlet</servlet-name>
8671
<url-pattern>/rest/*</url-pattern>
8772
</servlet-mapping>
88-
89-
<servlet-mapping>
90-
<servlet-name>XQueryURLRewrite</servlet-name>
91-
<url-pattern>/*</url-pattern>
92-
</servlet-mapping>
9373
</web-app>

extensions/webdav/src/test/resources/standalone-webapp/WEB-INF/web.xml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@
5454
</init-param>
5555
<init-param>
5656
<param-name>start</param-name>
57-
<param-value>true</param-value>
57+
<param-value>false</param-value>
5858
</init-param>
59-
<load-on-startup>2</load-on-startup>
6059
</servlet>
6160

6261
<!--
@@ -93,21 +92,6 @@
9392
<param-value>com.bradmcevoy.http.DebugFilter</param-value>
9493
</init-param>
9594
-->
96-
<load-on-startup>3</load-on-startup>
97-
</servlet>
98-
99-
<servlet>
100-
<servlet-name>XQueryURLRewrite</servlet-name>
101-
<servlet-class>org.exist.http.urlrewrite.XQueryURLRewrite</servlet-class>
102-
<init-param>
103-
<param-name>config</param-name>
104-
<param-value>WEB-INF/controller-config.xml</param-value>
105-
</init-param>
106-
</servlet>
107-
108-
<servlet>
109-
<servlet-name>XSLTServlet</servlet-name>
110-
<servlet-class>org.exist.http.servlets.XSLTServlet</servlet-class>
11195
</servlet>
11296

11397
<servlet-mapping>
@@ -126,9 +110,4 @@
126110
<servlet-name>milton</servlet-name>
127111
<url-pattern>/webdav/*</url-pattern>
128112
</servlet-mapping>
129-
130-
<servlet-mapping>
131-
<servlet-name>XQueryURLRewrite</servlet-name>
132-
<url-pattern>/*</url-pattern>
133-
</servlet-mapping>
134113
</web-app>

0 commit comments

Comments
 (0)