use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.
the class MessageOperationExecutorTest method shouldRetrieveMessageFromQueueAndPerformFunctionWhenChecksumMatches.
@Test
public void shouldRetrieveMessageFromQueueAndPerformFunctionWhenChecksumMatches() throws Exception {
GetResponse response = mockDefaultGetResponse();
when(channel.basicGet(DEFAULT_QUEUE_NAME, false)).thenReturn(response);
sut.consumeMessageApplyFunctionAndAckknowlegeOnSuccess(DEFAULT_BROKER_NAME, DEFAULT_QUEUE_NAME, DEFAULT_CHECKSUM, function);
verify(function).apply(channel, response);
verify(channel).basicAck(DEFAULT_DELIVERY_TAG, false);
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.
the class MessageOperationExecutorTest method shouldThrowExceptionWhenAckCannotBeSentAfterSuccessfulFunctionExecution.
@Test
public void shouldThrowExceptionWhenAckCannotBeSentAfterSuccessfulFunctionExecution() throws Exception {
GetResponse getResponse = mockDefaultGetResponse();
when(channel.basicGet(DEFAULT_QUEUE_NAME, false)).thenReturn(getResponse);
when(messageChecksum.createFor(DEFAULT_BASIC_PROPERTIES, DEFAULT_PAYLOAD)).thenReturn(DEFAULT_CHECKSUM);
IOException expectedException = new IOException();
doThrow(expectedException).when(channel).basicAck(DEFAULT_DELIVERY_TAG, false);
try {
sut.consumeMessageApplyFunctionAndAckknowlegeOnSuccess(DEFAULT_BROKER_NAME, DEFAULT_QUEUE_NAME, DEFAULT_CHECKSUM, function);
} catch (MessageOperationFailedException e) {
assertSame(expectedException, e.getCause());
}
verify(messageChecksum).createFor(DEFAULT_BASIC_PROPERTIES, DEFAULT_PAYLOAD);
verify(channel).basicGet(DEFAULT_QUEUE_NAME, false);
verify(function).apply(channel, getResponse);
verify(channel).basicAck(DEFAULT_DELIVERY_TAG, false);
verifyNoMoreInteractions(channel);
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.
the class MessageMapperTest method shouldMapAmqpBasicProperties.
@Test
public void shouldMapAmqpBasicProperties() {
String contentType = "contentType";
String contentEncoding = "contentEncoding";
String headerKey = "headerKey";
String headerValue = "headerValue";
Map<String, Object> headers = new HashMap<>();
headers.put(headerKey, headerValue);
Integer deliveryMode = 12;
Integer priority = 13;
String correlationId = "correlationId";
String replyTo = "replyTo";
String expiration = "expiration";
String messageId = "messageId";
Date timestamp = new Date();
String type = "type";
String userId = "userId";
String appId = "appId";
String clusterId = "clusterId";
AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
when(basicProperties.getContentType()).thenReturn(contentType);
when(basicProperties.getContentEncoding()).thenReturn(contentEncoding);
when(basicProperties.getHeaders()).thenReturn(headers);
when(basicProperties.getDeliveryMode()).thenReturn(deliveryMode);
when(basicProperties.getPriority()).thenReturn(priority);
when(basicProperties.getCorrelationId()).thenReturn(correlationId);
when(basicProperties.getReplyTo()).thenReturn(replyTo);
when(basicProperties.getExpiration()).thenReturn(expiration);
when(basicProperties.getMessageId()).thenReturn(messageId);
when(basicProperties.getTimestamp()).thenReturn(timestamp);
when(basicProperties.getType()).thenReturn(type);
when(basicProperties.getUserId()).thenReturn(userId);
when(basicProperties.getAppId()).thenReturn(appId);
when(basicProperties.getClusterId()).thenReturn(clusterId);
Envelope envelope = mock(Envelope.class);
GetResponse getResponse = mockResponse(envelope, basicProperties);
Message result = sut.map(getResponse);
BasicProperties basicPropertiesOfResult = result.getProperties();
assertNotNull(basicPropertiesOfResult);
assertEquals(contentType, basicPropertiesOfResult.getContentType());
assertEquals(contentEncoding, basicPropertiesOfResult.getContentEncoding());
assertThat(basicPropertiesOfResult.getHeaders().keySet(), Matchers.hasSize(1));
assertThat(basicPropertiesOfResult.getHeaders(), Matchers.hasKey(headerKey));
assertEquals(headerValue, basicPropertiesOfResult.getHeaders().get(headerKey));
assertEquals(deliveryMode, basicPropertiesOfResult.getDeliveryMode());
assertEquals(priority, basicPropertiesOfResult.getPriority());
assertEquals(correlationId, basicPropertiesOfResult.getCorrelationId());
assertEquals(replyTo, basicPropertiesOfResult.getReplyTo());
assertEquals(expiration, basicPropertiesOfResult.getExpiration());
assertEquals(messageId, basicPropertiesOfResult.getMessageId());
assertEquals(timestamp, basicPropertiesOfResult.getTimestamp());
assertEquals(type, basicPropertiesOfResult.getType());
assertEquals(userId, basicPropertiesOfResult.getUserId());
assertEquals(appId, basicPropertiesOfResult.getAppId());
assertEquals(clusterId, basicPropertiesOfResult.getClusterId());
}
use of com.rabbitmq.client.GetResponse in project spring-integration by spring-projects.
the class AmqpMessageSourceTests method testNackOrRequeue.
private void testNackOrRequeue(boolean requeue) throws IOException, TimeoutException {
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");
Message<?> received = source.receive();
verify(connection).createChannel();
StaticMessageHeaderAccessor.getAcknowledgmentCallback(received).acknowledge(requeue ? Status.REQUEUE : Status.REJECT);
verify(channel).basicReject(123L, requeue);
verify(connection).createChannel();
ccf.destroy();
verify(channel).close();
verify(connection).close(30000);
}
use of com.rabbitmq.client.GetResponse in project spring-integration by spring-projects.
the class AmqpMessageSourceTests method testAck.
@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);
Message<?> received = source.receive();
assertThat(received.getHeaders().get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE), instanceOf(org.springframework.amqp.core.Message.class));
assertThat(received.getHeaders().get(AmqpHeaders.CONSUMER_QUEUE), equalTo("foo"));
// make sure channel is not cached
org.springframework.amqp.rabbit.connection.Connection conn = ccf.createConnection();
// should not have been "closed"
Channel notCached = conn.createChannel(false);
verify(connection, times(2)).createChannel();
StaticMessageHeaderAccessor.getAcknowledgmentCallback(received).acknowledge(Status.ACCEPT);
verify(channel).basicAck(123L, false);
// should have been "closed"
Channel cached = conn.createChannel(false);
verify(connection, times(2)).createChannel();
notCached.close();
cached.close();
ccf.destroy();
verify(channel, times(2)).close();
verify(connection).close(30000);
}
Aggregations