Merge pull request #17336 from izeye
* gh-17336: Polish TomcatReactiveWebServerFactoryTests Closes gh-17336
This commit is contained in:
@@ -40,7 +40,6 @@ import org.mockito.InOrder;
|
||||
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory;
|
||||
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests;
|
||||
import org.springframework.boot.web.server.PortInUseException;
|
||||
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests;
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
@@ -217,7 +216,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
|
||||
}
|
||||
|
||||
@Test
|
||||
protected void portClashOfPrimaryConnectorResultsInPortInUseException() throws IOException {
|
||||
void portClashOfPrimaryConnectorResultsInPortInUseException() throws IOException {
|
||||
doWithBlockedPort((port) -> {
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
|
||||
AbstractReactiveWebServerFactory factory = getFactory();
|
||||
@@ -228,8 +227,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
|
||||
});
|
||||
}
|
||||
|
||||
protected final void doWithBlockedPort(AbstractServletWebServerFactoryTests.BlockedPortAction action)
|
||||
throws IOException {
|
||||
private void doWithBlockedPort(BlockedPortAction action) throws IOException {
|
||||
int port = SocketUtils.findAvailableTcpPort(40000);
|
||||
ServerSocket serverSocket = new ServerSocket();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
@@ -248,9 +246,15 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleExceptionCausedByBlockedPortOnPrimaryConnector(RuntimeException ex, int blockedPort) {
|
||||
private void handleExceptionCausedByBlockedPortOnPrimaryConnector(RuntimeException ex, int blockedPort) {
|
||||
assertThat(ex).isInstanceOf(PortInUseException.class);
|
||||
assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort);
|
||||
}
|
||||
|
||||
public interface BlockedPortAction {
|
||||
|
||||
void run(int port);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user