List of usage examples for org.springframework.integration.ip.tcp.connection AbstractClientConnectionFactory isActive
protected boolean isActive()
From source file:org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactoryTests.java
@Test public void testCachedFailover() throws Exception { // Failover//from w w w . ja v a 2 s. co m AbstractClientConnectionFactory factory1 = mock(AbstractClientConnectionFactory.class); AbstractClientConnectionFactory factory2 = mock(AbstractClientConnectionFactory.class); List<AbstractClientConnectionFactory> factories = new ArrayList<AbstractClientConnectionFactory>(); factories.add(factory1); factories.add(factory2); TcpConnectionSupport mockConn1 = makeMockConnection(); TcpConnectionSupport mockConn2 = makeMockConnection(); when(factory1.getConnection()).thenReturn(mockConn1); when(factory2.getConnection()).thenReturn(mockConn2); when(factory1.isActive()).thenReturn(true); when(factory2.isActive()).thenReturn(true); doThrow(new IOException("fail")).when(mockConn1).send(Mockito.any(Message.class)); doAnswer(invocation -> null).when(mockConn2).send(Mockito.any(Message.class)); FailoverClientConnectionFactory failoverFactory = new FailoverClientConnectionFactory(factories); failoverFactory.start(); // Cache CachingClientConnectionFactory cachingFactory = new CachingClientConnectionFactory(failoverFactory, 2); cachingFactory.start(); TcpConnection conn1 = cachingFactory.getConnection(); GenericMessage<String> message = new GenericMessage<String>("foo"); conn1 = cachingFactory.getConnection(); conn1.send(message); Mockito.verify(mockConn2).send(message); }