use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class UnacknowledgedMessageMapImpl method acknowledge.
@Override
public Collection<MessageConsumerAssociation> acknowledge(long deliveryTag, boolean multiple) {
if (multiple) {
Map<Long, MessageConsumerAssociation> ackedMessageMap = new LinkedHashMap<>();
collect(deliveryTag, multiple, ackedMessageMap);
remove(ackedMessageMap.keySet());
List<MessageConsumerAssociation> acknowledged = new ArrayList<>();
for (MessageConsumerAssociation messageConsumerAssociation : ackedMessageMap.values()) {
MessageInstance instance = messageConsumerAssociation.getMessageInstance();
if (instance.makeAcquisitionUnstealable(messageConsumerAssociation.getConsumer())) {
acknowledged.add(messageConsumerAssociation);
}
}
return acknowledged;
} else {
final MessageConsumerAssociation association = remove(deliveryTag, true);
if (association != null) {
final MessageInstance messageInstance = association.getMessageInstance();
if (messageInstance != null && messageInstance.makeAcquisitionUnstealable(association.getConsumer())) {
return Collections.singleton(association);
}
}
return Collections.emptySet();
}
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class UnacknowledgedMessageMapTest method createMessageInstance.
private MessageInstance createMessageInstance(final int id) {
MessageInstance instance = mock(MessageInstance.class);
when(instance.makeAcquisitionUnstealable(_consumer)).thenReturn(Boolean.TRUE);
when(instance.getAcquiringConsumer()).thenReturn(_consumer);
ServerMessage message = mock(ServerMessage.class);
when(message.getSize()).thenReturn(0L);
when(instance.getMessage()).thenReturn(message);
return instance;
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class AutoCommitTransactionTest method createTestQueueEntries.
private Collection<MessageInstance> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags) {
Collection<MessageInstance> queueEntries = new ArrayList<MessageInstance>();
assertTrue("Boolean arrays must be the same length", queueDurableFlags.length == messagePersistentFlags.length);
for (int i = 0; i < queueDurableFlags.length; i++) {
final BaseQueue queue = createTestAMQQueue(queueDurableFlags[i]);
final ServerMessage message = createTestMessage(messagePersistentFlags[i]);
final boolean hasRecord = queueDurableFlags[i] && messagePersistentFlags[i];
queueEntries.add(new MockMessageInstance() {
@Override
public ServerMessage getMessage() {
return message;
}
@Override
public TransactionLogResource getOwningResource() {
return queue;
}
@Override
public MessageEnqueueRecord getEnqueueRecord() {
if (hasRecord) {
return mock(MessageEnqueueRecord.class);
} else {
return null;
}
}
});
}
return queueEntries;
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class ConsumerTarget_1_0Test method testTTLAdjustedOnSend.
public void testTTLAdjustedOnSend() throws Exception {
final MessageInstanceConsumer comsumer = mock(MessageInstanceConsumer.class);
long ttl = 2000L;
long arrivalTime = System.currentTimeMillis() - 1000L;
final Header header = new Header();
header.setTtl(UnsignedInteger.valueOf(ttl));
final Message_1_0 message = createTestMessage(header, arrivalTime);
final MessageInstance messageInstance = mock(MessageInstance.class);
when(messageInstance.getMessage()).thenReturn(message);
AtomicReference<QpidByteBuffer> payloadRef = new AtomicReference<>();
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
Transfer transfer = (Transfer) args[0];
QpidByteBuffer transferPayload = transfer.getPayload();
QpidByteBuffer payloadCopy = transferPayload.duplicate();
payloadRef.set(payloadCopy);
return null;
}).when(_sendingLinkEndpoint).transfer(any(Transfer.class), anyBoolean());
_consumerTarget.doSend(comsumer, messageInstance, false);
verify(_sendingLinkEndpoint, times(1)).transfer(any(Transfer.class), anyBoolean());
final List<EncodingRetainingSection<?>> sections;
try (QpidByteBuffer payload = payloadRef.get()) {
sections = new SectionDecoderImpl(_describedTypeRegistry.getSectionDecoderRegistry()).parseAll(payload);
}
Header sentHeader = null;
for (EncodingRetainingSection<?> section : sections) {
if (section instanceof HeaderSection) {
sentHeader = ((HeaderSection) section).getValue();
}
}
assertNotNull("Header is not found", sentHeader);
assertNotNull("Ttl is not set", sentHeader.getTtl());
assertTrue("Unexpected ttl", sentHeader.getTtl().longValue() <= 1000);
}
use of org.apache.qpid.server.message.MessageInstance in project qpid-broker-j by apache.
the class StandardQueueTest method testEnqueueDequeuedEntry.
/**
* Tests that entry in dequeued state are not enqueued and not delivered to consumer
*/
public void testEnqueueDequeuedEntry() throws Exception {
// create a queue where each even entry is considered a dequeued
AbstractQueue queue = new DequeuedQueue(getVirtualHost());
queue.create();
// create a consumer
TestConsumerTarget consumer = new TestConsumerTarget();
// register consumer
queue.addConsumer(consumer, null, createMessage(-1l).getClass(), "test", EnumSet.of(ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);
// put test messages into a queue
putGivenNumberOfMessages(queue, 4);
while (consumer.processPending()) ;
// assert received messages
List<MessageInstance> messages = consumer.getMessages();
assertEquals("Only 2 messages should be returned", 2, messages.size());
assertEquals("ID of first message should be 1", 1l, (messages.get(0).getMessage()).getMessageNumber());
assertEquals("ID of second message should be 3", 3l, (messages.get(1).getMessage()).getMessageNumber());
}
Aggregations