@ -66,6 +66,7 @@ import org.apache.jasper.servlet.JspServlet;
import org.apache.tomcat.JarScanFilter ;
import org.apache.tomcat.JarScanFilter ;
import org.apache.tomcat.JarScanType ;
import org.apache.tomcat.JarScanType ;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable ;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable ;
import org.awaitility.Awaitility ;
import org.junit.jupiter.api.AfterEach ;
import org.junit.jupiter.api.AfterEach ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.Test ;
import org.mockito.ArgumentCaptor ;
import org.mockito.ArgumentCaptor ;
@ -599,17 +600,21 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory
assertThat ( keepAliveRequest . get ( ) ) . isInstanceOf ( HttpResponse . class ) ;
assertThat ( keepAliveRequest . get ( ) ) . isInstanceOf ( HttpResponse . class ) ;
Future < Object > request = initiateGetRequest ( port , "/blocking" ) ;
Future < Object > request = initiateGetRequest ( port , "/blocking" ) ;
blockingServlet . awaitQueue ( ) ;
blockingServlet . awaitQueue ( ) ;
blockingServlet . setBlocking ( false ) ;
this . webServer . shutDownGracefully ( ( result ) - > {
this . webServer . shutDownGracefully ( ( result ) - > {
} ) ;
} ) ;
Object idleConnectionRequestResult = Awaitility . await ( ) . until ( ( ) - > {
Future < Object > idleConnectionRequest = initiateGetRequest ( httpClient , port , "/blocking" ) ;
Future < Object > idleConnectionRequest = initiateGetRequest ( httpClient , port , "/blocking" ) ;
blockingServlet . admitOne ( ) ;
Object result = idleConnectionRequest . get ( ) ;
Object response = request . get ( ) ;
return result ;
assertThat ( response ) . isInstanceOf ( HttpResponse . class ) ;
} , ( result ) - > result instanceof Exception ) ;
Object idleConnectionRequestResult = idleConnectionRequest . get ( ) ;
assertThat ( idleConnectionRequestResult ) . isInstanceOfAny ( SocketException . class , NoHttpResponseException . class ) ;
assertThat ( idleConnectionRequestResult ) . isInstanceOfAny ( SocketException . class , NoHttpResponseException . class ) ;
if ( idleConnectionRequestResult instanceof SocketException ) {
if ( idleConnectionRequestResult instanceof SocketException ) {
assertThat ( ( SocketException ) idleConnectionRequestResult ) . hasMessage ( "Connection reset" ) ;
assertThat ( ( SocketException ) idleConnectionRequestResult ) . hasMessage ( "Connection reset" ) ;
}
}
blockingServlet . admitOne ( ) ;
Object response = request . get ( ) ;
assertThat ( response ) . isInstanceOf ( HttpResponse . class ) ;
this . webServer . stop ( ) ;
this . webServer . stop ( ) ;
}
}