Fix TCP tests to use OS-selected port (#224)

* Fix TCP tests to use OS-selected port

https://build.spring.io/browse/INTSAMPLES-NIGHTLY-2413

Modify all the `tcpclientserver` tests to rely on the OS-selected port,
in other words set `0` to the server port and get the real port for the
client when server is listening

* * Upgrade to Gradle-4.6
* Fix Travis config do not perform assemble task
This commit is contained in:
Artem Bilan
2018-04-02 15:17:59 -04:00
committed by Gary Russell
parent 7e7642823b
commit 9d02471346
15 changed files with 238 additions and 227 deletions

View File

@@ -5,7 +5,12 @@ services:
- mongodb
- rabbitmq
- redis-server
env:
- TERM=dumb
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
install: true
script:
- ./gradlew check --continue
- ./gradlew check --refresh-dependencies --no-daemon

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.tcpclientserver;
import java.util.HashMap;
@@ -49,6 +50,8 @@ import org.springframework.util.SocketUtils;
*/
public final class Main {
private static final String AVAILABLE_SERVER_SOCKET = "availableServerSocket";
/**
* Prevent instantiation.
*/
@@ -64,14 +67,14 @@ public final class Main {
final Scanner scanner = new Scanner(System.in);
System.out.println("\n========================================================="
+ "\n "
+ "\n Welcome to the Spring Integration "
+ "\n TCP-Client-Server Sample! "
+ "\n "
+ "\n For more information please visit: "
+ "\n http://www.springintegration.org/ "
+ "\n "
+ "\n=========================================================" );
+ "\n "
+ "\n Welcome to the Spring Integration "
+ "\n TCP-Client-Server Sample! "
+ "\n "
+ "\n For more information please visit: "
+ "\n http://www.springintegration.org/ "
+ "\n "
+ "\n=========================================================");
final GenericXmlApplicationContext context = Main.setupContext();
final SimpleGateway gateway = context.getBean(SimpleGateway.class);
@@ -87,14 +90,14 @@ public final class Main {
System.out.println("\t- Entering q will quit the application");
System.out.print("\n");
System.out.println("\t--> Please also check out the other samples, " +
"that are provided as JUnit tests.");
"that are provided as JUnit tests.");
System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort() + "' using Telnet.\n\n");
while (true) {
final String input = scanner.nextLine();
if("q".equals(input.trim())) {
if ("q".equals(input.trim())) {
break;
}
else {
@@ -111,17 +114,19 @@ public final class Main {
public static GenericXmlApplicationContext setupContext() {
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
System.out.print("Detect open server socket...");
int availableServerSocket = SocketUtils.findAvailableTcpPort(5678);
if (System.getProperty(AVAILABLE_SERVER_SOCKET) == null) {
System.out.print("Detect open server socket...");
int availableServerSocket = SocketUtils.findAvailableTcpPort(5678);
final Map<String, Object> sockets = new HashMap<String, Object>();
sockets.put("availableServerSocket", availableServerSocket);
final Map<String, Object> sockets = new HashMap<>();
sockets.put(AVAILABLE_SERVER_SOCKET, availableServerSocket);
final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);
final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);
context.getEnvironment().getPropertySources().addLast(propertySource);
context.getEnvironment().getPropertySources().addLast(propertySource);
}
System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket"));
System.out.println("using port " + context.getEnvironment().getProperty(AVAILABLE_SERVER_SOCKET));
context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml");
context.registerShutdownHook();

View File

@@ -1,67 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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
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">
<context:property-placeholder />
<context:property-placeholder/>
<!-- Client side -->
<int:gateway id="gw"
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"/>
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"/>
<int-ip:tcp-connection-factory id="client"
type="client"
host="localhost"
port="${availableServerSocket}"
single-use="true"
so-timeout="10000"/>
type="client"
host="localhost"
port="#{crLfServer.port}"
single-use="true"
so-timeout="10000"/>
<int:channel id="input" />
<int:channel id="input"/>
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"/>
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"/>
<int:object-to-string-transformer id="clientBytes2String"
input-channel="clientBytes2StringChannel" />
input-channel="clientBytes2StringChannel"/>
<!-- Server side -->
<int-ip:tcp-connection-factory id="crLfServer"
type="server"
port="${availableServerSocket}"/>
type="server"
port="${availableServerSocket:0}"/>
<int-ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="crLfServer"
request-channel="serverBytes2StringChannel"
error-channel="errorChannel"/>
connection-factory="crLfServer"
request-channel="serverBytes2StringChannel"
error-channel="errorChannel"/>
<int:channel id="toSA" />
<int:channel id="toSA"/>
<int:service-activator input-channel="toSA"
ref="echoService"
method="test"/>
ref="echoService"
method="test"/>
<bean id="echoService"
class="org.springframework.integration.samples.tcpclientserver.EchoService" />
class="org.springframework.integration.samples.tcpclientserver.EchoService"/>
<int:object-to-string-transformer id="serverBytes2String"
input-channel="serverBytes2StringChannel"
output-channel="toSA"/>
input-channel="serverBytes2StringChannel"
output-channel="toSA"/>
<int:transformer id="errorHandler"
input-channel="errorChannel"
expression="payload.failedMessage.payload + ':' + payload.cause.message"/>
input-channel="errorChannel"
expression="payload.failedMessage.payload + ':' + payload.cause.message"/>
</beans>

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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
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">
@@ -15,69 +15,69 @@
</description>
<bean id="integrationConversionService"
class="org.springframework.context.support.ConversionServiceFactoryBean">
class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="org.springframework.integration.samples.tcpclientserver.ByteArrayToStringConverter" />
<bean class="org.springframework.integration.samples.tcpclientserver.ByteArrayToStringConverter"/>
</list>
</property>
</bean>
<context:property-placeholder />
<context:property-placeholder/>
<!-- Client side -->
<int:gateway id="gw"
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"
default-reply-channel="reply"/>
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"
default-reply-channel="reply"/>
<int-ip:tcp-connection-factory id="client"
type="client"
host="localhost"
port="${availableServerSocket}"
single-use="true"
so-timeout="10000"
/>
type="client"
host="localhost"
port="#{crLfServer.port}"
single-use="true"
so-timeout="10000"
/>
<int:channel id="input" />
<int:channel id="input"/>
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input"
reply-channel="reply"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"
/>
request-channel="input"
reply-channel="reply"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"
/>
<!-- dataType attribute invokes the conversion service -->
<int:channel id="reply" datatype="java.lang.String" />
<int:channel id="reply" datatype="java.lang.String"/>
<!-- Server side -->
<int-ip:tcp-connection-factory id="crLfServer"
type="server"
port="${availableServerSocket}"/>
type="server"
port="${availableServerSocket:0}"/>
<int-ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="crLfServer"
request-channel="toSA"
error-channel="errorChannel"/>
connection-factory="crLfServer"
request-channel="toSA"
error-channel="errorChannel"/>
<!-- dataType attribute invokes the conversion service -->
<int:channel id="toSA" datatype="java.lang.String" />
<int:channel id="toSA" datatype="java.lang.String"/>
<int:service-activator input-channel="toSA"
ref="echoService"
method="test"
ref="echoService"
method="test"
/>
<bean id="echoService"
class="org.springframework.integration.samples.tcpclientserver.EchoService" />
class="org.springframework.integration.samples.tcpclientserver.EchoService"/>
<int:transformer id="errorHandler"
input-channel="errorChannel"
expression="payload.failedMessage.payload + ':' + payload.cause.message"/>
input-channel="errorChannel"
expression="payload.failedMessage.payload + ':' + payload.cause.message"/>
</beans>

View File

@@ -1,69 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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
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">
<context:property-placeholder />
<context:property-placeholder/>
<!-- Client side -->
<int:gateway id="gw"
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"/>
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"/>
<!-- Create a connection for the client gateway that uses the same Stx-Etx deserializer to turn the stream
into the appropriate content (it looks for the Stx byte, extracts anything between it and the Etx byte). We
don't specify the serializer (although we could) because the unit test explicitly shows how the content
to be sent is wrapped by the Stx and Etx bytes. -->
<int-ip:tcp-connection-factory id="client"
type="client"
host="localhost"
port="${availableServerSocket}"
single-use="true"
so-timeout="10000"
deserializer="connectionSerializeDeserialize"/>
type="client"
host="localhost"
port="#{serverConnectionFactory.port}"
single-use="true"
so-timeout="10000"
deserializer="connectionSerializeDeserialize"/>
<int:channel id="input" />
<int:channel id="input"/>
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"/>
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"/>
<int:channel id="clientBytes2StringChannel"/>
<int:object-to-string-transformer id="clientBytes2String"
input-channel="clientBytes2StringChannel" />
input-channel="clientBytes2StringChannel"/>
<!-- Server side -->
<!-- When creating the socket factory on the server side, we specify both the serializer and deserializer
which deals with both accepting a stream formatted with the Stx-Etx bytes as well as sending a stream
formatted with the Stx-Etx bytes. -->
<int-ip:tcp-connection-factory id="serverConnectionFactory"
type="server"
port="${availableServerSocket}"
serializer="connectionSerializeDeserialize"
deserializer="connectionSerializeDeserialize"/>
type="server"
port="${availableServerSocket:0}"
serializer="connectionSerializeDeserialize"
deserializer="connectionSerializeDeserialize"/>
<bean id="connectionSerializeDeserialize" class="org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer"/>
<bean id="connectionSerializeDeserialize"
class="org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer"/>
<int-ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="serverConnectionFactory"
request-channel="incomingServerChannel"
error-channel="errorChannel"/>
connection-factory="serverConnectionFactory"
request-channel="incomingServerChannel"
error-channel="errorChannel"/>
<!-- We leave a message listener off of this channel on purpose because we hook
one up before the test actually runs (see the unit test associated with this
context file) -->
<int:channel id="incomingServerChannel" />
<int:channel id="incomingServerChannel"/>
</beans>
</beans>

View File

@@ -17,7 +17,7 @@
formatted with the Stx-Etx bytes. -->
<int-ip:tcp-connection-factory id="serverConnectionFactory"
type="server"
port="${availableServerSocket}"
port="${availableServerSocket:0}"
single-use="true"
so-linger="10000"
serializer="connectionSerializeDeserialize"

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2018 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.
@@ -19,10 +19,12 @@ package org.springframework.integration.samples.tcpclientserver;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
@@ -32,6 +34,7 @@ import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.ip.tcp.TcpInboundGateway;
import org.springframework.integration.ip.tcp.TcpOutboundGateway;
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
@@ -39,9 +42,10 @@ 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.util.TestingUtilities;
import org.springframework.util.SocketUtils;
import org.springframework.integration.test.context.SpringIntegrationTest;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -63,6 +67,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*/
@ContextConfiguration(classes = TcpClientServerAnnotationDemoTest.Config.class)
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
@SpringIntegrationTest(noAutoStartup = "*tcpOutGate*")
public class TcpClientServerAnnotationDemoTest {
@Autowired
@@ -71,9 +77,20 @@ public class TcpClientServerAnnotationDemoTest {
@Autowired
AbstractServerConnectionFactory crLfServer;
@Autowired
AbstractClientConnectionFactory client;
@Autowired
@Qualifier("tcpClientServerAnnotationDemoTest.Config.tcpOutGate.serviceActivator")
AbstractEndpoint outGateway;
@Before
public void setup() {
TestingUtilities.waitListening(this.crLfServer, 10000L);
if (!this.outGateway.isRunning()) {
TestingUtilities.waitListening(this.crLfServer, 10000L);
this.client.setPort(this.crLfServer.getPort());
this.outGateway.start();
}
}
@Test
@@ -87,9 +104,7 @@ public class TcpClientServerAnnotationDemoTest {
@Configuration
public static class Config {
private final int port = SocketUtils.findAvailableTcpPort();
@MessagingGateway(defaultRequestChannel="toTcp")
@MessagingGateway(defaultRequestChannel = "toTcp")
public interface Gateway {
String viaTcp(String in);
@@ -97,7 +112,7 @@ public class TcpClientServerAnnotationDemoTest {
}
@Bean
@ServiceActivator(inputChannel="toTcp")
@ServiceActivator(inputChannel = "toTcp")
public MessageHandler tcpOutGate(AbstractClientConnectionFactory connectionFactory) {
TcpOutboundGateway gate = new TcpOutboundGateway();
gate.setConnectionFactory(connectionFactory);
@@ -106,7 +121,7 @@ public class TcpClientServerAnnotationDemoTest {
}
@Bean
public TcpInboundGateway tcpInGate(AbstractServerConnectionFactory connectionFactory) {
public TcpInboundGateway tcpInGate(AbstractServerConnectionFactory connectionFactory) {
TcpInboundGateway inGate = new TcpInboundGateway();
inGate.setConnectionFactory(connectionFactory);
inGate.setRequestChannel(fromTcp());
@@ -121,31 +136,31 @@ public class TcpClientServerAnnotationDemoTest {
@MessageEndpoint
public static class Echo {
@Transformer(inputChannel="fromTcp", outputChannel="toEcho")
@Transformer(inputChannel = "fromTcp", outputChannel = "toEcho")
public String convert(byte[] bytes) {
return new String(bytes);
}
@ServiceActivator(inputChannel="toEcho")
@ServiceActivator(inputChannel = "toEcho")
public String upCase(String in) {
return in.toUpperCase();
}
@Transformer(inputChannel="resultToString")
@Transformer(inputChannel = "resultToString")
public String convertResult(byte[] bytes) {
return new String(bytes);
}
}
}
@Bean
public AbstractClientConnectionFactory clientCF() {
return new TcpNetClientConnectionFactory("localhost", this.port);
return new TcpNetClientConnectionFactory("localhost", serverCF().getPort());
}
@Bean
public AbstractServerConnectionFactory serverCF() {
return new TcpNetServerConnectionFactory(this.port);
return new TcpNetServerConnectionFactory(0);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.tcpclientserver;
import static org.junit.Assert.assertEquals;
@@ -20,10 +21,13 @@ import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
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.test.context.SpringIntegrationTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -41,12 +45,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*
* @author Gary Russell
* @author Gunnar Hillert
* @author Artem Bilan
*
*/
// This one uses transformers
@ContextConfiguration(loader=CustomTestContextLoader.class, locations={"/META-INF/spring/integration/tcpClientServerDemo-context.xml"})
@ContextConfiguration("/META-INF/spring/integration/tcpClientServerDemo-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
@SpringIntegrationTest(noAutoStartup = "outGateway")
public class TcpClientServerDemoTest {
@Autowired
@@ -55,9 +61,19 @@ public class TcpClientServerDemoTest {
@Autowired
AbstractServerConnectionFactory crLfServer;
@Autowired
AbstractClientConnectionFactory client;
@Autowired
AbstractEndpoint outGateway;
@Before
public void setup() {
TestingUtilities.waitListening(this.crLfServer, 10000L);
if (!this.outGateway.isRunning()) {
TestingUtilities.waitListening(this.crLfServer, 10000L);
this.client.setPort(this.crLfServer.getPort());
this.outGateway.start();
}
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.tcpclientserver;
import static org.junit.Assert.assertEquals;
@@ -20,10 +21,13 @@ import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
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.test.context.SpringIntegrationTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -42,11 +46,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*
* @author Gary Russell
* @author Gunnar Hillert
* @author Artme Bilan
*
*/
@ContextConfiguration(loader=CustomTestContextLoader.class, locations={"/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml"})
@ContextConfiguration("/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
@SpringIntegrationTest(noAutoStartup = "outGateway")
public class TcpClientServerDemoWithConversionServiceTest {
@Autowired
@@ -55,9 +61,19 @@ public class TcpClientServerDemoWithConversionServiceTest {
@Autowired
AbstractServerConnectionFactory crLfServer;
@Autowired
AbstractClientConnectionFactory client;
@Autowired
AbstractEndpoint outGateway;
@Before
public void setup() {
TestingUtilities.waitListening(this.crLfServer, 10000L);
if (!this.outGateway.isRunning()) {
TestingUtilities.waitListening(this.crLfServer, 10000L);
this.client.setPort(this.crLfServer.getPort());
this.outGateway.start();
}
}
@Test

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.tcpclientserver;
import static org.junit.Assert.assertEquals;
@@ -25,14 +26,16 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
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.test.context.SpringIntegrationTest;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -47,11 +50,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*
* @author Christian Posta
* @author Gunnar Hillert
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=CustomTestContextLoader.class,
locations = {"/META-INF/spring/integration/tcpServerConnectionDeserialize-context.xml"})
@ContextConfiguration("/META-INF/spring/integration/tcpServerConnectionDeserialize-context.xml")
@DirtiesContext
@SpringIntegrationTest(noAutoStartup = "outGateway")
public class TcpServerConnectionDeserializeTest {
@Autowired
@@ -64,9 +68,20 @@ public class TcpServerConnectionDeserializeTest {
@Autowired
AbstractServerConnectionFactory crLfServer;
@Autowired
AbstractClientConnectionFactory client;
@Autowired
AbstractEndpoint outGateway;
@Before
public void setup() {
TestingUtilities.waitListening(this.crLfServer, 10000L);
if (!this.outGateway.isRunning()) {
TestingUtilities.waitListening(this.crLfServer, 10000L);
this.client.setPort(this.crLfServer.getPort());
this.outGateway.start();
}
}
@Test
@@ -112,4 +127,5 @@ public class TcpServerConnectionDeserializeTest {
writer.write(ByteArrayStxEtxSerializer.ETX);
return writer.toString();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.tcpclientserver;
import static org.junit.Assert.assertEquals;
@@ -34,11 +35,9 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
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.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
@@ -55,11 +54,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Christian Posta
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = CustomTestContextLoader.class, locations = {
"/META-INF/spring/integration/tcpServerCustomSerialize-context.xml" })
@ContextConfiguration("/META-INF/spring/integration/tcpServerCustomSerialize-context.xml")
@DirtiesContext
public class TcpServerCustomSerializerTest {
@@ -69,9 +68,6 @@ public class TcpServerCustomSerializerTest {
@Qualifier("incomingServerChannel")
MessageChannel incomingServerChannel;
@Value("${availableServerSocket}")
int availableServerSocket;
@Autowired
AbstractServerConnectionFactory serverConnectionFactory;
@@ -111,7 +107,7 @@ public class TcpServerCustomSerializerTest {
BufferedReader in = null;
try {
socket = new Socket("localhost", availableServerSocket);
socket = new Socket("localhost", this.serverConnectionFactory.getPort());
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
out.write(sourceMessage);
out.flush();
@@ -130,7 +126,8 @@ public class TcpServerCustomSerializerTest {
}
catch (IOException e) {
LOGGER.error(e.getMessage(), e);
fail(String.format("Test (port: %s) ended with an exception: %s", availableServerSocket, e.getMessage()));
fail(String.format("Test (port: %s) ended with an exception: %s", this.serverConnectionFactory.getPort(),
e.getMessage()));
}
finally {
try {

View File

@@ -1,59 +0,0 @@
/*
* Copyright 2002-2017 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.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.util.SocketUtils;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.support.GenericXmlContextLoader;
/**
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*/
public class CustomTestContextLoader extends GenericXmlContextLoader {
private static final Log LOGGER = LogFactory.getLog(CustomTestContextLoader.class);
@Override
protected void loadBeanDefinitions(GenericApplicationContext context,
MergedContextConfiguration mergedConfig) {
int availableServerSocket = SocketUtils.findAvailableTcpPort(5678);
final Map<String, Object> sockets = new HashMap<String, Object>();
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);
}
}

View File

@@ -5,7 +5,7 @@ buildscript {
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE'
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
classpath 'org.akhikhl.gretty:gretty:1.4.2'
classpath 'org.akhikhl.gretty:gretty:2.0.0'
}
}
plugins {
@@ -409,7 +409,7 @@ project('loan-broker') {
project('loanshark') {
description = 'Loan Shark Sample'
apply plugin: 'org.akhikhl.gretty'
// apply plugin: 'org.akhikhl.gretty'
apply plugin: 'eclipse-wtp'
dependencies {
@@ -585,7 +585,7 @@ project('http') {
description = 'HTTP Sample'
apply plugin: 'application'
apply plugin: 'org.akhikhl.gretty'
// apply plugin: 'org.akhikhl.gretty'
apply plugin: 'eclipse-wtp'
mainClassName = 'org.springframework.integration.samples.http.HttpClientDemo'
@@ -950,7 +950,7 @@ project('twitter') {
project('ws-inbound-gateway') {
description = 'WS Inbound Gateway Sample'
apply plugin: 'org.akhikhl.gretty'
// apply plugin: 'org.akhikhl.gretty'
apply plugin: 'eclipse-wtp'
dependencies {
@@ -1070,7 +1070,7 @@ project('mail-attachments') {
project('monitoring') {
description = 'Monitoring Application'
apply plugin: 'org.akhikhl.gretty'
// apply plugin: 'org.akhikhl.gretty'
apply plugin: 'application'
apply plugin: 'eclipse-wtp'
@@ -1089,7 +1089,7 @@ project('monitoring') {
project('multipart-http') {
description = 'HTTP Multipart Demo'
apply plugin: 'org.akhikhl.gretty'
// apply plugin: 'org.akhikhl.gretty'
apply plugin: 'eclipse-wtp'
dependencies {
@@ -1105,7 +1105,7 @@ project('multipart-http') {
project('rest-http') {
description = 'Spring Integration Rest HTTP Path Usage Demo'
apply plugin: 'org.akhikhl.gretty'
// apply plugin: 'org.akhikhl.gretty'
apply plugin: 'eclipse-wtp'
dependencies {

Binary file not shown.

View File

@@ -1,6 +1,5 @@
#Tue Jul 25 14:05:00 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip