Search in sources :

Example 1 with ObjectToStringTransformer

use of org.springframework.integration.transformer.ObjectToStringTransformer in project spring-integration by spring-projects.

the class ConnectionFacforyTests method test.

@Test
public void test() throws Exception {
    ApplicationEventPublisher publisher = e -> {
    };
    AbstractServerConnectionFactory server = Tcp.netServer(0).backlog(2).soTimeout(5000).get();
    final AtomicReference<Message<?>> received = new AtomicReference<>();
    final CountDownLatch latch = new CountDownLatch(1);
    server.registerListener(m -> {
        received.set(new ObjectToStringTransformer().transform(m));
        latch.countDown();
        return false;
    });
    server.setApplicationEventPublisher(publisher);
    server.afterPropertiesSet();
    server.start();
    TestingUtilities.waitListening(server, null);
    AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get();
    client.setApplicationEventPublisher(publisher);
    client.afterPropertiesSet();
    client.start();
    client.getConnection().send(new GenericMessage<>("foo"));
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertEquals("foo", received.get().getPayload());
    client.stop();
    server.stop();
}
Also used : TcpNioClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeUnit(java.util.concurrent.TimeUnit) ObjectToStringTransformer(org.springframework.integration.transformer.ObjectToStringTransformer) CountDownLatch(java.util.concurrent.CountDownLatch) TestingUtilities(org.springframework.integration.ip.util.TestingUtilities) AbstractClientConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory) TcpNetServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) TcpNioServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Assert.assertEquals(org.junit.Assert.assertEquals) TcpNetClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory) AbstractClientConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ObjectToStringTransformer(org.springframework.integration.transformer.ObjectToStringTransformer) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1 AbstractClientConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory)1 AbstractServerConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory)1 TcpNetClientConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory)1 TcpNetServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory)1 TcpNioClientConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory)1 TcpNioServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory)1 TestingUtilities (org.springframework.integration.ip.util.TestingUtilities)1 ObjectToStringTransformer (org.springframework.integration.transformer.ObjectToStringTransformer)1 Message (org.springframework.messaging.Message)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1