Search in sources :

Example 1 with Consumer

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);
}
Also used : Consumer(com.rabbitmq.client.Consumer) ExecutorService(java.util.concurrent.ExecutorService) AlreadyClosedException(com.rabbitmq.client.AlreadyClosedException) Test(org.junit.Test)

Aggregations

AlreadyClosedException (com.rabbitmq.client.AlreadyClosedException)1 Consumer (com.rabbitmq.client.Consumer)1 ExecutorService (java.util.concurrent.ExecutorService)1 Test (org.junit.Test)1