use of org.apache.activemq.command.ConsumerInfo in project activemq-artemis by apache.
the class AdvisoryBrokerTest method testConnectionAdvisories.
public void testConnectionAdvisories() throws Exception {
ActiveMQDestination destination = AdvisorySupport.getConnectionAdvisoryTopic();
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(consumerInfo1);
// We should get an advisory of our own connection.
Message m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo1.getConnectionId());
// Setup a second connection
StubConnection connection2 = createConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
connection2.send(connectionInfo2);
// We should get an advisory of the second connection.
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo2.getConnectionId());
// Close the second connection.
connection2.send(closeConnectionInfo(connectionInfo2));
connection2.stop();
// We should get an advisory of the second connection closing
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
RemoveInfo r = (RemoveInfo) m1.getDataStructure();
assertEquals(r.getObjectId(), connectionInfo2.getConnectionId());
assertNoMessagesLeft(connection1);
}
use of org.apache.activemq.command.ConsumerInfo in project activemq-artemis by apache.
the class AdvisoryBrokerTest method testConsumerAdvisories.
public void testConsumerAdvisories() throws Exception {
ActiveMQDestination queue = new ActiveMQQueue("test");
ActiveMQDestination destination = AdvisorySupport.getConsumerAdvisoryTopic(queue);
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(consumerInfo1);
// We should not see and advisory for the advisory consumer.
assertNoMessagesLeft(connection1);
// Setup a second consumer.
StubConnection connection2 = createConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
consumerInfo1.setPrefetchSize(100);
connection2.send(connectionInfo2);
connection2.send(sessionInfo2);
connection2.send(consumerInfo2);
// We should get an advisory of the new consumer.
Message m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ConsumerInfo) m1.getDataStructure()).getConsumerId(), consumerInfo2.getConsumerId());
// Close the second connection.
connection2.request(closeConnectionInfo(connectionInfo2));
connection2.stop();
// We should get an advisory of the consumer closing
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
RemoveInfo r = (RemoveInfo) m1.getDataStructure();
assertEquals(r.getObjectId(), consumerInfo2.getConsumerId());
assertNoMessagesLeft(connection2);
}
use of org.apache.activemq.command.ConsumerInfo in project activemq-artemis by apache.
the class AdvisoryBrokerTest method testProducerAdvisories.
public void testProducerAdvisories() throws Exception {
ActiveMQDestination queue = new ActiveMQQueue("test");
ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(consumerInfo1);
assertNoMessagesLeft(connection1);
// Setup a producer.
StubConnection connection2 = createConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
producerInfo2.setDestination(queue);
connection2.send(connectionInfo2);
connection2.send(sessionInfo2);
connection2.send(producerInfo2);
// We should get an advisory of the new producer.
Message m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
// Close the second connection.
connection2.request(closeConnectionInfo(connectionInfo2));
connection2.stop();
// We should get an advisory of the producer closing
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
RemoveInfo r = (RemoveInfo) m1.getDataStructure();
assertEquals(r.getObjectId(), producerInfo2.getProducerId());
assertNoMessagesLeft(connection2);
}
use of org.apache.activemq.command.ConsumerInfo 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.command.ConsumerInfo 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);
}
Aggregations