Search in sources :

Example 21 with ServerMessage

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

the class LocalTransactionTest method testEnqueueInvokesTransactionObserver.

public void testEnqueueInvokesTransactionObserver() throws Exception {
    final TransactionObserver transactionObserver = mock(TransactionObserver.class);
    _transaction = new LocalTransaction(_transactionLog, transactionObserver);
    _message = createTestMessage(true);
    _queues = createTestBaseQueues(new boolean[] { false, true, false, true });
    _transaction.enqueue(_queues, _message, null);
    verify(transactionObserver).onMessageEnqueue(_transaction, _message);
    ServerMessage message2 = createTestMessage(true);
    _transaction.enqueue(createQueue(true), message2, null);
    verify(transactionObserver).onMessageEnqueue(_transaction, message2);
    verifyNoMoreInteractions(transactionObserver);
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 22 with ServerMessage

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

the class AMQChannelTest method testPublishContentHeaderWhenMessageAuthorizationSucceeds.

public void testPublishContentHeaderWhenMessageAuthorizationSucceeds() throws Exception {
    when(_virtualHost.getDefaultDestination()).thenReturn(_messageDestination);
    when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore() {

        @Override
        public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData) {
            MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
            return messageHandle;
        }
    });
    final ArgumentCaptor<ServerMessage> messageCaptor = ArgumentCaptor.forClass(ServerMessage.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            ServerMessage message = messageCaptor.getValue();
            return new RoutingResult(message);
        }
    }).when(_messageDestination).route(messageCaptor.capture(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
    AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
    BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
    properties.setUserId(_amqConnection.getAuthorizedPrincipal().getName());
    channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, ROUTING_KEY, false, false);
    channel.receiveMessageHeader(properties, 0);
    verify(_messageDestination).route((ServerMessage) any(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage) StoredMemoryMessage(org.apache.qpid.server.store.StoredMemoryMessage) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) RoutingResult(org.apache.qpid.server.message.RoutingResult) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) MessageHandle(org.apache.qpid.server.store.MessageHandle) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 23 with ServerMessage

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

the class AbstractQueueTestBase method testExclusiveConsumer.

public void testExclusiveConsumer() throws Exception {
    ServerMessage messageA = createMessage(new Long(24));
    // Check adding an exclusive consumer adds it to the queue
    _consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.EXCLUSIVE, ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    assertEquals("Queue does not have consumer", 1, _queue.getConsumerCount());
    assertEquals("Queue does not have active consumer", 1, _queue.getConsumerCountWithCredit());
    // Check sending a message ends up with the subscriber
    _queue.enqueue(messageA, null, null);
    while (_consumerTarget.processPending()) ;
    assertEquals("Queue context did not see expected message", messageA, _consumer.getQueueContext().getLastSeenEntry().getMessage());
    // Check we cannot add a second subscriber to the queue
    TestConsumerTarget subB = new TestConsumerTarget();
    Exception ex = null;
    try {
        _queue.addConsumer(subB, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    } catch (MessageSource.ExistingExclusiveConsumer e) {
        ex = e;
    }
    assertNotNull(ex);
    // Check we cannot add an exclusive subscriber to a queue with an
    // existing consumer
    _consumer.close();
    _consumer = (QueueConsumer<?, ?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
    try {
        _consumer = (QueueConsumer<?, ?>) _queue.addConsumer(subB, null, messageA.getClass(), "test", EnumSet.of(ConsumerOption.EXCLUSIVE), 0);
    } catch (MessageSource.ExistingConsumerPreventsExclusive e) {
        ex = e;
    }
    assertNotNull(ex);
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageSource(org.apache.qpid.server.message.MessageSource) MessageDestinationIsAlternateException(org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) TestConsumerTarget(org.apache.qpid.server.consumer.TestConsumerTarget)

Example 24 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage 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 25 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage 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)

Aggregations

ServerMessage (org.apache.qpid.server.message.ServerMessage)103 HashMap (java.util.HashMap)26 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)16 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)16 Exchange (org.apache.qpid.server.model.Exchange)14 MessageReference (org.apache.qpid.server.message.MessageReference)13 ArrayList (java.util.ArrayList)9 MessageInstance (org.apache.qpid.server.message.MessageInstance)8 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)7 Queue (org.apache.qpid.server.model.Queue)7 StoredMessage (org.apache.qpid.server.store.StoredMessage)6 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)3 MessageDeletedException (org.apache.qpid.server.message.MessageDeletedException)3 PrivilegedAction (java.security.PrivilegedAction)2 UUID (java.util.UUID)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)2 RoutingResult (org.apache.qpid.server.message.RoutingResult)2