|
|
@ -763,18 +763,14 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|
|
|
public void portClashOfPrimaryConnectorResultsInPortInUseException()
|
|
|
|
public void portClashOfPrimaryConnectorResultsInPortInUseException()
|
|
|
|
throws IOException {
|
|
|
|
throws IOException {
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
|
|
|
|
doWithBlockedPort(new BlockedPortAction() {
|
|
|
|
final int port = SocketUtils.findAvailableTcpPort(40000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
factory.setPort(port);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.container = factory.getEmbeddedServletContainer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doWithBlockedPort(port, new Runnable() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run(int port) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
factory.setPort(port);
|
|
|
|
|
|
|
|
AbstractEmbeddedServletContainerFactoryTests.this.container = factory
|
|
|
|
|
|
|
|
.getEmbeddedServletContainer();
|
|
|
|
AbstractEmbeddedServletContainerFactoryTests.this.container.start();
|
|
|
|
AbstractEmbeddedServletContainerFactoryTests.this.container.start();
|
|
|
|
fail();
|
|
|
|
fail();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -784,25 +780,21 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void portClashOfSecondaryConnectorResultsInPortInUseException()
|
|
|
|
public void portClashOfSecondaryConnectorResultsInPortInUseException()
|
|
|
|
throws IOException {
|
|
|
|
throws IOException {
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
doWithBlockedPort(new BlockedPortAction() {
|
|
|
|
factory.setPort(SocketUtils.findAvailableTcpPort(40000));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final int port = SocketUtils.findAvailableTcpPort(40000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addConnector(port, factory);
|
|
|
|
|
|
|
|
this.container = factory.getEmbeddedServletContainer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doWithBlockedPort(port, new Runnable() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run(int port) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
|
|
|
|
|
|
|
factory.setPort(SocketUtils.findAvailableTcpPort(40000));
|
|
|
|
|
|
|
|
addConnector(port, factory);
|
|
|
|
|
|
|
|
AbstractEmbeddedServletContainerFactoryTests.this.container = factory
|
|
|
|
|
|
|
|
.getEmbeddedServletContainer();
|
|
|
|
AbstractEmbeddedServletContainerFactoryTests.this.container.start();
|
|
|
|
AbstractEmbeddedServletContainerFactoryTests.this.container.start();
|
|
|
|
fail();
|
|
|
|
fail();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -998,12 +990,19 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|
|
|
return bean;
|
|
|
|
return bean;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected final void doWithBlockedPort(final int port, Runnable action)
|
|
|
|
protected final void doWithBlockedPort(BlockedPortAction action) throws IOException {
|
|
|
|
throws IOException {
|
|
|
|
int port = SocketUtils.findAvailableTcpPort(40000);
|
|
|
|
ServerSocket serverSocket = new ServerSocket();
|
|
|
|
ServerSocket serverSocket = new ServerSocket();
|
|
|
|
serverSocket.bind(new InetSocketAddress(port));
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
serverSocket.bind(new InetSocketAddress(port));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
action.run();
|
|
|
|
action.run(port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
finally {
|
|
|
|
serverSocket.close();
|
|
|
|
serverSocket.close();
|
|
|
@ -1051,4 +1050,10 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface BlockedPortAction {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void run(int port);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|