-
Notifications
You must be signed in to change notification settings - Fork 40.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Tomcat's handling of a request on an idle connection
See gh-4657
- Loading branch information
1 parent
b8cb61b
commit 19cc388
Showing
1 changed file
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.SocketException; | ||
import java.net.URISyntaxException; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
|
@@ -57,7 +58,9 @@ | |
import org.apache.coyote.ProtocolHandler; | ||
import org.apache.coyote.http11.AbstractHttp11Protocol; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.conn.HttpHostConnectException; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.jasper.servlet.JspServlet; | ||
import org.apache.tomcat.JarScanFilter; | ||
import org.apache.tomcat.JarScanType; | ||
|
@@ -582,8 +585,40 @@ void whenServerIsShuttingDownGracefullyThenNewConnectionsCannotBeMade() throws E | |
assertThat(shutdownResult.get()).isEqualTo(false); | ||
blockingServlet.admitOne(); | ||
assertThat(request.get()).isInstanceOf(HttpResponse.class); | ||
this.webServer.stop(); | ||
assertThat(unconnectableRequest.get()).isInstanceOf(HttpHostConnectException.class); | ||
this.webServer.stop(); | ||
} | ||
|
||
@Test | ||
void whenServerIsShuttingDownARequestOnAnIdleConnectionResultsInConnectionReset() throws Exception { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wilkinsona
Author
Member
|
||
AbstractServletWebServerFactory factory = getFactory(); | ||
Shutdown shutdown = new Shutdown(); | ||
shutdown.setGracePeriod(Duration.ofSeconds(5)); | ||
factory.setShutdown(shutdown); | ||
BlockingServlet blockingServlet = new BlockingServlet(); | ||
this.webServer = factory.getWebServer((context) -> { | ||
Dynamic registration = context.addServlet("blockingServlet", blockingServlet); | ||
registration.addMapping("/blocking"); | ||
registration.setAsyncSupported(true); | ||
}); | ||
HttpClient httpClient = HttpClients.createMinimal(); | ||
this.webServer.start(); | ||
int port = this.webServer.getPort(); | ||
Future<Object> keepAliveRequest = initiateGetRequest(httpClient, port, "/blocking"); | ||
blockingServlet.awaitQueue(); | ||
blockingServlet.admitOne(); | ||
assertThat(keepAliveRequest.get()).isInstanceOf(HttpResponse.class); | ||
Future<Object> request = initiateGetRequest(port, "/blocking"); | ||
blockingServlet.awaitQueue(); | ||
initiateGracefulShutdown(); | ||
Future<Object> idleConnectionRequest = initiateGetRequest(httpClient, port, "/blocking"); | ||
blockingServlet.admitOne(); | ||
Object response = request.get(); | ||
assertThat(response).isInstanceOf(HttpResponse.class); | ||
Object idleConnectionRequestResult = idleConnectionRequest.get(); | ||
assertThat(idleConnectionRequestResult).isInstanceOf(SocketException.class); | ||
assertThat((SocketException) idleConnectionRequestResult).hasMessage("Connection reset"); | ||
this.webServer.stop(); | ||
} | ||
|
||
@Override | ||
|
This seems to fail on JDK 11+, @wilkinsona . Are you aware?