|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
36 | 36 | import io.undertow.servlet.api.DeploymentInfo;
|
37 | 37 | import io.undertow.servlet.api.ServletContainer;
|
38 | 38 | import jakarta.servlet.ServletRegistration.Dynamic;
|
| 39 | +import org.apache.hc.client5.http.classic.HttpClient; |
| 40 | +import org.apache.hc.client5.http.impl.classic.HttpClients; |
39 | 41 | import org.apache.hc.core5.http.HttpResponse;
|
40 | 42 | import org.apache.jasper.servlet.JspServlet;
|
41 | 43 | import org.awaitility.Awaitility;
|
@@ -211,6 +213,35 @@ void whenServerIsShuttingDownGracefullyThenRequestsAreRejectedWithServiceUnavail
|
211 | 213 | this.webServer.stop();
|
212 | 214 | }
|
213 | 215 |
|
| 216 | + @Test |
| 217 | + void whenServerIsShuttingDownARequestOnAnIdleConnectionAreRejectedWithServiceUnavailable() throws Exception { |
| 218 | + AbstractServletWebServerFactory factory = getFactory(); |
| 219 | + factory.setShutdown(Shutdown.GRACEFUL); |
| 220 | + BlockingServlet blockingServlet = new BlockingServlet(); |
| 221 | + this.webServer = factory.getWebServer((context) -> { |
| 222 | + Dynamic registration = context.addServlet("blockingServlet", blockingServlet); |
| 223 | + registration.addMapping("/blocking"); |
| 224 | + registration.setAsyncSupported(true); |
| 225 | + }); |
| 226 | + HttpClient httpClient = HttpClients.createMinimal(); |
| 227 | + this.webServer.start(); |
| 228 | + int port = this.webServer.getPort(); |
| 229 | + Future<Object> keepAliveRequest = initiateGetRequest(httpClient, port, "/blocking"); |
| 230 | + blockingServlet.awaitQueue(); |
| 231 | + blockingServlet.admitOne(); |
| 232 | + assertThat(keepAliveRequest.get()).isInstanceOf(HttpResponse.class); |
| 233 | + Future<Object> request = initiateGetRequest(port, "/blocking"); |
| 234 | + blockingServlet.awaitQueue(); |
| 235 | + this.webServer.shutDownGracefully((result) -> { |
| 236 | + }); |
| 237 | + HttpResponse idleConnectionResponse = (HttpResponse) initiateGetRequest(httpClient, port, "/").get(); |
| 238 | + assertThat(idleConnectionResponse.getCode()).isEqualTo(503); |
| 239 | + blockingServlet.admitOne(); |
| 240 | + Object response = request.get(); |
| 241 | + assertThat(response).isInstanceOf(HttpResponse.class); |
| 242 | + this.webServer.stop(); |
| 243 | + } |
| 244 | + |
214 | 245 | private void testAccessLog(String prefix, String suffix, String expectedFile)
|
215 | 246 | throws IOException, URISyntaxException {
|
216 | 247 | UndertowServletWebServerFactory factory = getFactory();
|
|
0 commit comments