List of usage examples for com.rabbitmq.client Connection createChannel
Channel createChannel(int channelNumber) throws IOException;
From source file:org.springframework.integration.amqp.inbound.AmqpMessageSourceTests.java
License:Apache License
@Test public void testAck() throws Exception { Channel channel = mock(Channel.class); willReturn(true).given(channel).isOpen(); Envelope envelope = new Envelope(123L, false, "ex", "rk"); BasicProperties props = new BasicProperties.Builder().build(); GetResponse getResponse = new GetResponse(envelope, props, "bar".getBytes(), 0); willReturn(getResponse).given(channel).basicGet("foo", false); Connection connection = mock(Connection.class); willReturn(true).given(connection).isOpen(); willReturn(channel).given(connection).createChannel(); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); willReturn(connection).given(connectionFactory).newConnection((ExecutorService) isNull(), anyString()); CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory); AmqpMessageSource source = new AmqpMessageSource(ccf, "foo"); source.setRawMessageHeader(true);// w w w .ja va 2s .c om Message<?> received = source.receive(); assertThat(received.getHeaders().get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE)) .isInstanceOf(org.springframework.amqp.core.Message.class); assertThat(received.getHeaders().get(IntegrationMessageHeaderAccessor.SOURCE_DATA)) .isSameAs(received.getHeaders().get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE)); assertThat(received.getHeaders().get(AmqpHeaders.CONSUMER_QUEUE)).isEqualTo("foo"); // make sure channel is not cached org.springframework.amqp.rabbit.connection.Connection conn = ccf.createConnection(); Channel notCached = conn.createChannel(false); // should not have been "closed" verify(connection, times(2)).createChannel(); StaticMessageHeaderAccessor.getAcknowledgmentCallback(received).acknowledge(Status.ACCEPT); verify(channel).basicAck(123L, false); Channel cached = conn.createChannel(false); // should have been "closed" verify(connection, times(2)).createChannel(); notCached.close(); cached.close(); ccf.destroy(); verify(channel, times(2)).close(); verify(connection).close(30000); }