use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testException.
@Test
public void testException() throws Exception {
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
noopPublisher(scf);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
scf.setDeserializer(serializer);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
scf.start();
TestingUtilities.waitListening(scf, null);
int port = scf.getPort();
SubscribableChannel channel = new DirectChannel();
adapter.setOutputChannel(channel);
ServiceActivatingHandler handler = new ServiceActivatingHandler(new FailingService());
channel.subscribe(handler);
QueueChannel errorChannel = new QueueChannel();
adapter.setErrorChannel(errorChannel);
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.getOutputStream().write("Test1\r\n".getBytes());
socket.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
scf.stop();
}
use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.
the class ParserUnitTests method testConnServer2.
@Test
public void testConnServer2() {
assertTrue(server2 instanceof TcpNetServerConnectionFactory);
assertEquals(55, server1.getSoLinger());
assertEquals(1234, server1.getSoReceiveBufferSize());
assertEquals(1235, server1.getSoSendBufferSize());
assertEquals(1236, server1.getSoTimeout());
assertEquals(12, server1.getSoTrafficClass());
DirectFieldAccessor dfa = new DirectFieldAccessor(server1);
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertEquals(123, dfa.getPropertyValue("backlog"));
assertNotNull(dfa.getPropertyValue("interceptorFactoryChain"));
}
use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.
the class ConnectionFacforyTests method shouldReturnNetFlavor.
@Test
public void shouldReturnNetFlavor() throws Exception {
AbstractServerConnectionFactory server = Tcp.netServer(0).get();
assertTrue(server instanceof TcpNetServerConnectionFactory);
AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get();
assertTrue(client instanceof TcpNetClientConnectionFactory);
}
use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.
the class FactoryStopStartTests method testRestart.
@Test
public void testRestart() {
AbstractServerConnectionFactory factory = new TcpNetServerConnectionFactory(0);
factory.setSoTimeout(10000);
factory.start();
factory.stop();
factory.start();
factory.stop();
}
use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory 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));
}
Aggregations