INT-2564 Move Some SocketTestUtils to Test Module

Move SocketTestUtils.findAvailableServerSocket to Test Module

For reference see: https://jira.springsource.org/browse/INT-2564

* Move SocketTestUtils.findAvailableServerSocket to Spring Integration Test Module
* Fix tests
This commit is contained in:
Gunnar Hillert
2012-06-20 14:57:14 -04:00
committed by Gary Russell
parent f505d426a2
commit 0269de0f98
29 changed files with 518 additions and 257 deletions

View File

@@ -782,6 +782,7 @@ project('spring-integration-test') {
'org.apache.tools.ant.*;version="[1.7.0, 2.0.0)"',
'org.springframework.*;version="[3.1.1, 4.0.0)"',
'org.springframework.integration.*;version="[2.2.0, 2.2.1)"',
'javax.net.*;version="0"',
'junit.framework.*;version="[4.6.0, 4.7.0)"',
'org.junit.*;version="[4.6.0, 4.7.0)"',
'org.mockito.*;version="[1.6.0, 2.0.0)"',

View File

@@ -13,7 +13,7 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<int:channel id="udpChannel" />

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<ip:tcp-connection-factory id="cfS1"
type="server"

View File

@@ -8,7 +8,7 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<int:channel id="in"/>

View File

@@ -11,7 +11,7 @@
<int:message-history/>
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<int-ip:tcp-connection-factory id="server"
type="server"
@@ -37,11 +37,11 @@
connection-factory="server"
reply-timeout="1"
/>
<int:channel id="queue">
<int:queue/>
</int:channel>
<task:executor id="exec" pool-size="10"/>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* 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.
@@ -18,7 +18,7 @@ package org.springframework.integration.ip.tcp;
import org.junit.Test;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.test.util.SocketUtils;
/**
@@ -27,10 +27,10 @@ import org.springframework.integration.ip.util.SocketTestUtils;
*
*/
public class FactoryStopStartTests {
@Test
public void testRestart() {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory factory = new TcpNetServerConnectionFactory(port);
factory.setSoTimeout(10000);
factory.start();

View File

@@ -7,12 +7,12 @@
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">
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<bean id="serializer" class="org.springframework.core.serializer.DefaultSerializer" />
<bean id="deserializer" class="org.springframework.core.serializer.DefaultDeserializer" />
<bean id="helloWorldInterceptors" class="org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain">
<property name="interceptors">
<array>
@@ -24,7 +24,7 @@
</array>
</property>
</bean>
<int-ip:tcp-connection-factory id="server"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(10100)}"
@@ -46,9 +46,9 @@
deserializer="deserializer"
interceptor-factory-chain="helloWorldInterceptors"
/>
<int:channel id="input" />
<int:channel id="replies">
<int:queue/>
</int:channel>
@@ -56,15 +56,15 @@
<int-ip:tcp-outbound-channel-adapter id="outboundClient"
channel="input"
connection-factory="client"/>
<int-ip:tcp-inbound-channel-adapter id="inboundClient"
channel="replies"
connection-factory="client"/>
connection-factory="client"/>
<int-ip:tcp-inbound-channel-adapter id="inboundServer"
channel="loop"
connection-factory="server"/>
<int-ip:tcp-outbound-channel-adapter id="outboundServer"
channel="loop"
connection-factory="server"/>

View File

@@ -9,7 +9,7 @@
<int:message-history/>
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<bean id="serializer" class="org.springframework.core.serializer.DefaultSerializer" />

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* 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.
@@ -48,16 +48,16 @@ import org.springframework.integration.ip.tcp.connection.AbstractServerConnectio
import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.channel.ChannelResolver;
import org.springframework.integration.test.util.SocketUtils;
public class TcpInboundGatewayTests {
@Test
public void testNetSingle() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
scf.setSingleUse(true);
TcpInboundGateway gateway = new TcpInboundGateway();
@@ -87,7 +87,7 @@ public class TcpInboundGatewayTests {
@Test
public void testNetNotSingle() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
scf.setSingleUse(false);
TcpInboundGateway gateway = new TcpInboundGateway();
@@ -111,7 +111,7 @@ public class TcpInboundGatewayTests {
@Test
public void testNetClientMode() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractClientConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
ccf.setSingleUse(false);
TcpInboundGateway gateway = new TcpInboundGateway();
@@ -166,7 +166,7 @@ public class TcpInboundGatewayTests {
@Test
public void testNioSingle() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
scf.setSingleUse(true);
TcpInboundGateway gateway = new TcpInboundGateway();
@@ -196,7 +196,7 @@ public class TcpInboundGatewayTests {
@Test
public void testNioNotSingle() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
scf.setSingleUse(false);
TcpInboundGateway gateway = new TcpInboundGateway();
@@ -223,7 +223,7 @@ public class TcpInboundGatewayTests {
@Test
public void testErrorFlow() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
scf.setSingleUse(true);
TcpInboundGateway gateway = new TcpInboundGateway();

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<int-ip:tcp-connection-factory
id="scf"

View File

@@ -45,8 +45,8 @@ import org.springframework.integration.MessageTimeoutException;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.SocketUtils;
import org.springframework.integration.test.util.TestUtils;
/**
@@ -57,7 +57,7 @@ public class TcpOutboundGatewayTests {
@Test
public void testGoodNetSingle() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
@@ -118,7 +118,7 @@ public class TcpOutboundGatewayTests {
@Test
public void testGoodNetMultiplex() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -170,7 +170,7 @@ public class TcpOutboundGatewayTests {
@Test
public void testGoodNetTimeout() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* 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.
@@ -56,8 +56,8 @@ import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionF
import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory;
import org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.test.util.SocketUtils;
/**
* @author Gary Russell
@@ -66,7 +66,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNet() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -91,7 +91,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNetClientMode() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
@@ -141,7 +141,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNio() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -170,7 +170,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNetShared() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -202,7 +202,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNioShared() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -234,7 +234,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNetSingleNoOutbound() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -264,7 +264,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNioSingleNoOutbound() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -304,7 +304,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNetSingleShared() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -339,7 +339,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNioSingleShared() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -374,7 +374,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNioSingleSharedMany() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
@@ -412,42 +412,42 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testNetInterceptors() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
interceptorsGuts(port, scf);
}
@Test
public void testNetSingleNoOutboundInterceptors() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
singleNoOutboundInterceptorsGuts(port, scf);
}
@Test
public void testNetSingleSharedInterceptors() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
singleSharedInterceptorsGuts(port, scf);
}
@Test
public void testNioInterceptors() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
interceptorsGuts(port, scf);
}
@Test
public void testNioSingleNoOutboundInterceptors() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
singleNoOutboundInterceptorsGuts(port, scf);
}
@Test
public void testNioSingleSharedInterceptors() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
singleSharedInterceptorsGuts(port, scf);
}
@@ -576,7 +576,7 @@ public class TcpReceivingChannelAdapterTests {
@Test
public void testException() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);

View File

@@ -61,10 +61,10 @@ import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionF
import org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer;
import org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer;
import org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.SocketUtils;
/**
* @author Gary Russell
@@ -84,7 +84,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetCrLf() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -134,7 +134,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetCrLfClientMode() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -191,7 +191,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioCrLf() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -243,7 +243,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetStxEtx() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -292,7 +292,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioStxEtx() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -344,7 +344,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetLength() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -396,7 +396,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioLength() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -451,7 +451,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetSerial() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -499,7 +499,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioSerial() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -550,7 +550,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetSingleUseNoInbound() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final Semaphore semaphore = new Semaphore(0);
final AtomicBoolean done = new AtomicBoolean();
@@ -594,7 +594,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioSingleUseNoInbound() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final Semaphore semaphore = new Semaphore(0);
final AtomicBoolean done = new AtomicBoolean();
@@ -638,7 +638,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetSingleUseWithInbound() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final Semaphore semaphore = new Semaphore(0);
final AtomicBoolean done = new AtomicBoolean();
@@ -695,7 +695,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioSingleUseWithInbound() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final Semaphore semaphore = new Semaphore(0);
final AtomicBoolean done = new AtomicBoolean();
@@ -752,7 +752,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioSingleUseWithInboundMany() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final Semaphore semaphore = new Semaphore(0);
final AtomicBoolean done = new AtomicBoolean();
@@ -820,7 +820,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetNegotiate() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -887,7 +887,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioNegotiate() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -952,7 +952,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNetNegotiateSingleNoListen() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -1009,7 +1009,7 @@ public class TcpSendingMessageHandlerTests {
@Test
public void testNioNegotiateSingleNoListen() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {

View File

@@ -10,7 +10,7 @@
http://www.springframework.org/schema/integration/ip
http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<bean id="crLfSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer" />
<bean id="stxEtxSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer" />

View File

@@ -21,8 +21,8 @@ import java.net.Socket;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.test.util.SocketUtils;
import org.springframework.integration.test.util.TestUtils;
/**
@@ -34,7 +34,7 @@ public class DefaultTimeoutTests {
@Test
public void test() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
TcpNetServerConnectionFactory server = new TcpNetServerConnectionFactory(port);
server.registerListener(new TcpListener() {
public boolean onMessage(Message<?> message) {

View File

@@ -49,9 +49,9 @@ import org.springframework.integration.core.SubscribableChannel;
import org.springframework.integration.ip.IpHeaders;
import org.springframework.integration.ip.tcp.TcpInboundGateway;
import org.springframework.integration.ip.tcp.TcpOutboundGateway;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.test.util.SocketUtils;
import org.springframework.integration.test.util.TestUtils;
/**
@@ -226,8 +226,11 @@ public class FailoverClientConnectionFactoryTests {
@Test
public void testRealNet() throws Exception {
int port1 = SocketTestUtils.findAvailableServerSocket();
int port2 = SocketTestUtils.findAvailableServerSocket(port1 + 1);
final List<Integer> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2);
int port1 = openPorts.get(0);
int port2 = openPorts.get(1);
AbstractClientConnectionFactory client1 = new TcpNetClientConnectionFactory("localhost", port1);
AbstractClientConnectionFactory client2 = new TcpNetClientConnectionFactory("localhost", port2);
AbstractServerConnectionFactory server1 = new TcpNetServerConnectionFactory(port1);
@@ -237,8 +240,12 @@ public class FailoverClientConnectionFactoryTests {
@Test
public void testRealNio() throws Exception {
int port1 = SocketTestUtils.findAvailableServerSocket();
int port2 = SocketTestUtils.findAvailableServerSocket(port1 + 1);
final List<Integer> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2);
int port1 = openPorts.get(0);
int port2 = openPorts.get(1);
AbstractClientConnectionFactory client1 = new TcpNioClientConnectionFactory("localhost", port1);
AbstractClientConnectionFactory client2 = new TcpNioClientConnectionFactory("localhost", port2);
AbstractServerConnectionFactory server1 = new TcpNioServerConnectionFactory(port1);
@@ -248,8 +255,12 @@ public class FailoverClientConnectionFactoryTests {
@Test
public void testRealNetSingleUse() throws Exception {
int port1 = SocketTestUtils.findAvailableServerSocket();
int port2 = SocketTestUtils.findAvailableServerSocket(port1 + 1);
final List<Integer> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2);
int port1 = openPorts.get(0);
int port2 = openPorts.get(1);
AbstractClientConnectionFactory client1 = new TcpNetClientConnectionFactory("localhost", port1);
AbstractClientConnectionFactory client2 = new TcpNetClientConnectionFactory("localhost", port2);
AbstractServerConnectionFactory server1 = new TcpNetServerConnectionFactory(port1);
@@ -261,8 +272,12 @@ public class FailoverClientConnectionFactoryTests {
@Test
public void testRealNioSingleUse() throws Exception {
int port1 = SocketTestUtils.findAvailableServerSocket();
int port2 = SocketTestUtils.findAvailableServerSocket(port1 + 1);
final List<Integer> openPorts = SocketUtils.findAvailableServerSockets(SocketUtils.getRandomSeedPort(), 2);
int port1 = openPorts.get(0);
int port2 = openPorts.get(1);
AbstractClientConnectionFactory client1 = new TcpNioClientConnectionFactory("localhost", port1);
AbstractClientConnectionFactory client2 = new TcpNioClientConnectionFactory("localhost", port2);
AbstractServerConnectionFactory server1 = new TcpNioServerConnectionFactory(port1);

View File

@@ -7,18 +7,18 @@
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">
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketTestUtils" />
<bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
<int-ip:tcp-connection-factory id="inCFNet"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(9000)}"
so-timeout="1000"
single-use="true"
/>
<int-ip:tcp-inbound-gateway request-channel="echo"
connection-factory="inCFNet" />
<int-ip:tcp-connection-factory id="inCFNio"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(9100)}"
@@ -26,10 +26,10 @@
single-use="true"
using-nio="true"
/>
<int-ip:tcp-inbound-gateway request-channel="echo"
connection-factory="inCFNio" />
<int-ip:tcp-connection-factory id="inCFNetRst"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(9200)}"
@@ -37,10 +37,10 @@
single-use="true"
so-linger="0"
/>
<int-ip:tcp-inbound-gateway request-channel="echo"
connection-factory="inCFNetRst" />
<int-ip:tcp-connection-factory id="inCFNioRst"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(9300)}"
@@ -49,10 +49,10 @@
using-nio="true"
so-linger="0"
/>
<int-ip:tcp-inbound-gateway request-channel="echo"
connection-factory="inCFNioRst" />
<int-ip:tcp-connection-factory id="inCFNetLinger"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(9400)}"
@@ -60,10 +60,10 @@
single-use="true"
so-linger="1000"
/>
<int-ip:tcp-inbound-gateway request-channel="echo"
connection-factory="inCFNetLinger" />
<int-ip:tcp-connection-factory id="inCFNioLinger"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(9500)}"
@@ -72,12 +72,12 @@
using-nio="true"
so-linger="1000"
/>
<int-ip:tcp-inbound-gateway request-channel="echo"
connection-factory="inCFNioLinger" />
<int:service-activator input-channel="echo" ref="testService"/>
<bean id="testService" class="org.springframework.integration.ip.tcp.TestService"/>
</beans>

View File

@@ -47,9 +47,9 @@ import org.springframework.integration.ip.tcp.connection.support.TcpSSLContextSu
import org.springframework.integration.ip.tcp.connection.support.TcpSocketFactorySupport;
import org.springframework.integration.ip.tcp.connection.support.TcpSocketSupport;
import org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.test.util.SocketUtils;
import org.springframework.integration.test.util.TestUtils;
/**
@@ -122,7 +122,7 @@ public class SocketSupportTests {
@Test
public void testNioClientAndServer() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
TcpNioClientConnectionFactory clientConnectionFactory = new TcpNioClientConnectionFactory("localhost", port);
final AtomicInteger ppSocketCountClient = new AtomicInteger();
final AtomicInteger ppServerSocketCountClient = new AtomicInteger();
@@ -264,7 +264,7 @@ Certificate fingerprints:
@Test
public void testNetClientAndServerSSL() throws Exception {
System.setProperty("javax.net.debug", "all"); // SSL activity in the console
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
TcpNetServerConnectionFactory server = new TcpNetServerConnectionFactory(port);
TcpSSLContextSupport sslContextSupport = new DefaultTcpSSLContextSupport("test.ks",
"test.truststore.ks", "secret", "secret");
@@ -296,7 +296,7 @@ Certificate fingerprints:
@Test
public void testNetClientAndServerSSLDifferentContexts() throws Exception {
System.setProperty("javax.net.debug", "all"); // SSL activity in the console
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
TcpNetServerConnectionFactory server = new TcpNetServerConnectionFactory(port);
TcpSSLContextSupport serverSslContextSupport = new DefaultTcpSSLContextSupport("server.ks",
"server.truststore.ks", "secret", "secret");
@@ -332,7 +332,7 @@ Certificate fingerprints:
@Test
public void testNioClientAndServerSSL() throws Exception {
System.setProperty("javax.net.debug", "all"); // SSL activity in the console
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory server = new TcpNioServerConnectionFactory(port);
DefaultTcpSSLContextSupport sslContextSupport = new DefaultTcpSSLContextSupport("test.ks",
"test.truststore.ks", "secret", "secret");
@@ -372,7 +372,7 @@ Certificate fingerprints:
@Test
public void testNioClientAndServerSSLDifferentContextsLargeDataWithReply() throws Exception {
System.setProperty("javax.net.debug", "all"); // SSL activity in the console
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory server = new TcpNioServerConnectionFactory(port);
TcpSSLContextSupport serverSslContextSupport = new DefaultTcpSSLContextSupport("server.ks",
"server.truststore.ks", "secret", "secret");

View File

@@ -39,6 +39,7 @@ import org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSe
import org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.test.util.SocketUtils;
/**
* @author Gary Russell
@@ -73,7 +74,7 @@ public class TcpNioConnectionReadTests {
@SuppressWarnings("unchecked")
@Test
public void testReadLength() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayLengthHeaderSerializer serializer = new ByteArrayLengthHeaderSerializer();
final List<Message<?>> responses = new ArrayList<Message<?>>();
final Semaphore semaphore = new Semaphore(0);
@@ -104,7 +105,7 @@ public class TcpNioConnectionReadTests {
@SuppressWarnings("unchecked")
@Test
public void testFragmented() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayLengthHeaderSerializer serializer = new ByteArrayLengthHeaderSerializer();
final List<Message<?>> responses = new ArrayList<Message<?>>();
final Semaphore semaphore = new Semaphore(0);
@@ -138,7 +139,7 @@ public class TcpNioConnectionReadTests {
@SuppressWarnings("unchecked")
@Test
public void testReadStxEtx() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayStxEtxSerializer serializer = new ByteArrayStxEtxSerializer();
final List<Message<?>> responses = new ArrayList<Message<?>>();
final Semaphore semaphore = new Semaphore(0);
@@ -170,7 +171,7 @@ public class TcpNioConnectionReadTests {
@SuppressWarnings("unchecked")
@Test
public void testReadCrLf() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
final List<Message<?>> responses = new ArrayList<Message<?>>();
final Semaphore semaphore = new Semaphore(0);
@@ -201,7 +202,7 @@ public class TcpNioConnectionReadTests {
*/
@Test
public void testReadLengthOverflow() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayLengthHeaderSerializer serializer = new ByteArrayLengthHeaderSerializer();
final List<Message<?>> responses = new ArrayList<Message<?>>();
final Semaphore semaphore = new Semaphore(0);
@@ -239,7 +240,7 @@ public class TcpNioConnectionReadTests {
*/
@Test
public void testReadStxEtxOverflow() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayStxEtxSerializer serializer = new ByteArrayStxEtxSerializer();
serializer.setMaxMessageSize(1024);
final List<Message<?>> responses = new ArrayList<Message<?>>();
@@ -278,7 +279,7 @@ public class TcpNioConnectionReadTests {
*/
@Test
public void testReadCrLfOverflow() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
serializer.setMaxMessageSize(1024);
final List<Message<?>> responses = new ArrayList<Message<?>>();
@@ -319,7 +320,7 @@ public class TcpNioConnectionReadTests {
*/
@Test
public void testCloseCleanupNoData() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
serializer.setMaxMessageSize(1024);
final List<Message<?>> responses = new ArrayList<Message<?>>();
@@ -358,7 +359,7 @@ public class TcpNioConnectionReadTests {
*/
@Test
public void testCloseCleanupPartialData() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
serializer.setMaxMessageSize(1024);
final List<Message<?>> responses = new ArrayList<Message<?>>();
@@ -429,7 +430,7 @@ public class TcpNioConnectionReadTests {
private void testClosureMidMessageGuts(AbstractByteArraySerializer serializer, String shortMessage)
throws Exception, IOException, UnknownHostException,
InterruptedException {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final List<Message<?>> responses = new ArrayList<Message<?>>();
final Semaphore semaphore = new Semaphore(0);
final List<TcpConnection> added = new ArrayList<TcpConnection>();

View File

@@ -56,8 +56,8 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.integration.Message;
import org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.SocketUtils;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.FieldCallback;
@@ -75,7 +75,7 @@ public class TcpNioConnectionTests {
@Test
public void testWriteTimeout() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost", port);
factory.setSoTimeout(1000);
factory.start();
@@ -106,7 +106,7 @@ public class TcpNioConnectionTests {
@Test
public void testReadTimeout() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost", port);
factory.setSoTimeout(1000);
factory.start();
@@ -145,7 +145,7 @@ public class TcpNioConnectionTests {
@Test
public void testMemoryLeak() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost", port);
factory.setNioHarvestInterval(100);
factory.start();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* 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.
@@ -27,17 +27,16 @@ import java.nio.ByteBuffer;
import javax.net.ServerSocketFactory;
import org.junit.Test;
import org.springframework.integration.ip.tcp.serializer.AbstractByteArraySerializer;
import org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer;
import org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer;
import org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.SocketUtils;
/**
* @author Gary Russell
* @since 2.0
* @since 2.0
*/
public class TcpNioConnectionWriteTests {
@@ -51,10 +50,10 @@ public class TcpNioConnectionWriteTests {
ccf.start();
return ccf;
}
@Test
public void testWriteLengthHeader() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault()
.createServerSocket(port);
@@ -87,7 +86,7 @@ public class TcpNioConnectionWriteTests {
@Test
public void testWriteStxEtx() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault()
.createServerSocket(port);
@@ -120,7 +119,7 @@ public class TcpNioConnectionWriteTests {
@Test
public void testWriteCrLf() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault()
.createServerSocket(port);
@@ -153,7 +152,7 @@ public class TcpNioConnectionWriteTests {
@Test
public void testWriteLengthHeaderDirect() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault()
.createServerSocket(port);
@@ -186,7 +185,7 @@ public class TcpNioConnectionWriteTests {
@Test
public void testWriteStxEtxDirect() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault()
.createServerSocket(port);
@@ -220,7 +219,7 @@ public class TcpNioConnectionWriteTests {
@Test
public void testWriteCrLfDirect() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault()
.createServerSocket(port);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* 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.
@@ -26,9 +26,9 @@ import java.net.Socket;
import javax.net.ServerSocketFactory;
import org.junit.Test;
import org.springframework.core.serializer.DefaultDeserializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.test.util.SocketUtils;
/**
* @author Gary Russell
@@ -38,7 +38,7 @@ public class DeserializationTests {
@Test
public void testReadLength() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendLength(port, null);
@@ -46,17 +46,17 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayLengthHeaderSerializer serializer = new ByteArrayLengthHeaderSerializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
server.close();
}
@Test
public void testReadStxEtx() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendStxEtx(port, null);
@@ -64,17 +64,17 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayStxEtxSerializer serializer = new ByteArrayStxEtxSerializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
server.close();
}
@Test
public void testReadCrLf() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendCrLf(port, null);
@@ -82,17 +82,17 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
server.close();
}
@Test
public void testReadRaw() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendRaw(port);
@@ -100,14 +100,14 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayRawSerializer serializer = new ByteArrayRawSerializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
server.close();
}
@Test
public void testReadSerialized() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendSerialized(port);
@@ -123,7 +123,7 @@ public class DeserializationTests {
@Test
public void testReadLengthOverflow() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendLengthOverflow(port);
@@ -144,7 +144,7 @@ public class DeserializationTests {
@Test
public void testReadStxEtxTimeout() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendStxEtxOverflow(port);
@@ -165,7 +165,7 @@ public class DeserializationTests {
@Test
public void testReadStxEtxOverflow() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendStxEtxOverflow(port);
@@ -187,7 +187,7 @@ public class DeserializationTests {
@Test
public void testReadCrLfTimeout() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendCrLfOverflow(port);
@@ -208,7 +208,7 @@ public class DeserializationTests {
@Test
public void testReadCrLfOverflow() throws Exception {
int port = SocketTestUtils.findAvailableServerSocket();
int port = SocketUtils.findAvailableServerSocket();
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
SocketTestUtils.testSendCrLfOverflow(port);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* 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.
@@ -29,9 +29,8 @@ import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
import org.junit.Test;
import org.springframework.core.serializer.DefaultSerializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.test.util.SocketUtils;
/**
* @author Gary Russell
@@ -41,7 +40,7 @@ public class SerializationTests {
@Test
public void testWriteLengthHeader() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
@@ -74,7 +73,7 @@ public class SerializationTests {
@Test
public void testWriteStxEtx() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
@@ -107,7 +106,7 @@ public class SerializationTests {
@Test
public void testWriteCrLf() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
@@ -137,10 +136,10 @@ public class SerializationTests {
assertEquals('\n', buff[testString.length() + 1]);
server.close();
}
@Test
public void testWriteRaw() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
@@ -170,10 +169,10 @@ public class SerializationTests {
assertEquals(-1, buff[testString.length()]);
server.close();
}
@Test
public void testWriteSerialized() throws Exception {
final int port = SocketTestUtils.findAvailableServerSocket();
final int port = SocketUtils.findAvailableServerSocket();
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
server.setSoTimeout(10000);
@@ -201,7 +200,7 @@ public class SerializationTests {
assertEquals(testString, ois.readObject());
server.close();
}
/**
* @param is
* @param buff

View File

@@ -24,6 +24,7 @@ import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -34,8 +35,8 @@ import org.junit.Ignore;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.integration.ip.IpHeaders;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.SocketUtils;
/**
* @author Mark Fisher
@@ -45,10 +46,10 @@ import org.springframework.integration.support.MessageBuilder;
public class DatagramPacketSendingHandlerTests {
private boolean noMulticast;
@Test
public void verifySend() throws Exception {
final int testPort = SocketTestUtils.findAvailableUdpSocket();
final int testPort = SocketUtils.findAvailableUdpSocket();
byte[] buffer = new byte[8];
final DatagramPacket receivedPacket = new DatagramPacket(buffer, buffer.length);
final CountDownLatch latch = new CountDownLatch(1);
@@ -66,7 +67,7 @@ public class DatagramPacketSendingHandlerTests {
}
});
Thread.sleep(1000);
UnicastSendingMessageHandler handler =
UnicastSendingMessageHandler handler =
new UnicastSendingMessageHandler("localhost", testPort);
String payload = "foo";
handler.handleMessage(MessageBuilder.withPayload(payload).build());
@@ -82,14 +83,18 @@ public class DatagramPacketSendingHandlerTests {
@Test
public void verifySendWithAck() throws Exception {
final int testPort = SocketTestUtils.findAvailableUdpSocket();
final int ackPort = SocketTestUtils.findAvailableUdpSocket(testPort + 1);
final List<Integer> openPorts = SocketUtils.findAvailableUdpSockets(SocketUtils.getRandomSeedPort(), 2);
final int testPort = openPorts.get(0);
final int ackPort = openPorts.get(1);
byte[] buffer = new byte[1000];
final DatagramPacket receivedPacket = new DatagramPacket(buffer, buffer.length);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
UnicastSendingMessageHandler handler =
new UnicastSendingMessageHandler("localhost", testPort, true,
UnicastSendingMessageHandler handler =
new UnicastSendingMessageHandler("localhost", testPort, true,
true, "localhost", ackPort, 5000);
handler.afterPropertiesSet();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -105,7 +110,7 @@ public class DatagramPacketSendingHandlerTests {
Message<byte[]> message = mapper.toMessage(receivedPacket);
Object id = message.getHeaders().get(IpHeaders.ACK_ID);
byte[] ack = id.toString().getBytes();
DatagramPacket ackPack = new DatagramPacket(ack, ack.length,
DatagramPacket ackPack = new DatagramPacket(ack, ack.length,
new InetSocketAddress("localHost", ackPort));
DatagramSocket out = new DatagramSocket();
out.send(ackPack);
@@ -133,7 +138,7 @@ public class DatagramPacketSendingHandlerTests {
@Test
@Ignore
public void verifySendMulticast() throws Exception {
final int testPort = SocketTestUtils.findAvailableUdpSocket();
final int testPort = SocketUtils.findAvailableUdpSocket();
final String multicastAddress = "225.6.7.8";
final String payload = "foo";
final CountDownLatch latch1 = new CountDownLatch(2);
@@ -184,8 +189,12 @@ public class DatagramPacketSendingHandlerTests {
@Test
@Ignore
public void verifySendMulticastWithAcks() throws Exception {
final int testPort = SocketTestUtils.findAvailableUdpSocket();
final int ackPort = SocketTestUtils.findAvailableUdpSocket(testPort + 1);
final List<Integer> openPorts = SocketUtils.findAvailableUdpSockets(SocketUtils.getRandomSeedPort(), 2);
final int testPort = openPorts.get(0);
final int ackPort = openPorts.get(1);
final String multicastAddress = "225.6.7.8";
final String payload = "foobar";
final CountDownLatch latch1 = new CountDownLatch(2);
@@ -215,7 +224,7 @@ public class DatagramPacketSendingHandlerTests {
Message<byte[]> message = mapper.toMessage(receivedPacket);
Object id = message.getHeaders().get(IpHeaders.ACK_ID);
byte[] ack = id.toString().getBytes();
DatagramPacket ackPack = new DatagramPacket(ack, ack.length,
DatagramPacket ackPack = new DatagramPacket(ack, ack.length,
new InetSocketAddress("localHost", ackPort));
DatagramSocket out = new DatagramSocket();
out.send(ackPack);
@@ -236,13 +245,13 @@ public class DatagramPacketSendingHandlerTests {
if (noMulticast) {
return;
}
MulticastSendingMessageHandler handler =
new MulticastSendingMessageHandler(multicastAddress, testPort, true,
MulticastSendingMessageHandler handler =
new MulticastSendingMessageHandler(multicastAddress, testPort, true,
true, "localhost", ackPort, 500000);
handler.setMinAcksForSuccess(2);
handler.handleMessage(MessageBuilder.withPayload(payload).build());
assertTrue(latch2.await(10000, TimeUnit.MILLISECONDS));
handler.shutDown();
}
}

View File

@@ -24,11 +24,12 @@ import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.SocketUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/**
*
*
* For both .net. and .nio. adapters, creates a single server and 10 clients
* and sends 3 messages from each client to the associated server.
* Ensures that all messages are correctly assembled and received ok.
@@ -37,7 +38,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
* will cause messages to be lost.
* Even with this restriction, we are still testing the receiving adapter's
* ability to handle multiple requests from multiple clients.
*
*
* @author Gary Russell
*
*/
@@ -46,9 +47,9 @@ public class MultiClientTests {
@SuppressWarnings("unchecked")
@Test @Ignore
public void testNoAck() throws Exception {
final String payload = largePayload(1000);
final UnicastReceivingChannelAdapter adapter =
new UnicastReceivingChannelAdapter(SocketTestUtils.findAvailableUdpSocket());
final String payload = largePayload(1000);
final UnicastReceivingChannelAdapter adapter =
new UnicastReceivingChannelAdapter(SocketUtils.findAvailableUdpSocket());
int drivers = 10;
adapter.setPoolSize(drivers);
QueueChannel queue = new QueueChannel(drivers * 3);
@@ -87,9 +88,9 @@ public class MultiClientTests {
@Test @Ignore
public void testAck() throws Exception {
Thread.sleep(1000);
final String payload = largePayload(1000);
final UnicastReceivingChannelAdapter adapter =
new UnicastReceivingChannelAdapter(SocketTestUtils.findAvailableUdpSocket(), false);
final String payload = largePayload(1000);
final UnicastReceivingChannelAdapter adapter =
new UnicastReceivingChannelAdapter(SocketUtils.findAvailableUdpSocket(), false);
int drivers = 5;
adapter.setPoolSize(drivers);
QueueChannel queue = new QueueChannel(drivers * 3);
@@ -107,7 +108,7 @@ public class MultiClientTests {
UnicastSendingMessageHandler sender = new UnicastSendingMessageHandler(
"localhost", adapter.getPort(),
false, true, "localhost",
SocketTestUtils.findAvailableUdpSocket(adapter.getPort() + j + 1000),
SocketUtils.findAvailableUdpSocket(adapter.getPort() + j + 1000),
10000);
while (true) {
Message<?> message = queueIn.receive();
@@ -132,11 +133,11 @@ public class MultiClientTests {
@Test @Ignore
public void testAckWithLength() throws Exception {
Thread.sleep(1000);
final String payload = largePayload(1000);
final UnicastReceivingChannelAdapter adapter =
new UnicastReceivingChannelAdapter(SocketTestUtils.findAvailableUdpSocket(), true);
final String payload = largePayload(1000);
final UnicastReceivingChannelAdapter adapter =
new UnicastReceivingChannelAdapter(SocketUtils.findAvailableUdpSocket(), true);
int drivers = 10;
adapter.setPoolSize(drivers);
adapter.setPoolSize(drivers);
QueueChannel queue = new QueueChannel(drivers * 3);
adapter.setOutputChannel(queue);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
@@ -152,7 +153,7 @@ public class MultiClientTests {
UnicastSendingMessageHandler sender = new UnicastSendingMessageHandler(
"localhost", adapter.getPort(),
true, true, "localhost",
SocketTestUtils.findAvailableUdpSocket(adapter.getPort() + j + 1100),
SocketUtils.findAvailableUdpSocket(adapter.getPort() + j + 1100),
10000);
while (true) {
Message<?> message = queueIn.receive();

View File

@@ -18,6 +18,7 @@ import org.springframework.integration.core.SubscribableChannel;
import org.springframework.integration.handler.ServiceActivatingHandler;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.SocketUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@@ -27,7 +28,7 @@ public class UdpChannelAdapterTests {
@Test
public void testUnicastReceiver() throws Exception {
QueueChannel channel = new QueueChannel(2);
int port = SocketTestUtils.findAvailableUdpSocket();
int port = SocketUtils.findAvailableUdpSocket();
UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(port);
adapter.setOutputChannel(channel);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
@@ -36,21 +37,21 @@ public class UdpChannelAdapterTests {
// SocketUtils.setLocalNicIfPossible(adapter);
adapter.start();
SocketTestUtils.waitListening(adapter);
Message<byte[]> message = MessageBuilder.withPayload("ABCD".getBytes()).build();
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
DatagramPacket packet = mapper.fromMessage(message);
packet.setSocketAddress(new InetSocketAddress("localhost", port));
new DatagramSocket(SocketTestUtils.findAvailableUdpSocket()).send(packet);
new DatagramSocket(SocketUtils.findAvailableUdpSocket()).send(packet);
Message<byte[]> receivedMessage = (Message<byte[]>) channel.receive(2000);
assertEquals(new String(message.getPayload()), new String(receivedMessage.getPayload()));
}
@SuppressWarnings("unchecked")
@Test
public void testUnicastSender() throws Exception {
QueueChannel channel = new QueueChannel(2);
int port = SocketTestUtils.findAvailableUdpSocket();
int port = SocketUtils.findAvailableUdpSocket();
UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(port);
adapter.setOutputChannel(channel);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
@@ -64,8 +65,8 @@ public class UdpChannelAdapterTests {
UnicastSendingMessageHandler handler = new UnicastSendingMessageHandler(
"localhost", port, false, true,
"localhost",
// whichNic,
SocketTestUtils.findAvailableUdpSocket(), 5000);
// whichNic,
SocketUtils.findAvailableUdpSocket(), 5000);
// handler.setLocalAddress(whichNic);
handler.afterPropertiesSet();
Message<byte[]> message = MessageBuilder.withPayload("ABCD".getBytes()).build();
@@ -78,7 +79,7 @@ public class UdpChannelAdapterTests {
@Test @Ignore
public void testMulticastReceiver() throws Exception {
QueueChannel channel = new QueueChannel(2);
int port = SocketTestUtils.findAvailableUdpSocket();
int port = SocketUtils.findAvailableUdpSocket();
MulticastReceivingChannelAdapter adapter = new MulticastReceivingChannelAdapter("225.6.7.8", port);
adapter.setOutputChannel(channel);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
@@ -92,7 +93,7 @@ public class UdpChannelAdapterTests {
adapter.setLocalAddress(nic);
adapter.start();
SocketTestUtils.waitListening(adapter);
Message<byte[]> message = MessageBuilder.withPayload("ABCD".getBytes()).build();
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
DatagramPacket packet = mapper.fromMessage(message);
@@ -108,7 +109,7 @@ public class UdpChannelAdapterTests {
@Test @Ignore
public void testMulticastSender() throws Exception {
QueueChannel channel = new QueueChannel(2);
int port = SocketTestUtils.findAvailableUdpSocket();
int port = SocketUtils.findAvailableUdpSocket();
UnicastReceivingChannelAdapter adapter = new MulticastReceivingChannelAdapter("225.6.7.9", port);
adapter.setOutputChannel(channel);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
@@ -122,12 +123,12 @@ public class UdpChannelAdapterTests {
adapter.setLocalAddress(nic);
adapter.start();
SocketTestUtils.waitListening(adapter);
MulticastSendingMessageHandler handler = new MulticastSendingMessageHandler("225.6.7.9", port);
handler.setLocalAddress(nic);
Message<byte[]> message = MessageBuilder.withPayload("ABCD".getBytes()).build();
handler.handleMessage(message);
Message<byte[]> receivedMessage = (Message<byte[]>) channel.receive(2000);
assertNotNull(receivedMessage);
assertEquals(new String(message.getPayload()), new String(receivedMessage.getPayload()));
@@ -136,7 +137,7 @@ public class UdpChannelAdapterTests {
@Test
public void testUnicastReceiverException() throws Exception {
SubscribableChannel channel = new DirectChannel();
int port = SocketTestUtils.findAvailableUdpSocket();
int port = SocketUtils.findAvailableUdpSocket();
UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(port);
adapter.setOutputChannel(channel);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
@@ -150,17 +151,17 @@ public class UdpChannelAdapterTests {
adapter.setErrorChannel(errorChannel);
adapter.start();
SocketTestUtils.waitListening(adapter);
Message<byte[]> message = MessageBuilder.withPayload("ABCD".getBytes()).build();
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
DatagramPacket packet = mapper.fromMessage(message);
packet.setSocketAddress(new InetSocketAddress("localhost", port));
new DatagramSocket(SocketTestUtils.findAvailableUdpSocket()).send(packet);
new DatagramSocket(SocketUtils.findAvailableUdpSocket()).send(packet);
Message<?> receivedMessage = errorChannel.receive(2000);
assertNotNull(receivedMessage);
assertEquals("Failed", ((Exception) receivedMessage.getPayload()).getCause().getMessage());
}
private class FailingService {
@SuppressWarnings("unused")
public String serviceMethod(byte[] bytes) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* 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.
@@ -18,16 +18,12 @@ package org.springframework.integration.ip.util;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.concurrent.CountDownLatch;
import javax.net.ServerSocketFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -35,8 +31,9 @@ import org.springframework.integration.ip.AbstractInternetProtocolReceivingChann
/**
* TCP/IP Test utilities.
*
*
* @author Gary Russell
* @author Gunnar Hillert
*
*/
public class SocketTestUtils {
@@ -44,7 +41,7 @@ public class SocketTestUtils {
public static final String TEST_STRING = "TestMessage";
private static final Log logger = LogFactory.getLog(SocketTestUtils.class);
/**
* Sends a message in two chunks with a preceding length. Two such messages are sent.
* @param latch If not null, await until counted down before sending second chunk.
@@ -137,7 +134,7 @@ public class SocketTestUtils {
}
Thread.sleep(500);
}
/**
* Sends a STX/ETX message in two chunks. Two such messages are sent.
* @param latch If not null, await until counted down before sending second chunk.
@@ -170,7 +167,7 @@ public class SocketTestUtils {
thread.setDaemon(true);
thread.start();
}
/**
* Sends a large STX/ETX message with no ETX
*/
@@ -191,7 +188,7 @@ public class SocketTestUtils {
thread.setDaemon(true);
thread.start();
}
/**
* Sends a message +CRLF in two chunks. Two such messages are sent.
* @param latch If not null, await until counted down before sending second chunk.
@@ -317,37 +314,6 @@ public class SocketTestUtils {
thread.setDaemon(true);
thread.start();
}
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);
}
public static int findAvailableUdpSocket(int seed) {
for (int i = seed; i < seed+200; i++) {
try {
DatagramSocket sock = new DatagramSocket(i);
sock.close();
Thread.sleep(100);
return i;
} catch (Exception e) { }
}
throw new RuntimeException("Cannot find a free server socket");
}
public static int findAvailableUdpSocket() {
return findAvailableUdpSocket(9876);
}
public static void setLocalNicIfPossible(
AbstractInternetProtocolReceivingChannelAdapter adapter)
@@ -359,22 +325,22 @@ public class SocketTestUtils {
adapter.setLocalAddress(loopBack);
}
}
public static String chooseANic(boolean multicast) throws Exception {
// Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
// Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
// while (interfaces.hasMoreElements()) {
// NetworkInterface intface = interfaces.nextElement();
// if (intface.isLoopback() || (multicast && !intface.supportsMulticast()))
// continue;
// Enumeration<InetAddress> inet = intface.getInetAddresses();
// if (!inet.hasMoreElements())
// if (!inet.hasMoreElements())
// continue;
// String address = inet.nextElement().getHostAddress();
// return address;
// }
return null;
}
public static void waitListening(AbstractInternetProtocolReceivingChannelAdapter adapter) throws Exception {
int n = 0;
while (!adapter.isListening()) {
@@ -383,9 +349,7 @@ public class SocketTestUtils {
throw new Exception("Gateway failed to listen");
}
}
}
}
}

View File

@@ -0,0 +1,214 @@
/*
* 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.test.util;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.net.ServerSocketFactory;
import org.springframework.util.Assert;
/**
*
* Contains several socket-specific utility methods. For example, you may have
* test cases that require an open port. Rather than hard-coding the relevant port,
* it will be better to use methods from this utility class to automatically select
* an open port, therefore improving the portability of your test-cases across
* systems.
*
* @author Gunnar Hillert
* @since 2.2
*
*/
public final class SocketUtils {
public static final int DEFAULT_PORT_RANGE_MIN = 10000;
public static final int DEFAULT_PORT_RANGE_MAX = 60000;
/**
* The constructor is intentionally public. In several test cases you may have
* the need to use the methods of this class multiple times from within your
* Spring Application Context XML file using SpEL. Of course you can do:
*
* <pre>
* {@code
* ...port="#{T(org.springframework.integration.test.util.SocketUtils).findAvailableServerSocket(12000)}"
* }
* </pre>
*
* But unfortunately, you would need to repeat the package for each usage.
* This will be acceptable for single use, but if you need to invoke the
* methods numerous time, you may instead want to do this:
*
* <pre>
* {@code
* <bean id="tcpIpUtils" class="org.springframework.integration.test.util.SocketUtils" />
*
* ...port="#{tcpIpUtils.findAvailableServerSocket(12000)}"
* }
* </pre>
*
*/
public SocketUtils() { }
/**
* Determines a free available server socket (port) using the 'seed' value as
* the starting port. The utility methods will probe for 200 sockets but will
* return as soon an open port is found.
*
* @param seed The starting port, which must not be negative.
* @return An available port number
*
* @throws IllegalStateException when no open port was found.
*/
public static int findAvailableServerSocket(int seed) {
final List<Integer> openPorts = findAvailableServerSockets(seed, 1);
return openPorts.get(0);
}
/**
* Determines a free available server socket (port) using the 'seed' value as
* the starting port. The utility methods will probe for 200 sockets but will
* return as soon an open port is found.
*
* @param seed The starting port, which must not be negative.
* @param numberOfRequestedPorts How many open ports shall be retrieved?
* @return A list containing the requested number of open ports
*
* @throws IllegalStateException when no open port was found.
*/
public static List<Integer> findAvailableServerSockets(int seed, int numberOfRequestedPorts) {
Assert.isTrue(seed >= 0, "'seed' must not be negative");
Assert.isTrue(numberOfRequestedPorts > 0, "'numberOfRequestedPorts' must not be negative");
final List<Integer> openPorts = new ArrayList<Integer>(numberOfRequestedPorts);
for (int i = seed; i < seed+200; i++) {
try {
ServerSocket sock = ServerSocketFactory.getDefault().createServerSocket(i);
sock.close();
openPorts.add(i);
if (openPorts.size() == numberOfRequestedPorts) {
return openPorts;
}
} catch (Exception e) { }
}
throw new IllegalStateException(String.format("Cannot find a free server socket (%s requested)", numberOfRequestedPorts));
}
/**
* Determines a free available server socket (port) using an automatically
* chosen start seed port.
*
* @return An available port number
*
* @throws IllegalStateException when no open port was found.
*/
public static int findAvailableServerSocket() {
int seed = getRandomSeedPort();
return findAvailableServerSocket(seed);
}
/**
* Determines a free available Udp socket (port) using the 'seed' value as
* the starting port. The utility methods will probe for 200 sockets but will
* return as soon an open port is found.
*
* @param seed The starting port, which must not be negative.
* @return An available port number
*
* @throws IllegalStateException when no open port was found.
*
*/
public static int findAvailableUdpSocket(int seed) {
final List<Integer> openPorts = findAvailableUdpSockets(seed, 1);
return openPorts.get(0);
}
/**
* Determines free available udp socket(s) (port) using the 'seed' value as
* the starting port. The utility methods will probe for 200 sockets but will
* return as soon an open port is found.
*
* @param seed The starting port, which must not be negative.
* @param numberOfRequestedPorts How many open ports shall be retrieved?
* @return A list containing the requested number of open ports
*
* @throws IllegalStateException when no open port was found.
*/
public static List<Integer> findAvailableUdpSockets(int seed, int numberOfRequestedPorts) {
Assert.isTrue(seed >= 0, "'seed' must not be negative");
Assert.isTrue(numberOfRequestedPorts > 0, "'numberOfRequestedPorts' must not be negative");
final List<Integer> openPorts = new ArrayList<Integer>(numberOfRequestedPorts);
for (int i = seed; i < seed+200; i++) {
try {
DatagramSocket sock = new DatagramSocket(i);
sock.close();
Thread.sleep(100);
openPorts.add(i);
if (openPorts.size() == numberOfRequestedPorts) {
return openPorts;
}
} catch (Exception e) { }
}
throw new IllegalStateException(String.format("Cannot find a free server socket (%s requested)", numberOfRequestedPorts));
}
/**
* Determines a free available Udp socket using an automatically
* chosen start seed port.
*
* @return An available port number
*
* @throws IllegalStateException when no open port was found.
*/
public static int findAvailableUdpSocket() {
int seed = getRandomSeedPort();
return findAvailableUdpSocket(seed);
}
/**
* Determines a random seed port number within the port range
* {@value #DEFAULT_PORT_RANGE_MIN} and {@value #DEFAULT_PORT_RANGE_MAX}.
*
* @return A number with the the specified range
*/
public static int getRandomSeedPort() {
final Random random = new Random();
int randomNumber = random.nextInt(DEFAULT_PORT_RANGE_MAX - DEFAULT_PORT_RANGE_MIN + 1) + DEFAULT_PORT_RANGE_MIN;
return randomNumber;
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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.test.util;
import junit.framework.Assert;
import org.junit.Test;
/**
* @author Gunnar Hillert
*/
public class SocketUtilsTests {
@Test
public void testFindAvailableServerSocketWithNegativeSeedPort() {
try {
SocketUtils.findAvailableServerSocket(-500);
}
catch (IllegalArgumentException e) {
Assert.assertEquals("'seed' must not be negative", e.getMessage());
return;
}
Assert.fail("Expected an IllegalArgumentException to be thrown.");
}
@Test
public void testFindAvailableUdpSocketWithNegativeSeedPort() {
try {
SocketUtils.findAvailableUdpSocket(-500);
}
catch (IllegalArgumentException e) {
Assert.assertEquals("'seed' must not be negative", e.getMessage());
return;
}
Assert.fail("Expected an IllegalArgumentException to be thrown.");
}
}