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);
}
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));
}
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);
}
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());
}
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());
}
Aggregations