use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class TcpInboundGatewayTests method testNetSingle.
@Test
public void testNetSingle() throws Exception {
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
scf.setSingleUse(true);
TcpInboundGateway gateway = new TcpInboundGateway();
gateway.setConnectionFactory(scf);
gateway.setBeanFactory(mock(BeanFactory.class));
scf.start();
TestingUtilities.waitListening(scf, 20000L);
int port = scf.getPort();
final QueueChannel channel = new QueueChannel();
gateway.setRequestChannel(channel);
ServiceActivatingHandler handler = new ServiceActivatingHandler(new Service());
handler.setChannelResolver(channelName -> channel);
Socket socket1 = SocketFactory.getDefault().createSocket("localhost", port);
socket1.getOutputStream().write("Test1\r\n".getBytes());
Socket socket2 = SocketFactory.getDefault().createSocket("localhost", port);
socket2.getOutputStream().write("Test2\r\n".getBytes());
handler.handleMessage(channel.receive(10000));
handler.handleMessage(channel.receive(10000));
byte[] bytes = new byte[12];
readFully(socket1.getInputStream(), bytes);
assertEquals("Echo:Test1\r\n", new String(bytes));
readFully(socket2.getInputStream(), bytes);
assertEquals("Echo:Test2\r\n", new String(bytes));
}
use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class TcpInboundGatewayTests method testNetNotSingle.
@Test
public void testNetNotSingle() throws Exception {
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
scf.setSingleUse(false);
TcpInboundGateway gateway = new TcpInboundGateway();
gateway.setConnectionFactory(scf);
scf.start();
TestingUtilities.waitListening(scf, 20000L);
int port = scf.getPort();
final QueueChannel channel = new QueueChannel();
gateway.setRequestChannel(channel);
gateway.setBeanFactory(mock(BeanFactory.class));
ServiceActivatingHandler handler = new ServiceActivatingHandler(new Service());
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.getOutputStream().write("Test1\r\n".getBytes());
socket.getOutputStream().write("Test2\r\n".getBytes());
handler.handleMessage(channel.receive(10000));
handler.handleMessage(channel.receive(10000));
byte[] bytes = new byte[12];
readFully(socket.getInputStream(), bytes);
assertEquals("Echo:Test1\r\n", new String(bytes));
readFully(socket.getInputStream(), bytes);
assertEquals("Echo:Test2\r\n", new String(bytes));
}
use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class TcpInboundGatewayTests method testNioNotSingle.
@Test
public void testNioNotSingle() throws Exception {
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
scf.setSingleUse(false);
TcpInboundGateway gateway = new TcpInboundGateway();
gateway.setConnectionFactory(scf);
scf.start();
TestingUtilities.waitListening(scf, 20000L);
int port = scf.getPort();
final QueueChannel channel = new QueueChannel();
gateway.setRequestChannel(channel);
gateway.setBeanFactory(mock(BeanFactory.class));
ServiceActivatingHandler handler = new ServiceActivatingHandler(new Service());
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.getOutputStream().write("Test1\r\n".getBytes());
socket.getOutputStream().write("Test2\r\n".getBytes());
handler.handleMessage(channel.receive(10000));
handler.handleMessage(channel.receive(10000));
Set<String> results = new HashSet<String>();
byte[] bytes = new byte[12];
readFully(socket.getInputStream(), bytes);
results.add(new String(bytes));
readFully(socket.getInputStream(), bytes);
results.add(new String(bytes));
assertTrue(results.remove("Echo:Test1\r\n"));
assertTrue(results.remove("Echo:Test2\r\n"));
}
use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testNetInterceptors.
@Test
public void testNetInterceptors() throws Exception {
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
noopPublisher(scf);
interceptorsGuts(scf);
scf.stop();
}
use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testNetSingleSharedInterceptors.
@Test
public void testNetSingleSharedInterceptors() throws Exception {
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
noopPublisher(scf);
singleSharedInterceptorsGuts(scf);
scf.stop();
}
Aggregations