List of usage examples for org.springframework.amqp.rabbit.connection CachingConnectionFactory createConnection
@Override public final Connection createConnection() throws AmqpException
From source file:org.springframework.amqp.rabbit.connection.CachingConnectionFactoryTests.java
@Test public void setUri() throws Exception { URI uri = new URI("amqp://localhost:1234/%2f"); ConnectionFactory mock = mock(com.rabbitmq.client.ConnectionFactory.class); CachingConnectionFactory ccf = new CachingConnectionFactory(mock); ccf.setExecutor(mock(ExecutorService.class)); ccf.setUri(uri);/*from w w w .j av a 2s .co m*/ ccf.createConnection(); InOrder order = inOrder(mock); order.verify(mock).isAutomaticRecoveryEnabled(); order.verify(mock).setUri(uri); Log logger = TestUtils.getPropertyValue(ccf, "logger", Log.class); if (logger.isInfoEnabled()) { order.verify(mock).getHost(); order.verify(mock).getPort(); } order.verify(mock).newConnection(any(ExecutorService.class), anyString()); verifyNoMoreInteractions(mock); }
From source file:org.springframework.amqp.rabbit.connection.CachingConnectionFactoryTests.java
@Test public void testChannelCloseIdempotency() throws Exception { com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock( com.rabbitmq.client.ConnectionFactory.class); com.rabbitmq.client.Connection mockConnection = mock(com.rabbitmq.client.Connection.class); Channel mockChannel = mock(Channel.class); when(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())) .thenReturn(mockConnection); when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel); when(mockChannel.isOpen()).thenReturn(true).thenReturn(false); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); ccf.setExecutor(mock(ExecutorService.class)); Connection con = ccf.createConnection(); Channel channel = con.createChannel(false); // RabbitUtils.setPhysicalCloseRequired(true); channel.close(); // should be ignored, and placed into channel cache. channel.close(); // physically closed, so remove from the cache. channel.close(); // physically closed and removed from the cache before, so void "close". Channel channel2 = con.createChannel(false); assertNotSame(channel, channel2);/*w w w . j a va 2 s .c om*/ }
From source file:org.springframework.amqp.rabbit.connection.CachingConnectionFactoryTests.java
@Test @Ignore // Test to verify log message is suppressed after patch to CCF public void testReturnsNormalCloseDeferredClose() throws Exception { com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock( com.rabbitmq.client.ConnectionFactory.class); com.rabbitmq.client.Connection mockConnection = mock(com.rabbitmq.client.Connection.class); Channel mockChannel = mock(Channel.class); when(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())) .thenReturn(mockConnection); when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel); when(mockChannel.isOpen()).thenReturn(true); doThrow(new ShutdownSignalException(true, false, new com.rabbitmq.client.AMQP.Connection.Close.Builder().replyCode(200).replyText("OK").build(), null)).when(mockChannel).close(); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); ccf.setPublisherReturns(true);/*from w w w . j ava2 s . co m*/ ccf.setExecutor(Executors.newSingleThreadExecutor()); Connection conn = ccf.createConnection(); Channel channel = conn.createChannel(false); RabbitUtils.setPhysicalCloseRequired(channel, true); channel.close(); Thread.sleep(6000); }