use of com.rabbitmq.client.Consumer in project camel by apache.
the class RabbitMQConsumerTest method testStoppingConsumerShutdownConnectionWhenServerHasClosedChannel.
@Test
public void testStoppingConsumerShutdownConnectionWhenServerHasClosedChannel() throws Exception {
AlreadyClosedException alreadyClosedException = Mockito.mock(AlreadyClosedException.class);
RabbitMQConsumer consumer = new RabbitMQConsumer(endpoint, processor);
Mockito.when(endpoint.createExecutor()).thenReturn(Executors.newFixedThreadPool(3));
Mockito.when(endpoint.getConcurrentConsumers()).thenReturn(1);
Mockito.when(endpoint.connect(Matchers.any(ExecutorService.class))).thenReturn(conn);
Mockito.when(conn.createChannel()).thenReturn(channel);
Mockito.when(channel.basicConsume(anyString(), anyBoolean(), any(Consumer.class))).thenReturn("TAG");
Mockito.when(channel.isOpen()).thenReturn(false);
Mockito.doThrow(alreadyClosedException).when(channel).basicCancel("TAG");
Mockito.doThrow(alreadyClosedException).when(channel).close();
consumer.doStart();
consumer.doStop();
Mockito.verify(conn).close(30 * 1000);
}
Aggregations