use of org.apache.activemq.broker.region.MessageReference in project activemq-artemis by apache.
the class ActiveMQMessageAuditTest method testSerialization.
public void testSerialization() throws Exception {
ActiveMQMessageAuditNoSync audit = new ActiveMQMessageAuditNoSync();
byte[] bytes = serialize(audit);
LOG.debug("Length: " + bytes.length);
audit = recover(bytes);
List<MessageReference> list = new ArrayList<>();
for (int j = 0; j < 1000; j++) {
ProducerId pid = new ProducerId();
pid.setConnectionId("test");
pid.setSessionId(0);
pid.setValue(j);
LOG.debug("producer " + j);
for (int i = 0; i < 1000; i++) {
MessageId id = new MessageId();
id.setProducerId(pid);
id.setProducerSequenceId(i);
ActiveMQMessage msg = new ActiveMQMessage();
msg.setMessageId(id);
list.add(msg);
assertFalse(audit.isDuplicate(msg.getMessageId().toString()));
if (i % 100 == 0) {
bytes = serialize(audit);
LOG.debug("Length: " + bytes.length);
audit = recover(bytes);
}
if (i % 250 == 0) {
for (MessageReference message : list) {
audit.rollback(message.getMessageId().toString());
}
list.clear();
bytes = serialize(audit);
LOG.debug("Length: " + bytes.length);
audit = recover(bytes);
}
}
}
}
use of org.apache.activemq.broker.region.MessageReference in project activemq-artemis by apache.
the class ActiveMQMessageAuditTest method testIsDuplicateMessageReference.
public void testIsDuplicateMessageReference() {
int count = 10000;
ActiveMQMessageAudit audit = new ActiveMQMessageAudit();
// add to a list
List<MessageReference> list = new ArrayList<>();
for (int i = 0; i < count; i++) {
ProducerId pid = new ProducerId();
pid.setConnectionId("test");
pid.setSessionId(0);
pid.setValue(1);
MessageId id = new MessageId();
id.setProducerId(pid);
id.setProducerSequenceId(i);
ActiveMQMessage msg = new ActiveMQMessage();
msg.setMessageId(id);
list.add(msg);
assertFalse(audit.isDuplicate(msg.getMessageId()));
}
List<MessageReference> windowList = list.subList(list.size() - 1 - audit.getAuditDepth(), list.size() - 1);
for (MessageReference msg : windowList) {
assertTrue("duplicate msg:" + msg, audit.isDuplicate(msg));
}
}
use of org.apache.activemq.broker.region.MessageReference in project activemq-artemis by apache.
the class StoreQueueCursorOrderTest method testSetBatchWithFuture.
@Test
public void testSetBatchWithFuture() throws Exception {
final int count = 4;
final Message[] messages = new Message[count];
final TestMessageStore queueMessageStore = new TestMessageStore(messages, destination);
final ConsumerInfo consumerInfo = new ConsumerInfo();
final DestinationStatistics destinationStatistics = new DestinationStatistics();
consumerInfo.setExclusive(true);
final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, null);
queueMessageStore.start();
queueMessageStore.registerIndexListener(null);
QueueStorePrefetch underTest = new QueueStorePrefetch(queue, brokerService.getBroker());
SystemUsage systemUsage = new SystemUsage();
// ensure memory limit is reached
systemUsage.getMemoryUsage().setLimit(messageBytesSize * (count + 6));
underTest.setSystemUsage(systemUsage);
underTest.setEnableAudit(false);
underTest.start();
assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
ActiveMQTextMessage msg = getMessage(0);
messages[0] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.setRecievedByDFBridge(true);
final ActiveMQTextMessage msgRef = msg;
FutureTask<Long> future0 = new FutureTask<Long>(new Runnable() {
@Override
public void run() {
msgRef.getMessageId().setFutureOrSequenceLong(0L);
}
}, 0L) {
};
msg.getMessageId().setFutureOrSequenceLong(future0);
underTest.addMessageLast(msg);
Executors.newSingleThreadExecutor().submit(future0);
msg = getMessage(1);
messages[3] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.setRecievedByDFBridge(true);
final ActiveMQTextMessage msgRef1 = msg;
FutureTask<Long> future1 = new FutureTask<Long>(new Runnable() {
@Override
public void run() {
msgRef1.getMessageId().setFutureOrSequenceLong(3L);
}
}, 3L) {
};
msg.getMessageId().setFutureOrSequenceLong(future1);
underTest.addMessageLast(msg);
msg = getMessage(2);
messages[1] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.getMessageId().setFutureOrSequenceLong(1L);
underTest.addMessageLast(msg);
assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
// out of order future
Executors.newSingleThreadExecutor().submit(future1);
// sync add to flip cache
msg = getMessage(3);
messages[2] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.getMessageId().setFutureOrSequenceLong(3L);
underTest.addMessageLast(msg);
assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
assertEquals("setBatch set", 2L, queueMessageStore.batch.get());
int dequeueCount = 0;
underTest.setMaxBatchSize(count);
underTest.reset();
while (underTest.hasNext() && dequeueCount < count) {
MessageReference ref = underTest.next();
ref.decrementReferenceCount();
underTest.remove();
LOG.info("Received message: {} with body: {}", ref.getMessageId(), ((ActiveMQTextMessage) ref.getMessage()).getText());
assertEquals(dequeueCount++, ref.getMessageId().getProducerSequenceId());
}
underTest.release();
assertEquals(count, dequeueCount);
}
use of org.apache.activemq.broker.region.MessageReference in project activemq-artemis by apache.
the class StoreQueueCursorOrderTest method tesBlockedFuture.
@Test
public void tesBlockedFuture() throws Exception {
final int count = 2;
final Message[] messages = new Message[count];
final TestMessageStore queueMessageStore = new TestMessageStore(messages, destination);
final ConsumerInfo consumerInfo = new ConsumerInfo();
final DestinationStatistics destinationStatistics = new DestinationStatistics();
consumerInfo.setExclusive(true);
final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, null);
queueMessageStore.start();
queueMessageStore.registerIndexListener(null);
QueueStorePrefetch underTest = new QueueStorePrefetch(queue, brokerService.getBroker());
SystemUsage systemUsage = new SystemUsage();
// ensure memory limit is reached
systemUsage.getMemoryUsage().setLimit(messageBytesSize * 1);
underTest.setSystemUsage(systemUsage);
underTest.setEnableAudit(false);
underTest.start();
assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
ActiveMQTextMessage msg = getMessage(0);
messages[1] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.setRecievedByDFBridge(true);
FutureTask<Long> future = new FutureTask<Long>(new Runnable() {
@Override
public void run() {
}
}, 2L) {
};
msg.getMessageId().setFutureOrSequenceLong(future);
underTest.addMessageLast(msg);
assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
// second message will flip the cache but will be stored before the future task
msg = getMessage(1);
messages[0] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.getMessageId().setFutureOrSequenceLong(1L);
underTest.addMessageLast(msg);
assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
assertEquals("setBatch unset", 0L, queueMessageStore.batch.get());
int dequeueCount = 0;
underTest.setMaxBatchSize(2);
underTest.reset();
while (underTest.hasNext() && dequeueCount < count) {
MessageReference ref = underTest.next();
ref.decrementReferenceCount();
underTest.remove();
LOG.info("Received message: {} with body: {}", ref.getMessageId(), ((ActiveMQTextMessage) ref.getMessage()).getText());
assertEquals(dequeueCount++, ref.getMessageId().getProducerSequenceId());
}
underTest.release();
assertEquals(count, dequeueCount);
}
use of org.apache.activemq.broker.region.MessageReference in project activemq-artemis by apache.
the class StoreQueueCursorOrderTest method testSetBatch.
@Test
public void testSetBatch() throws Exception {
final int count = 3;
final Message[] messages = new Message[count];
final TestMessageStore queueMessageStore = new TestMessageStore(messages, destination);
final ConsumerInfo consumerInfo = new ConsumerInfo();
final DestinationStatistics destinationStatistics = new DestinationStatistics();
consumerInfo.setExclusive(true);
final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, null);
queueMessageStore.start();
queueMessageStore.registerIndexListener(null);
QueueStorePrefetch underTest = new QueueStorePrefetch(queue, brokerService.getBroker());
SystemUsage systemUsage = new SystemUsage();
// ensure memory limit is reached
systemUsage.getMemoryUsage().setLimit(messageBytesSize * 5);
underTest.setSystemUsage(systemUsage);
underTest.setEnableAudit(false);
underTest.start();
assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
ActiveMQTextMessage msg = getMessage(0);
messages[0] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.getMessageId().setFutureOrSequenceLong(0L);
underTest.addMessageLast(msg);
msg = getMessage(1);
messages[1] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.getMessageId().setFutureOrSequenceLong(1L);
underTest.addMessageLast(msg);
assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
msg = getMessage(2);
messages[2] = msg;
msg.setMemoryUsage(systemUsage.getMemoryUsage());
msg.getMessageId().setFutureOrSequenceLong(2L);
underTest.addMessageLast(msg);
assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
assertEquals("setBatch set", 2L, queueMessageStore.batch.get());
int dequeueCount = 0;
underTest.setMaxBatchSize(2);
underTest.reset();
while (underTest.hasNext() && dequeueCount < count) {
MessageReference ref = underTest.next();
ref.decrementReferenceCount();
underTest.remove();
LOG.info("Received message: {} with body: {}", ref.getMessageId(), ((ActiveMQTextMessage) ref.getMessage()).getText());
assertEquals(dequeueCount++, ref.getMessageId().getProducerSequenceId());
}
underTest.release();
assertEquals(count, dequeueCount);
}
Aggregations