use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class StoreQueueCursorNoDuplicateTest method testNoDuplicateAfterCacheFullAndReadPast.
public void testNoDuplicateAfterCacheFullAndReadPast() throws Exception {
final PersistenceAdapter persistenceAdapter = brokerService.getPersistenceAdapter();
final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(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 + 2));
underTest.setSystemUsage(systemUsage);
underTest.setEnableAudit(false);
underTest.start();
assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
final ConnectionContext contextNotInTx = new ConnectionContext();
for (int i = 0; i < count; i++) {
ActiveMQTextMessage msg = getMessage(i);
msg.setMemoryUsage(systemUsage.getMemoryUsage());
queueMessageStore.addMessage(contextNotInTx, msg);
underTest.addMessageLast(msg);
}
assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
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.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class StoreQueueCursorNoDuplicateTest method getMessage.
private ActiveMQTextMessage getMessage(int i) throws Exception {
ActiveMQTextMessage message = new ActiveMQTextMessage();
MessageId id = new MessageId(mesageIdRoot + i);
id.setBrokerSequenceId(i);
id.setProducerSequenceId(i);
message.setMessageId(id);
message.setDestination(destination);
message.setPersistent(true);
message.setResponseRequired(true);
message.setText("Msg:" + i + " " + text);
assertEquals(message.getMessageId().getProducerSequenceId(), i);
return message;
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class StoreQueueCursorOrderTest method getMessage.
private ActiveMQTextMessage getMessage(int i) throws Exception {
ActiveMQTextMessage message = new ActiveMQTextMessage();
MessageId id = new MessageId(mesageIdRoot + i);
id.setBrokerSequenceId(i);
id.setProducerSequenceId(i);
message.setMessageId(id);
message.setDestination(destination);
message.setPersistent(true);
message.setResponseRequired(true);
message.setText("Msg:" + i + " " + text);
assertEquals(message.getMessageId().getProducerSequenceId(), i);
return message;
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class StoreQueueCursorOrderTest method testNoSetBatchWithUnOrderedFutureCurrentSync.
@Test
public void testNoSetBatchWithUnOrderedFutureCurrentSync() 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);
final ActiveMQTextMessage msgRef = msg;
FutureTask<Long> future = new FutureTask<Long>(new Runnable() {
@Override
public void run() {
msgRef.getMessageId().setFutureOrSequenceLong(1L);
}
}, 1L) {
};
msg.getMessageId().setFutureOrSequenceLong(future);
Executors.newSingleThreadExecutor().submit(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.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class FanoutTransportBrokerTest method createMessage.
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
message.setDestination(destination);
message.setPersistent(false);
try {
message.setText("Test Message Payload.");
} catch (MessageNotWriteableException e) {
}
return message;
}
Aggregations