use of org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer in project spring-integration by spring-projects.
the class TcpNioConnectionWriteTests method testWriteCrLfDirect.
@Test
public void testWriteCrLfDirect() throws Exception {
final String testString = "abcdef";
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(0);
final int port = server.getLocalPort();
server.setSoTimeout(10000);
final CountDownLatch latch = new CountDownLatch(1);
Thread t = new Thread(() -> {
AbstractConnectionFactory ccf = null;
try {
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
ccf = getClientConnectionFactory(true, port, serializer);
TcpConnection connection = ccf.getConnection();
connection.send(MessageBuilder.withPayload(testString.getBytes()).build());
latch.await(10, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (ccf != null) {
ccf.stop();
}
}
});
t.setDaemon(true);
t.start();
Socket socket = server.accept();
socket.setSoTimeout(5000);
InputStream is = socket.getInputStream();
byte[] buff = new byte[testString.length() + 2];
readFully(is, buff);
assertEquals(testString, new String(buff, 0, testString.length()));
assertEquals('\r', buff[testString.length()]);
assertEquals('\n', buff[testString.length() + 1]);
server.close();
latch.countDown();
}
Aggregations