use of org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testNioShared.
@Test
public void testNioShared() throws Exception {
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
noopPublisher(scf);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
scf.setDeserializer(serializer);
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
handler.setConnectionFactory(scf);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
scf.start();
QueueChannel channel = new QueueChannel();
adapter.setOutputChannel(channel);
TestingUtilities.waitListening(scf, null);
int port = scf.getPort();
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.setSoTimeout(2000);
socket.getOutputStream().write("Test\r\n".getBytes());
socket.getOutputStream().write("Test\r\n".getBytes());
Message<?> message = channel.receive(10000);
assertNotNull(message);
handler.handleMessage(message);
message = channel.receive(10000);
assertNotNull(message);
handler.handleMessage(message);
byte[] b = new byte[6];
readFully(socket.getInputStream(), b);
assertEquals("Test\r\n", new String(b));
readFully(socket.getInputStream(), b);
assertEquals("Test\r\n", new String(b));
scf.stop();
}
use of org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testNioInterceptors.
@Test
public void testNioInterceptors() throws Exception {
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
noopPublisher(scf);
interceptorsGuts(scf);
scf.stop();
}
use of org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testNioSingleNoOutboundInterceptors.
@Test
public void testNioSingleNoOutboundInterceptors() throws Exception {
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
noopPublisher(scf);
singleNoOutboundInterceptorsGuts(scf);
scf.stop();
}
use of org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory in project spring-integration by spring-projects.
the class ParserUnitTests method testConnServer1.
@Test
public void testConnServer1() {
assertTrue(server1 instanceof TcpNioServerConnectionFactory);
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"));
assertEquals(true, dfa.getPropertyValue("usingDirectBuffers"));
assertNotNull(dfa.getPropertyValue("interceptorFactoryChain"));
}
use of org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory in project spring-integration by spring-projects.
the class SyslogReceivingChannelAdapterTests method testTcpRFC5424.
@Test
public void testTcpRFC5424() throws Exception {
SyslogReceivingChannelAdapterFactoryBean factory = new SyslogReceivingChannelAdapterFactoryBean(SyslogReceivingChannelAdapterFactoryBean.Protocol.tcp);
PollableChannel outputChannel = new QueueChannel();
factory.setOutputChannel(outputChannel);
ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
final CountDownLatch latch = new CountDownLatch(2);
doAnswer(invocation -> {
latch.countDown();
return null;
}).when(publisher).publishEvent(any(ApplicationEvent.class));
factory.setBeanFactory(mock(BeanFactory.class));
AbstractServerConnectionFactory connectionFactory = new TcpNioServerConnectionFactory(0);
connectionFactory.setDeserializer(new RFC6587SyslogDeserializer());
connectionFactory.setApplicationEventPublisher(publisher);
factory.setConnectionFactory(connectionFactory);
factory.setConverter(new RFC5424MessageConverter());
factory.afterPropertiesSet();
factory.start();
TestingUtilities.waitListening(connectionFactory, null);
TcpSyslogReceivingChannelAdapter adapter = (TcpSyslogReceivingChannelAdapter) factory.getObject();
Log logger = spy(TestUtils.getPropertyValue(adapter, "logger", Log.class));
doReturn(true).when(logger).isDebugEnabled();
final CountDownLatch sawLog = new CountDownLatch(1);
doAnswer(invocation -> {
if (((String) invocation.getArgument(0)).contains("Error on syslog socket")) {
sawLog.countDown();
}
invocation.callRealMethod();
return null;
}).when(logger).debug(anyString());
new DirectFieldAccessor(adapter).setPropertyValue("logger", logger);
Thread.sleep(1000);
byte[] buf = ("253 <14>1 2014-06-20T09:14:07+00:00 loggregator d0602076-b14a-4c55-852a-981e7afeed38 DEA - " + "[exampleSDID@32473 iut=\\\"3\\\" eventSource=\\\"Application\\\" eventID=\\\"1011\\\"]" + "[exampleSDID@32473 iut=\\\"3\\\" eventSource=\\\"Application\\\" eventID=\\\"1011\\\"] Removing instance").getBytes("UTF-8");
Socket socket = SocketFactory.getDefault().createSocket("localhost", connectionFactory.getPort());
socket.getOutputStream().write(buf);
socket.close();
assertTrue(sawLog.await(10, TimeUnit.SECONDS));
@SuppressWarnings("unchecked") Message<Map<String, ?>> message = (Message<Map<String, ?>>) outputChannel.receive(10000);
assertNotNull(message);
assertEquals("loggregator", message.getPayload().get("syslog_HOST"));
adapter.stop();
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
Aggregations