Search in sources :

Example 71 with AMQMessageHeader

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;
}
Also used : AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 72 with AMQMessageHeader

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 73 with AMQMessageHeader

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;
}
Also used : AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 74 with AMQMessageHeader

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;
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 75 with AMQMessageHeader

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());
}
Also used : HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) Queue(org.apache.qpid.server.model.Queue)

Aggregations

AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)81 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)55 Matchers.anyString (org.mockito.Matchers.anyString)28 ServerMessage (org.apache.qpid.server.message.ServerMessage)16 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)15 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)11 HashMap (java.util.HashMap)10 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)8 MessageReference (org.apache.qpid.server.message.MessageReference)5 Queue (org.apache.qpid.server.model.Queue)5 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)5 Exchange (org.apache.qpid.server.model.Exchange)4 UUID (java.util.UUID)3 UnsignedLong (org.apache.qpid.server.protocol.v1_0.type.UnsignedLong)3 Date (java.util.Date)2 Set (java.util.Set)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)2 StoredMessage (org.apache.qpid.server.store.StoredMessage)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2