Example usage for org.springframework.integration.ip.tcp.connection CachingClientConnectionFactory setConnectionWaitTimeout

List of usage examples for org.springframework.integration.ip.tcp.connection CachingClientConnectionFactory setConnectionWaitTimeout

Introduction

In this page you can find the example usage for org.springframework.integration.ip.tcp.connection CachingClientConnectionFactory setConnectionWaitTimeout.

Prototype

public void setConnectionWaitTimeout(int connectionWaitTimeout) 

Source Link

Usage

From source file:org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactoryTests.java

@Test(expected = MessagingException.class)
public void testLimit() throws Exception {
    AbstractClientConnectionFactory factory = mock(AbstractClientConnectionFactory.class);
    when(factory.isRunning()).thenReturn(true);
    TcpConnectionSupport mockConn1 = makeMockConnection("conn1");
    TcpConnectionSupport mockConn2 = makeMockConnection("conn2");
    when(factory.getConnection()).thenReturn(mockConn1).thenReturn(mockConn2);
    CachingClientConnectionFactory cachingFactory = new CachingClientConnectionFactory(factory, 2);
    cachingFactory.setConnectionWaitTimeout(10);
    cachingFactory.start();//w  w  w. j  a  v  a  2  s  .c  o  m
    TcpConnection conn1 = cachingFactory.getConnection();
    assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
    conn1.close();
    conn1 = cachingFactory.getConnection();
    assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
    TcpConnection conn2 = cachingFactory.getConnection();
    assertEquals("Cached:" + mockConn2.toString(), conn2.toString());
    cachingFactory.getConnection();
}

From source file:org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactoryTests.java

private CachingClientConnectionFactory createCCCFWith2Connections(TcpConnectionSupport conn1,
        TcpConnectionSupport conn2) throws Exception {
    AbstractClientConnectionFactory factory = mock(AbstractClientConnectionFactory.class);
    when(factory.isRunning()).thenReturn(true);
    when(factory.getConnection()).thenReturn(conn1, conn2);
    CachingClientConnectionFactory cccf = new CachingClientConnectionFactory(factory, 1);
    cccf.setConnectionWaitTimeout(1);
    cccf.start();/*from w w w  .  j  ava  2s . c  om*/
    return cccf;
}

From source file:org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactoryTests.java

@Test //INT-3650
public void testRealConnection() throws Exception {
    TcpNetServerConnectionFactory in = new TcpNetServerConnectionFactory(0);
    final CountDownLatch latch1 = new CountDownLatch(2);
    final CountDownLatch latch2 = new CountDownLatch(102);
    final List<String> connectionIds = new ArrayList<String>();
    in.registerListener(message -> {//from w  ww  .  j a  va2s . c o  m
        connectionIds.add((String) message.getHeaders().get(IpHeaders.CONNECTION_ID));
        latch1.countDown();
        latch2.countDown();
        return false;
    });
    in.start();
    TestingUtilities.waitListening(in, null);
    int port = in.getPort();
    TcpNetClientConnectionFactory out = new TcpNetClientConnectionFactory("localhost", port);
    CachingClientConnectionFactory cache = new CachingClientConnectionFactory(out, 1);
    cache.setSingleUse(false);
    cache.setConnectionWaitTimeout(100);
    cache.start();
    TcpConnectionSupport connection1 = cache.getConnection();
    connection1.send(new GenericMessage<String>("foo"));
    connection1.close();
    TcpConnectionSupport connection2 = cache.getConnection();
    connection2.send(new GenericMessage<String>("foo"));
    connection2.close();
    assertTrue(latch1.await(10, TimeUnit.SECONDS));
    assertSame(connectionIds.get(0), connectionIds.get(1));
    for (int i = 0; i < 100; i++) {
        TcpConnectionSupport connection = cache.getConnection();
        connection.send(new GenericMessage<String>("foo"));
        connection.close();
    }
    assertTrue(latch2.await(10, TimeUnit.SECONDS));
    assertSame(connectionIds.get(0), connectionIds.get(101));
    in.stop();
    cache.stop();
}