Search in sources :

Example 1 with AMQMessageHeader

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

the class SortedQueueEntryListTest method generateTestMessage.

private ServerMessage generateTestMessage(final long id, final String keyValue) {
    final ServerMessage message = mock(ServerMessage.class);
    AMQMessageHeader hdr = mock(AMQMessageHeader.class);
    when(message.getMessageHeader()).thenReturn(hdr);
    when(hdr.getHeader(eq("KEY"))).thenReturn(keyValue);
    when(hdr.containsHeader(eq("KEY"))).thenReturn(true);
    when(hdr.getHeaderNames()).thenReturn(Collections.singleton("KEY"));
    MessageReference ref = mock(MessageReference.class);
    when(ref.getMessage()).thenReturn(message);
    when(message.newReference()).thenReturn(ref);
    when(message.newReference(any(TransactionLogResource.class))).thenReturn(ref);
    when(message.getMessageNumber()).thenReturn(id);
    return message;
}
Also used : 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 2 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);
    when(oldestEntry.acquireOrSteal(null)).thenReturn(true);
    return oldestEntry;
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 3 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);
    when(message.checkValid()).thenReturn(true);
    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 4 with AMQMessageHeader

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

the class AbstractQueueTestBase method testMessageHoldingDependentOnQueueProperty.

@Test
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(Long.valueOf(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", (long) 1, (long) _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) Test(org.junit.Test)

Example 5 with AMQMessageHeader

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

the class AbstractQueueTestBase method testUnheldMessageOvertakesHeld.

@Test
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(Long.valueOf(24));
    AMQMessageHeader messageHeader = messageA.getMessageHeader();
    when(messageHeader.getNotValidBefore()).thenReturn(System.currentTimeMillis() + 20000L);
    _queue.enqueue(messageA, null, null);
    ServerMessage messageB = createMessage(Long.valueOf(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)", (long) 1, (long) _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", (long) 2, (long) _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) Test(org.junit.Test)

Aggregations

AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)84 Test (org.junit.Test)58 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)56 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)28 ServerMessage (org.apache.qpid.server.message.ServerMessage)16 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 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)3 UnsignedLong (org.apache.qpid.server.protocol.v1_0.type.UnsignedLong)3 Serializable (java.io.Serializable)2 Date (java.util.Date)2 Set (java.util.Set)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 StoredMessage (org.apache.qpid.server.store.StoredMessage)2