From ecadea41202245888cbf199930166dc24e1b6361 Mon Sep 17 00:00:00 2001 From: Gunnar Hillert Date: Fri, 7 Dec 2012 00:07:20 -0500 Subject: [PATCH] INTSAMPLES-79 - Update TCP Samples to Use S-I-IP TestingUtilities * Also: Don't use hard-coded port in *tcp-client-server-multiplex* sample For reference: https://jira.springsource.org/browse/INTSAMPLES-79 --- basic/tcp-client-server/pom.xml | 5 + .../tcpclientserver/support/SocketUtils.java | 44 --------- .../TcpClientServerDemoTest.java | 5 +- ...ntServerDemoWithConversionServiceTest.java | 5 +- .../TcpServerConnectionDeserializeTest.java | 97 ++++++++++--------- .../TcpServerCustomSerializerTest.java | 4 +- .../support/CustomTestContextLoader.java | 1 + .../tcpclientserver/support/ServerUtils.java | 44 --------- .../tcp-client-server-multiplex/pom.xml | 5 + ...tcpClientServerDemo-conversion-context.xml | 12 ++- .../TcpClientServerDemoTest.java | 9 +- .../support/CustomTestContextLoader.java | 56 +++++++++++ .../tcpclientserver/support/ServerUtils.java | 45 --------- 13 files changed, 138 insertions(+), 194 deletions(-) delete mode 100644 basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/support/SocketUtils.java delete mode 100644 basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/ServerUtils.java create mode 100644 intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java delete mode 100644 intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/support/ServerUtils.java diff --git a/basic/tcp-client-server/pom.xml b/basic/tcp-client-server/pom.xml index 5d89671f..d3ad7dea 100644 --- a/basic/tcp-client-server/pom.xml +++ b/basic/tcp-client-server/pom.xml @@ -33,6 +33,11 @@ spring-integration-ip ${spring.integration.version} + + org.springframework.integration + spring-integration-test + ${spring.integration.version} + log4j log4j diff --git a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/support/SocketUtils.java b/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/support/SocketUtils.java deleted file mode 100644 index cf0bec8b..00000000 --- a/basic/tcp-client-server/src/main/java/org/springframework/integration/samples/tcpclientserver/support/SocketUtils.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.samples.tcpclientserver.support; - -import java.net.ServerSocket; - -import javax.net.ServerSocketFactory; - -/** - * - * @author Gunnar Hillert - * - */ -public final class SocketUtils { - - public static int findAvailableServerSocket(int seed) { - for (int i = seed; i < seed+200; i++) { - try { - ServerSocket sock = ServerSocketFactory.getDefault().createServerSocket(i); - sock.close(); - return i; - } catch (Exception e) { } - } - throw new RuntimeException("Cannot find a free server socket"); - } - - public static int findAvailableServerSocket() { - return findAvailableServerSocket(5678); - } - -} diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoTest.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoTest.java index da807e65..7113232f 100644 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoTest.java +++ b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoTest.java @@ -22,8 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; +import org.springframework.integration.ip.util.TestingUtilities; import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader; -import org.springframework.integration.samples.tcpclientserver.support.ServerUtils; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -40,6 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * Strings. * * @author Gary Russell + * @author Gunnar Hillert * */ // This one uses transformers @@ -56,7 +57,7 @@ public class TcpClientServerDemoTest { @Before public void setup() { - ServerUtils.waitListening(this.crLfServer); + TestingUtilities.waitListening(this.crLfServer, 10000L); } @Test diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoWithConversionServiceTest.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoWithConversionServiceTest.java index b54f2dd2..f897b9b0 100644 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoWithConversionServiceTest.java +++ b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoWithConversionServiceTest.java @@ -22,8 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; +import org.springframework.integration.ip.util.TestingUtilities; import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader; -import org.springframework.integration.samples.tcpclientserver.support.ServerUtils; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -41,6 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * Strings. * * @author Gary Russell + * @author Gunnar Hillert * */ @ContextConfiguration(loader=CustomTestContextLoader.class, locations={"/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml"}) @@ -56,7 +57,7 @@ public class TcpClientServerDemoWithConversionServiceTest { @Before public void setup() { - ServerUtils.waitListening(this.crLfServer); + TestingUtilities.waitListening(this.crLfServer, 10000L); } @Test diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerConnectionDeserializeTest.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerConnectionDeserializeTest.java index 21daec4a..6044fa28 100644 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerConnectionDeserializeTest.java +++ b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerConnectionDeserializeTest.java @@ -15,6 +15,10 @@ */ package org.springframework.integration.samples.tcpclientserver; +import static org.junit.Assert.assertEquals; + +import java.io.StringWriter; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -26,16 +30,12 @@ import org.springframework.integration.core.SubscribableChannel; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; import org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer; +import org.springframework.integration.ip.util.TestingUtilities; import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader; -import org.springframework.integration.samples.tcpclientserver.support.ServerUtils; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.io.StringWriter; - -import static org.junit.Assert.assertEquals; - /** * Shows an example of using the Stx/Etx stream framing serializers that are included with * Spring Integration. We can be confident that the streams are properly handled because we @@ -45,6 +45,7 @@ import static org.junit.Assert.assertEquals; * we create and attach to the incomingServerChannel), does not have any of the Stx/Etx bytes. * * @author: ceposta + * @author Gunnar Hillert */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader=CustomTestContextLoader.class, @@ -52,62 +53,62 @@ import static org.junit.Assert.assertEquals; @DirtiesContext public class TcpServerConnectionDeserializeTest { - @Autowired + @Autowired SimpleGateway gw; - @Autowired - @Qualifier("incomingServerChannel") - MessageChannel incomingServerChannel; + @Autowired + @Qualifier("incomingServerChannel") + MessageChannel incomingServerChannel; @Autowired AbstractServerConnectionFactory crLfServer; @Before public void setup() { - ServerUtils.waitListening(this.crLfServer); + TestingUtilities.waitListening(this.crLfServer, 10000L); } - @Test - public void testHappyPath() { + @Test + public void testHappyPath() { - // add a listener to this channel, otherwise there is not one defined - // the reason we use a listener here is so we can assert truths on the - // message and/or payload - SubscribableChannel channel = (SubscribableChannel) incomingServerChannel; - channel.subscribe(new AbstractReplyProducingMessageHandler(){ + // add a listener to this channel, otherwise there is not one defined + // the reason we use a listener here is so we can assert truths on the + // message and/or payload + SubscribableChannel channel = (SubscribableChannel) incomingServerChannel; + channel.subscribe(new AbstractReplyProducingMessageHandler(){ - @Override - protected Object handleRequestMessage(Message requestMessage) { - byte[] payload = (byte[]) requestMessage.getPayload(); + @Override + protected Object handleRequestMessage(Message requestMessage) { + byte[] payload = (byte[]) requestMessage.getPayload(); - // we assert during the processing of the messaging that the - // payload is just the content we wanted to send without the - // framing bytes (STX/ETX) - assertEquals("Hello World!", new String(payload)); - return requestMessage; - } - }); + // we assert during the processing of the messaging that the + // payload is just the content we wanted to send without the + // framing bytes (STX/ETX) + assertEquals("Hello World!", new String(payload)); + return requestMessage; + } + }); - String sourceMessage = wrapWithStxEtx("Hello World!"); - String result = gw.send(sourceMessage); - System.out.println(result); - assertEquals("Hello World!", result); - } + String sourceMessage = wrapWithStxEtx("Hello World!"); + String result = gw.send(sourceMessage); + System.out.println(result); + assertEquals("Hello World!", result); + } - /** - * Show, explicitly, how the stream would look if you had to manually create it. - * - * See more about TCP synchronous communication for more about framing the stream - * with STX/ETX: http://en.wikipedia.org/wiki/Binary_Synchronous_Communications - * - * @param content - * @return a string that is wrapped with the STX/ETX framing bytes - */ - private String wrapWithStxEtx(String content) { - StringWriter writer = new StringWriter(); - writer.write(ByteArrayStxEtxSerializer.STX); - writer.write(content); - writer.write(ByteArrayStxEtxSerializer.ETX); - return writer.toString(); - } + /** + * Show, explicitly, how the stream would look if you had to manually create it. + * + * See more about TCP synchronous communication for more about framing the stream + * with STX/ETX: http://en.wikipedia.org/wiki/Binary_Synchronous_Communications + * + * @param content + * @return a string that is wrapped with the STX/ETX framing bytes + */ + private String wrapWithStxEtx(String content) { + StringWriter writer = new StringWriter(); + writer.write(ByteArrayStxEtxSerializer.STX); + writer.write(content); + writer.write(ByteArrayStxEtxSerializer.ETX); + return writer.toString(); + } } diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerCustomSerializerTest.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerCustomSerializerTest.java index a6afc136..970892a4 100644 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerCustomSerializerTest.java +++ b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpServerCustomSerializerTest.java @@ -38,8 +38,8 @@ import org.springframework.integration.MessageChannel; import org.springframework.integration.core.SubscribableChannel; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; +import org.springframework.integration.ip.util.TestingUtilities; import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader; -import org.springframework.integration.samples.tcpclientserver.support.ServerUtils; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -74,7 +74,7 @@ public class TcpServerCustomSerializerTest { @Before public void setup() { - ServerUtils.waitListening(serverConnectionFactory); + TestingUtilities.waitListening(this.serverConnectionFactory, 10000L); } @Test diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java index 372d257f..e0d8793d 100644 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java +++ b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.log4j.Logger; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.env.MapPropertySource; +import org.springframework.integration.test.util.SocketUtils; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.support.GenericXmlContextLoader; diff --git a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/ServerUtils.java b/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/ServerUtils.java deleted file mode 100644 index 18ca7ca2..00000000 --- a/basic/tcp-client-server/src/test/java/org/springframework/integration/samples/tcpclientserver/support/ServerUtils.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.samples.tcpclientserver.support; - -import static org.junit.Assert.fail; - -import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; - -/** - * @author Gary Russell - * - */ -public class ServerUtils { - - public static void waitListening(AbstractServerConnectionFactory serverConnectionFactory) { - int n = 0; - while (!serverConnectionFactory.isListening()) { - - try { - Thread.sleep(100); - } catch (InterruptedException e1) { - throw new IllegalStateException(e1); - } - - if (n++ > 100) { - fail("Server didn't begin listening."); - } - } - } - -} diff --git a/intermediate/tcp-client-server-multiplex/pom.xml b/intermediate/tcp-client-server-multiplex/pom.xml index 84b456e1..ef1d51c0 100644 --- a/intermediate/tcp-client-server-multiplex/pom.xml +++ b/intermediate/tcp-client-server-multiplex/pom.xml @@ -25,6 +25,11 @@ spring-integration-ip ${spring.integration.version} + + org.springframework.integration + spring-integration-test + ${spring.integration.version} + log4j log4j diff --git a/intermediate/tcp-client-server-multiplex/src/main/resources/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml b/intermediate/tcp-client-server-multiplex/src/main/resources/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml index 2a0765e8..e6bbec33 100644 --- a/intermediate/tcp-client-server-multiplex/src/main/resources/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml +++ b/intermediate/tcp-client-server-multiplex/src/main/resources/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml @@ -3,14 +3,18 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/integration" xmlns:ip="http://www.springframework.org/schema/integration/ip" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd - http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd"> + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> Uses conversion service and collaborating channel adapters. + + @@ -31,7 +35,7 @@ diff --git a/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoTest.java b/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoTest.java index d5db944e..4f0b6ff0 100644 --- a/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoTest.java +++ b/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/TcpClientServerDemoTest.java @@ -30,7 +30,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; -import org.springframework.integration.samples.tcpclientserver.support.ServerUtils; +import org.springframework.integration.ip.util.TestingUtilities; +import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -46,8 +48,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @since 2.1 * */ -@ContextConfiguration("/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml") +@ContextConfiguration(loader=CustomTestContextLoader.class, locations={"/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml"}) @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class TcpClientServerDemoTest { @Autowired @@ -58,7 +61,7 @@ public class TcpClientServerDemoTest { @Before public void setup() { - ServerUtils.waitListening(this.crLfServer); + TestingUtilities.waitListening(this.crLfServer, 10000L); } @Test diff --git a/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java b/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java new file mode 100644 index 00000000..0139a442 --- /dev/null +++ b/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/support/CustomTestContextLoader.java @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.samples.tcpclientserver.support; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.env.MapPropertySource; +import org.springframework.integration.test.util.SocketUtils; +import org.springframework.test.context.MergedContextConfiguration; +import org.springframework.test.context.support.GenericXmlContextLoader; + +/** + * + * @author Gunnar Hillert + * + */ +public class CustomTestContextLoader extends GenericXmlContextLoader { + + private static final Logger LOGGER = Logger.getLogger(CustomTestContextLoader.class); + + @Override + protected void loadBeanDefinitions(GenericApplicationContext context, + MergedContextConfiguration mergedConfig) { + + int availableServerSocket = SocketUtils.findAvailableServerSocket(5678); + + final Map sockets = new HashMap(); + sockets.put("availableServerSocket", availableServerSocket); + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Available Server Socket: " + availableServerSocket); + } + + final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); + + context.getEnvironment().getPropertySources().addLast(propertySource); + super.loadBeanDefinitions(context, mergedConfig); + } + +} diff --git a/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/support/ServerUtils.java b/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/support/ServerUtils.java deleted file mode 100644 index 28333a3b..00000000 --- a/intermediate/tcp-client-server-multiplex/src/test/java/org/springframework/integration/samples/tcpclientserver/support/ServerUtils.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2002-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.samples.tcpclientserver.support; - -import static org.junit.Assert.fail; - -import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; - -/** - * @author Gary Russell - * - */ -public class ServerUtils { - - public static void waitListening(AbstractServerConnectionFactory serverConnectionFactory) { - int n = 0; - while (!serverConnectionFactory.isListening()) { - - try { - Thread.sleep(100); - } catch (InterruptedException e1) { - Thread.currentThread().interrupt(); - throw new IllegalStateException(e1); - } - - if (n++ > 100) { - fail("Server didn't begin listening."); - } - } - } - -}