Convert remaining samples to use random port

Partial fix for gh-337. See also gh-607 which complements this, but might
conflict on a merge.
This commit is contained in:
Dave Syer
2014-04-17 20:25:50 -07:00
parent f134e96053
commit 7b07fe8ce0
23 changed files with 239 additions and 72 deletions

View File

@@ -16,6 +16,8 @@
package samples.websocket.echo;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -35,6 +37,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.SocketUtils;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
@@ -44,8 +47,6 @@ import samples.websocket.client.SimpleGreetingService;
import samples.websocket.config.SampleWebSocketsApplication;
import samples.websocket.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { SampleWebSocketsApplication.class,
CustomContainerConfiguration.class })
@@ -56,14 +57,16 @@ public class CustomContainerWebSocketsApplicationTests {
private static Log logger = LogFactory
.getLog(CustomContainerWebSocketsApplicationTests.class);
private static int PORT = SocketUtils.findAvailableTcpPort();
private static final String WS_URI = "ws://localhost:9010/ws/echo/websocket";
private static final String WS_URI = "ws://localhost:" + PORT + "/ws/echo/websocket";
@Configuration
protected static class CustomContainerConfiguration {
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
return new TomcatEmbeddedServletContainerFactory("/ws", 9010);
return new TomcatEmbeddedServletContainerFactory("/ws", PORT);
}
}

View File

@@ -16,13 +16,17 @@
package samples.websocket.echo;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.IntegrationTest;
@@ -41,18 +45,24 @@ import samples.websocket.client.SimpleClientWebSocketHandler;
import samples.websocket.client.SimpleGreetingService;
import samples.websocket.config.SampleWebSocketsApplication;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleWebSocketsApplication.class)
@WebAppConfiguration
@IntegrationTest
@IntegrationTest("server.port:0")
@DirtiesContext
public class SampleWebSocketsApplicationTests {
private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class);
private static final String WS_URI = "ws://localhost:8080/echo/websocket";
private static String WS_URI;
@Value("${local.server.port}")
private int port;
@Before
public void init() {
WS_URI = "ws://localhost:" + port + "/echo/websocket";
}
@Test
public void runAndWait() throws Exception {