use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class AddressControlTest method testGetNumberOfPages.
@Test
public void testGetNumberOfPages() throws Exception {
session.close();
server.stop();
server.getConfiguration().setPersistenceEnabled(true);
SimpleString address = RandomUtil.randomSimpleString();
AddressSettings addressSettings = new AddressSettings().setPageSizeBytes(1024).setMaxSizeBytes(10 * 1024);
final int NUMBER_MESSAGES_BEFORE_PAGING = 7;
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
server.start();
ServerLocator locator2 = createInVMNonHALocator();
addServerLocator(locator2);
ClientSessionFactory sf2 = createSessionFactory(locator2);
session = sf2.createSession(false, true, false);
session.start();
session.createQueue(address, address, true);
QueueImpl serverQueue = (QueueImpl) server.locateQueue(address);
ClientProducer producer = session.createProducer(address);
for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++) {
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[896]);
producer.send(msg);
}
session.commit();
AddressControl addressControl = createManagementControl(address);
Assert.assertEquals(0, addressControl.getNumberOfPages());
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[896]);
producer.send(msg);
session.commit();
Assert.assertEquals(1, addressControl.getNumberOfPages());
msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[896]);
producer.send(msg);
session.commit();
Assert.assertEquals(1, addressControl.getNumberOfPages());
msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[896]);
producer.send(msg);
session.commit();
Assert.assertEquals("# of pages is 2", 2, addressControl.getNumberOfPages());
System.out.println("Address size=" + addressControl.getAddressSize());
Assert.assertEquals(serverQueue.getPageSubscription().getPagingStore().getAddressSize(), addressControl.getAddressSize());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class FailoverConsumerUnconsumedTest method assureQueueMessages.
private void assureQueueMessages(int num, SimpleString queueName) {
QueueImpl queue = (QueueImpl) broker.getActiveMQServer().getPostOffice().getBinding(queueName).getBindable();
Assert.assertEquals(num, queue.getMessageCount());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class AMQ1925Test method assertQueueLength.
private void assertQueueLength(int len) throws Exception, IOException {
QueueImpl queue = (QueueImpl) bs.getActiveMQServer().getPostOffice().getBinding(new SimpleString(QUEUE_NAME)).getBindable();
if (len > queue.getMessageCount()) {
// we wait for a moment as the tx might still in afterCommit stage (async op)
Thread.sleep(5000);
}
Assert.assertEquals(len, queue.getMessageCount());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class AmqpPurgeOnNoConsumersTest method testQueueReceiverReadMessage.
@Test(timeout = 60000)
public void testQueueReceiverReadMessage() throws Exception {
AmqpConnection connection = null;
String queue = "purgeQueue";
SimpleString ssQueue = new SimpleString(queue);
server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
AmqpClient client = createAmqpClient();
connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
final AmqpReceiver receiver = session.createReceiver(queue);
QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
assertEquals(0, queueView.getMessageCount());
sendMessages(queue, 5, null, true);
Wait.assertEquals(5, queueView::getMessageCount);
receiver.flow(5);
for (int i = 0; i < 4; i++) {
try {
AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
receive.accept();
assertNotNull(receive);
} catch (Exception e) {
e.printStackTrace();
}
}
try {
receiver.close();
} catch (IOException e) {
e.printStackTrace();
}
Wait.assertEquals(0, queueView::getMessageCount);
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
connection.close();
server.stop();
server.start();
queueView = (QueueImpl) getProxyToQueue(queue);
assertEquals(0, queueView.getMessageCount());
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class AmqpPurgeOnNoConsumersTest method testPurgeQueueCoreRollback.
// I'm adding the core test here to compare semantics between AMQP and core on this test.
@Test(timeout = 60000)
public void testPurgeQueueCoreRollback() throws Exception {
String queue = "purgeQueue";
SimpleString ssQueue = new SimpleString(queue);
server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:5672");
Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(session.createQueue("purgeQueue"));
javax.jms.Queue jmsQueue = session.createQueue(queue);
MessageConsumer consumer = session.createConsumer(jmsQueue);
for (int i = 0; i < 10; i++) {
Message message = session.createTextMessage("hello " + i);
producer.send(message);
}
session.commit();
QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
Wait.assertEquals(10, queueView::getMessageCount);
connection.start();
for (int i = 0; i < 10; i++) {
TextMessage txt = (TextMessage) consumer.receive(1000);
assertNotNull(txt);
assertEquals("hello " + i, txt.getText());
}
consumer.close();
session.rollback();
connection.close();
Wait.assertEquals(0, queueView::getMessageCount);
server.stop();
server.start();
queueView = (QueueImpl) getProxyToQueue(queue);
assertEquals(0, queueView.getMessageCount());
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
Aggregations