use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testGetMessagesAdded.
@Test
public void testGetMessagesAdded() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(0, getMessagesAdded(queueControl));
ClientProducer producer = session.createProducer(address);
producer.send(session.createMessage(durable));
Assert.assertEquals(1, getMessagesAdded(queueControl));
producer.send(session.createMessage(durable));
Assert.assertEquals(2, getMessagesAdded(queueControl));
consumeMessages(2, session, queue);
Assert.assertEquals(2, getMessagesAdded(queueControl));
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testAttributes.
@Test
public void testAttributes() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
SimpleString filter = new SimpleString("color = 'blue'");
session.createQueue(address, RoutingType.MULTICAST, queue, filter, durable);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(queue.toString(), queueControl.getName());
Assert.assertEquals(address.toString(), queueControl.getAddress());
Assert.assertEquals(filter.toString(), queueControl.getFilter());
Assert.assertEquals(durable, queueControl.isDurable());
Assert.assertEquals(false, queueControl.isTemporary());
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testGetNullFilter.
@Test
public void testGetNullFilter() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(queue.toString(), queueControl.getName());
Assert.assertEquals(null, queueControl.getFilter());
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testRemoveAllWithPagingMode.
@Test
public void testRemoveAllWithPagingMode() throws Exception {
// 3k
final int MESSAGE_SIZE = 1024 * 3;
// reset maxSize for Paging mode
Field maxSizField = PagingManagerImpl.class.getDeclaredField("maxSize");
maxSizField.setAccessible(true);
maxSizField.setLong(server.getPagingManager(), 10240);
clearDataRecreateServerDirs();
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queueName = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queueName, null, durable);
Queue queue = server.locateQueue(queueName);
Assert.assertEquals(false, queue.getPageSubscription().isPaging());
ClientProducer producer = session.createProducer(address);
byte[] body = new byte[MESSAGE_SIZE];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= MESSAGE_SIZE; j++) {
bb.put(getSamplebyte(j));
}
final int numberOfMessages = 8000;
ClientMessage message;
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
producer.send(message);
}
Assert.assertEquals(true, queue.getPageSubscription().isPaging());
QueueControl queueControl = createManagementControl(address, queueName);
assertMessageMetrics(queueControl, numberOfMessages, durable);
int removedMatchedMessagesCount = queueControl.removeAllMessages();
Assert.assertEquals(numberOfMessages, removedMatchedMessagesCount);
assertMessageMetrics(queueControl, 0, durable);
Field queueMemoprySizeField = QueueImpl.class.getDeclaredField("queueMemorySize");
queueMemoprySizeField.setAccessible(true);
AtomicInteger queueMemorySize = (AtomicInteger) queueMemoprySizeField.get(queue);
Assert.assertEquals(0, queueMemorySize.get());
session.deleteQueue(queueName);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testCountMessagesWithFilter.
@Test
public void testCountMessagesWithFilter() throws Exception {
SimpleString key = new SimpleString("key");
long matchingValue = RandomUtil.randomLong();
long unmatchingValue = matchingValue + 1;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
// send on queue
ClientMessage matchingMessage = session.createMessage(durable);
matchingMessage.putLongProperty(key, matchingValue);
ClientMessage unmatchingMessage = session.createMessage(durable);
unmatchingMessage.putLongProperty(key, unmatchingValue);
producer.send(matchingMessage);
producer.send(unmatchingMessage);
producer.send(matchingMessage);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(3, getMessageCount(queueControl));
assertMessageMetrics(queueControl, 3, durable);
Assert.assertEquals(2, queueControl.countMessages(key + " =" + matchingValue));
Assert.assertEquals(1, queueControl.countMessages(key + " =" + unmatchingValue));
session.deleteQueue(queue);
}
Aggregations