Search in sources :

Example 36 with AMQMessageHeader

use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_8Test method testLongContentEncodingConversion.

public void testLongContentEncodingConversion() {
    String contentEncoding = generateLongString();
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getEncoding()).thenReturn(contentEncoding);
    InternalMessage originalMessage = createTestMessage(header);
    try {
        _messageConverter.convert(originalMessage, _addressSpace);
        fail("Expected exception is not thrown");
    } catch (MessageConversionException e) {
    // pass
    }
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Matchers.anyString(org.mockito.Matchers.anyString) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 37 with AMQMessageHeader

use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.

the class AbstractQueueTestBase method testMessageHoldingDependentOnQueueProperty.

public void testMessageHoldingDependentOnQueueProperty() 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.FALSE);
    _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 was held despite queue not having holding enabled", 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)

Example 38 with AMQMessageHeader

use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.

the class AbstractQueueTestBase method testUnheldMessageOvertakesHeld.

public void testUnheldMessageOvertakesHeld() 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);
    ServerMessage messageB = createMessage(new Long(25));
    _queue.enqueue(messageB, null, null);
    _consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    while (_consumerTarget.processPending()) ;
    assertEquals("Expect one message (message B)", 1, _consumerTarget.getMessages().size());
    assertEquals("Wrong message received", messageB.getMessageHeader().getMessageId(), _consumerTarget.getMessages().get(0).getMessage().getMessageHeader().getMessageId());
    when(messageHeader.getNotValidBefore()).thenReturn(System.currentTimeMillis() - 100L);
    _queue.checkMessageStatus();
    while (_consumerTarget.processPending()) ;
    assertEquals("Message which was valid was not received", 2, _consumerTarget.getMessages().size());
    assertEquals("Wrong message received", messageA.getMessageHeader().getMessageId(), _consumerTarget.getMessages().get(1).getMessage().getMessageHeader().getMessageId());
}
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)

Example 39 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) {
    AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getMessageId()).thenReturn(String.valueOf(id));
    ServerMessage message = mock(ServerMessage.class);
    when(message.getMessageNumber()).thenReturn(id);
    when(message.getMessageHeader()).thenReturn(header);
    StoredMessage storedMessage = mock(StoredMessage.class);
    when(message.getStoredMessage()).thenReturn(storedMessage);
    MessageReference ref = mock(MessageReference.class);
    when(ref.getMessage()).thenReturn(message);
    when(message.newReference()).thenReturn(ref);
    when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
    return message;
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) MessageReference(org.apache.qpid.server.message.MessageReference) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 40 with AMQMessageHeader

use of org.apache.qpid.server.message.AMQMessageHeader in project qpid-broker-j by apache.

the class RingOverflowPolicyHandlerTest method createLastEntry.

private QueueEntry createLastEntry() {
    AMQMessageHeader oldestMessageHeader = mock(AMQMessageHeader.class);
    ServerMessage oldestMessage = mock(ServerMessage.class);
    when(oldestMessage.getMessageHeader()).thenReturn(oldestMessageHeader);
    QueueEntry oldestEntry = mock(QueueEntry.class);
    when(oldestEntry.getMessage()).thenReturn(oldestMessage);
    return oldestEntry;
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

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