private ChannelProxy findOpenChannel(LinkedList<ChannelProxy> channelList, // NOSONAR LinkedList.removeFirst() ChannelProxy channelArg) { ChannelProxy channel = channelArg; synchronized (channelList) { while (!channelList.isEmpty()) { channel = channelList.removeFirst(); if (logger.isTraceEnabled()) { logger.trace(channel + " retrieved from cache"); } if (channel.isOpen()) { break; } else { cleanUpClosedChannel(channel); channel = null; } } } return channel; }
private ChannelProxy findOpenChannel(LinkedList<ChannelProxy> channelList, // NOSONAR LinkedList.removeFirst() ChannelProxy channelArg) { ChannelProxy channel = channelArg; synchronized (channelList) { while (!channelList.isEmpty()) { channel = channelList.removeFirst(); if (logger.isTraceEnabled()) { logger.trace(channel + " retrieved from cache"); } if (channel.isOpen()) { break; } else { cleanUpClosedChannel(channel); channel = null; } } } return channel; }
@Test public void testAlwaysCancelAutoRecoverConsumer() throws IOException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); Connection connection = mock(Connection.class); ChannelProxy channel = mock(ChannelProxy.class); Channel rabbitChannel = mock(AutorecoveringChannel.class); when(channel.getTargetChannel()).thenReturn(rabbitChannel); when(connectionFactory.createConnection()).thenReturn(connection); when(connection.createChannel(anyBoolean())).thenReturn(channel); final AtomicBoolean isOpen = new AtomicBoolean(true); doReturn(isOpen.get()).when(channel).isOpen(); when(channel.queueDeclarePassive(anyString())) .then(invocation -> mock(AMQP.Queue.DeclareOk.class)); doAnswer(i -> { ((Consumer) i.getArgument(6)).handleConsumeOk("consumerTag"); return "consumerTag"; }).when(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), any(Consumer.class)); BlockingQueueConsumer blockingQueueConsumer = new BlockingQueueConsumer(connectionFactory, new DefaultMessagePropertiesConverter(), new ActiveObjectCounter<>(), AcknowledgeMode.AUTO, true, 2, "test"); blockingQueueConsumer.setDeclarationRetries(1); blockingQueueConsumer.setRetryDeclarationInterval(10); blockingQueueConsumer.setFailedDeclarationRetryInterval(10); blockingQueueConsumer.start(); verify(channel).basicQos(2); isOpen.set(false); blockingQueueConsumer.stop(); verify(channel).basicCancel("consumerTag"); }
when(connection.createChannel(anyBoolean())).thenReturn(channel); final AtomicBoolean isOpen = new AtomicBoolean(true); doReturn(isOpen.get()).when(channel).isOpen(); when(channel.queueDeclarePassive(anyString())) .then(invocation -> mock(AMQP.Queue.DeclareOk.class));
given(connection.createChannel(anyBoolean())).willReturn(channel); final AtomicBoolean isOpen = new AtomicBoolean(true); willAnswer(i -> isOpen.get()).given(channel).isOpen(); given(channel.queueDeclarePassive(Mockito.anyString())) .willAnswer(invocation -> mock(AMQP.Queue.DeclareOk.class));
given(connection.createChannel(anyBoolean())).willReturn(channel); final AtomicBoolean isOpen = new AtomicBoolean(true); willAnswer(i -> isOpen.get()).given(channel).isOpen(); given(channel.queueDeclarePassive(Mockito.anyString())) .willAnswer(invocation -> mock(AMQP.Queue.DeclareOk.class));
given(channel.isOpen()).willReturn(true); given(channel.queueDeclarePassive(Mockito.anyString())) .willAnswer(invocation -> mock(AMQP.Queue.DeclareOk.class));