Polish TomcatReactiveWebServerFactoryTests

See gh-17336
pull/17389/head
Johnny Lim 5 years ago committed by Andy Wilkinson
parent e1394d4b12
commit 0e7824cec1

@ -40,7 +40,6 @@ import org.mockito.InOrder;
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory;
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests; import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests;
import org.springframework.boot.web.server.PortInUseException; 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.http.server.reactive.HttpHandler;
import org.springframework.util.SocketUtils; import org.springframework.util.SocketUtils;
@ -217,7 +216,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
} }
@Test @Test
protected void portClashOfPrimaryConnectorResultsInPortInUseException() throws IOException { void portClashOfPrimaryConnectorResultsInPortInUseException() throws IOException {
doWithBlockedPort((port) -> { doWithBlockedPort((port) -> {
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> { assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
AbstractReactiveWebServerFactory factory = getFactory(); AbstractReactiveWebServerFactory factory = getFactory();
@ -228,8 +227,7 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
}); });
} }
protected final void doWithBlockedPort(AbstractServletWebServerFactoryTests.BlockedPortAction action) private void doWithBlockedPort(BlockedPortAction action) throws IOException {
throws IOException {
int port = SocketUtils.findAvailableTcpPort(40000); int port = SocketUtils.findAvailableTcpPort(40000);
ServerSocket serverSocket = new ServerSocket(); ServerSocket serverSocket = new ServerSocket();
for (int i = 0; i < 10; i++) { 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(ex).isInstanceOf(PortInUseException.class);
assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort); assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort);
} }
public interface BlockedPortAction {
void run(int port);
}
} }

Loading…
Cancel
Save