use of org.apache.activemq.command.Message 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.Message in project activemq-artemis by apache.
the class RecoverExpiredMessagesTest method sendSomeMessagesThatWillExpireIn5AndThenOne.
private void sendSomeMessagesThatWillExpireIn5AndThenOne() throws Exception {
// Setup the producer and send the message.
StubConnection connection = createConnection();
ConnectionInfo connectionInfo = createConnectionInfo();
SessionInfo sessionInfo = createSessionInfo(connectionInfo);
ProducerInfo producerInfo = createProducerInfo(sessionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
connection.send(producerInfo);
int MESSAGE_COUNT = 10;
for (int i = 0; i < MESSAGE_COUNT; i++) {
Message message = createMessage(producerInfo, destination);
message.setExpiration(System.currentTimeMillis() + 5000);
message.setPersistent(true);
connection.send(message);
}
Message message = createMessage(producerInfo, destination);
message.setPersistent(true);
connection.send(message);
expected.add(message.getMessageId().toString());
connection.request(closeConnectionInfo(connectionInfo));
}
use of org.apache.activemq.command.Message in project activemq-artemis by apache.
the class FailoverTransportBrokerTest method createMessage.
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination, int deliveryMode) {
Message message = createMessage(producerInfo, destination);
message.setPersistent(deliveryMode == DeliveryMode.PERSISTENT);
return message;
}
use of org.apache.activemq.command.Message in project activemq-artemis by apache.
the class FanoutTransportBrokerTest method createMessage.
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination, int deliveryMode) {
Message message = createMessage(producerInfo, destination);
message.setPersistent(deliveryMode == DeliveryMode.PERSISTENT);
return message;
}
use of org.apache.activemq.command.Message in project activemq-artemis by apache.
the class MessageTestSupport method populateObject.
@Override
protected void populateObject(Object object) throws Exception {
super.populateObject(object);
Message info = (Message) object;
info.setProducerId(createProducerId("ProducerId:1"));
info.setDestination(createActiveMQDestination("Destination:2"));
info.setTransactionId(createTransactionId("TransactionId:3"));
info.setOriginalDestination(createActiveMQDestination("OriginalDestination:4"));
info.setMessageId(createMessageId("MessageId:5"));
info.setOriginalTransactionId(createTransactionId("OriginalTransactionId:6"));
info.setGroupID("GroupID:7");
info.setGroupSequence(1);
info.setCorrelationId("CorrelationId:8");
info.setPersistent(true);
info.setExpiration(1);
info.setPriority((byte) 1);
info.setReplyTo(createActiveMQDestination("ReplyTo:9"));
info.setTimestamp(2);
info.setType("Type:10");
{
byte[] data = "Content:11".getBytes();
info.setContent(new org.apache.activemq.util.ByteSequence(data, 0, data.length));
}
{
byte[] data = "MarshalledProperties:12".getBytes();
info.setMarshalledProperties(new org.apache.activemq.util.ByteSequence(data, 0, data.length));
}
info.setDataStructure(createDataStructure("DataStructure:13"));
info.setTargetConsumerId(createConsumerId("TargetConsumerId:14"));
info.setCompressed(false);
info.setRedeliveryCounter(2);
{
BrokerId[] value = new BrokerId[2];
for (int i = 0; i < 2; i++) {
value[i] = createBrokerId("BrokerPath:15");
}
info.setBrokerPath(value);
}
info.setArrival(3);
info.setUserID("UserID:16");
info.setRecievedByDFBridge(true);
info.setDroppable(false);
{
BrokerId[] value = new BrokerId[2];
for (int i = 0; i < 2; i++) {
value[i] = createBrokerId("Cluster:17");
}
info.setCluster(value);
}
info.setBrokerInTime(4);
info.setBrokerOutTime(5);
}
Aggregations