use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.
the class FanoutExchangeTest method createTestMessage.
private ServerMessage<?> createTestMessage(Map<String, Object> headerValues) {
AMQMessageHeader header = mock(AMQMessageHeader.class);
headerValues.forEach((key, value) -> when(header.getHeader(key)).thenReturn(value));
@SuppressWarnings("unchecked") ServerMessage<?> message = mock(ServerMessage.class);
when(message.isResourceAcceptable(any(TransactionLogResource.class))).thenReturn(true);
when(message.getMessageHeader()).thenReturn(header);
return message;
}
use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.
the class HeadersExchangeTest method createTestMessage.
private ServerMessage<?> createTestMessage(Map<String, Object> headerValues) {
AMQMessageHeader header = mock(AMQMessageHeader.class);
headerValues.forEach((key, value) -> when(header.getHeader(key)).thenReturn(value));
headerValues.forEach((key, value) -> when(header.containsHeader(key)).thenReturn(true));
when(header.getHeaderNames()).thenReturn(headerValues.keySet());
when(header.containsHeaders(any())).then(invocation -> {
final Set<String> names = (Set<String>) invocation.getArguments()[0];
return headerValues.keySet().containsAll(names);
});
@SuppressWarnings("unchecked") ServerMessage<?> message = mock(ServerMessage.class);
when(message.isResourceAcceptable(any(TransactionLogResource.class))).thenReturn(true);
when(message.getMessageHeader()).thenReturn(header);
return message;
}
use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.
the class TopicExchangeTest method createTestMessage.
private ServerMessage<?> createTestMessage(Map<String, Object> headerValues) {
AMQMessageHeader header = mock(AMQMessageHeader.class);
headerValues.forEach((key, value) -> when(header.getHeader(key)).thenReturn(value));
@SuppressWarnings("unchecked") ServerMessage<?> message = mock(ServerMessage.class);
when(message.isResourceAcceptable(any(TransactionLogResource.class))).thenReturn(true);
when(message.getMessageHeader()).thenReturn(header);
return message;
}
use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.
the class AbstractQueueTestBase method createMessage.
protected ServerMessage createMessage(Long id, byte priority, final Map<String, Object> arguments, long arrivalTime) {
ServerMessage message = createMessage(id);
AMQMessageHeader hdr = message.getMessageHeader();
when(hdr.getPriority()).thenReturn(priority);
when(message.getArrivalTime()).thenReturn(arrivalTime);
when(hdr.getHeaderNames()).thenReturn(arguments.keySet());
final ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
when(hdr.containsHeader(nameCaptor.capture())).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
return arguments.containsKey(nameCaptor.getValue());
}
});
final ArgumentCaptor<Set> namesCaptor = ArgumentCaptor.forClass(Set.class);
when(hdr.containsHeaders(namesCaptor.capture())).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
return arguments.keySet().containsAll(namesCaptor.getValue());
}
});
final ArgumentCaptor<String> nameCaptor2 = ArgumentCaptor.forClass(String.class);
when(hdr.getHeader(nameCaptor2.capture())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
return arguments.get(nameCaptor2.getValue());
}
});
return message;
}
use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.
the class AbstractQueueTestBase method testMessageHeldIfNotYetValidWhenConsumerAdded.
public void testMessageHeldIfNotYetValidWhenConsumerAdded() throws Exception {
_queue.close();
Map<String, Object> attributes = new HashMap<>(_arguments);
attributes.put(Queue.NAME, _qname);
attributes.put(Queue.OWNER, _owner);
attributes.put(Queue.HOLD_ON_PUBLISH_ENABLED, Boolean.TRUE);
_queue = _virtualHost.createChild(Queue.class, attributes);
ServerMessage messageA = createMessage(new Long(24));
AMQMessageHeader messageHeader = messageA.getMessageHeader();
when(messageHeader.getNotValidBefore()).thenReturn(System.currentTimeMillis() + 20000L);
_queue.enqueue(messageA, null, null);
_consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
while (_consumerTarget.processPending()) ;
assertEquals("Message which was not yet valid was received", 0, _consumerTarget.getMessages().size());
when(messageHeader.getNotValidBefore()).thenReturn(System.currentTimeMillis() - 100L);
_queue.checkMessageStatus();
while (_consumerTarget.processPending()) ;
assertEquals("Message which was valid was not received", 1, _consumerTarget.getMessages().size());
}
Aggregations