List of usage examples for org.springframework.amqp.rabbit.connection ChannelProxy isTransactional
boolean isTransactional();
From source file:org.springframework.amqp.rabbit.connection.CachingConnectionFactoryTests.java
@Test public void testWithConnectionFactoryCacheSize() 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 mockChannel1 = mock(Channel.class); Channel mockChannel2 = mock(Channel.class); Channel mockTxChannel = mock(Channel.class); when(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())) .thenReturn(mockConnection); when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel1, mockChannel2, mockTxChannel); when(mockChannel1.basicGet("foo", false)).thenReturn(new GetResponse(null, null, null, 1)); when(mockChannel2.basicGet("bar", false)).thenReturn(new GetResponse(null, null, null, 1)); when(mockChannel1.isOpen()).thenReturn(true); when(mockChannel2.isOpen()).thenReturn(true); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); ccf.setExecutor(mock(ExecutorService.class)); ccf.setChannelCacheSize(2);/*w ww . j a va2 s . co m*/ Connection con = ccf.createConnection(); Channel channel1 = con.createChannel(false); Channel channel2 = con.createChannel(false); ChannelProxy txChannel = (ChannelProxy) con.createChannel(true); assertTrue(txChannel.isTransactional()); verify(mockTxChannel).txSelect(); txChannel.close(); channel1.basicGet("foo", true); channel2.basicGet("bar", true); channel1.close(); // should be ignored, and add last into channel cache. channel2.close(); // should be ignored, and add last into channel cache. Channel ch1 = con.createChannel(false); // remove first entry in cache // (channel1) Channel ch2 = con.createChannel(false); // remove first entry in cache // (channel2) assertNotSame(ch1, ch2); assertSame(ch1, channel1); assertSame(ch2, channel2); ch1.close(); ch2.close(); verify(mockConnection, times(3)).createChannel(); con.close(); // should be ignored verify(mockConnection, never()).close(); verify(mockChannel1, never()).close(); verify(mockChannel2, never()).close(); }