use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class PagingTest method testPurge.
@Test
public void testPurge() throws Exception {
clearDataRecreateServerDirs();
Configuration config = createDefaultNettyConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
String queue = "purgeQueue";
SimpleString ssQueue = new SimpleString(queue);
server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
QueueImpl purgeQueue = (QueueImpl) server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
javax.jms.Queue jmsQueue = session.createQueue(queue);
MessageProducer producer = session.createProducer(jmsQueue);
for (int i = 0; i < 100; i++) {
producer.send(session.createTextMessage("hello" + i));
}
session.commit();
Wait.assertEquals(0, purgeQueue::getMessageCount);
Assert.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore().getAddressSize());
MessageConsumer consumer = session.createConsumer(jmsQueue);
for (int i = 0; i < 100; i++) {
producer.send(session.createTextMessage("hello" + i));
if (i == 10) {
purgeQueue.getPageSubscription().getPagingStore().startPaging();
}
}
session.commit();
consumer.close();
Wait.assertEquals(0, purgeQueue::getMessageCount);
Wait.assertFalse(purgeQueue.getPageSubscription()::isPaging);
Wait.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore()::getAddressSize);
purgeQueue.getPageSubscription().getPagingStore().startPaging();
Wait.assertTrue(purgeQueue.getPageSubscription()::isPaging);
consumer = session.createConsumer(jmsQueue);
for (int i = 0; i < 100; i++) {
purgeQueue.getPageSubscription().getPagingStore().startPaging();
Assert.assertTrue(purgeQueue.getPageSubscription().isPaging());
producer.send(session.createTextMessage("hello" + i));
if (i % 2 == 0) {
session.commit();
}
}
session.commit();
connection.start();
server.getStorageManager().getMessageJournal().scheduleCompactAndBlock(50000);
Assert.assertNotNull(consumer.receive(5000));
session.commit();
consumer.close();
Wait.assertEquals(0, purgeQueue::getMessageCount);
Wait.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore()::getAddressSize);
Wait.assertFalse(purgeQueue.getPageSubscription()::isPaging);
StorageManager sm = server.getStorageManager();
for (int i = 0; i < 1000; i++) {
long tx = sm.generateID();
PageTransactionInfoImpl txinfo = new PageTransactionInfoImpl(tx);
sm.storePageTransaction(tx, txinfo);
sm.commit(tx);
tx = sm.generateID();
sm.updatePageTransaction(tx, txinfo, 1);
sm.commit(tx);
}
server.stop();
server.start();
Assert.assertEquals(0, server.getPagingManager().getTransactions().size());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class PagingOrderTest method testOrderOverRollback2.
@Test
public void testOrderOverRollback2() throws Throwable {
boolean persistentMessages = true;
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
server.start();
final int messageSize = 1024;
final int numberOfMessages = 200;
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(0);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
QueueImpl queue = (QueueImpl) server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
session.close();
session = sf.createSession(false, false, 0);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
// number of references without paging
int numberOfRefs = queue.getNumberOfReferences();
// consume all non-paged references
for (int ref = 0; ref < numberOfRefs; ref++) {
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
msg.acknowledge();
}
session.commit();
session.close();
session = sf.createSession(false, false, 0);
session.start();
consumer = session.createConsumer(ADDRESS);
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
int msgIDRolledBack = msg.getIntProperty("id").intValue();
msg.acknowledge();
session.rollback();
msg = consumer.receive(5000);
assertNotNull(msg);
assertEquals(msgIDRolledBack, msg.getIntProperty("id").intValue());
session.rollback();
session.close();
sf.close();
locator.close();
server.stop();
server.start();
locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(0);
sf = createSessionFactory(locator);
session = sf.createSession(false, false, 0);
session.start();
consumer = session.createConsumer(ADDRESS);
for (int i = msgIDRolledBack; i < numberOfMessages; i++) {
ClientMessage message = consumer.receive(5000);
assertNotNull(message);
assertEquals(i, message.getIntProperty("id").intValue());
message.acknowledge();
}
session.commit();
session.close();
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testAddRemoveConsumer.
@Test
public void testAddRemoveConsumer() throws Exception {
Consumer cons1 = new FakeConsumer();
Consumer cons2 = new FakeConsumer();
Consumer cons3 = new FakeConsumer();
QueueImpl queue = getTemporaryQueue();
Assert.assertEquals(0, queue.getConsumerCount());
queue.addConsumer(cons1);
Assert.assertEquals(1, queue.getConsumerCount());
queue.removeConsumer(cons1);
Assert.assertEquals(0, queue.getConsumerCount());
queue.addConsumer(cons1);
queue.addConsumer(cons2);
queue.addConsumer(cons3);
Assert.assertEquals(3, queue.getConsumerCount());
queue.removeConsumer(new FakeConsumer());
Assert.assertEquals(3, queue.getConsumerCount());
queue.removeConsumer(cons1);
Assert.assertEquals(2, queue.getConsumerCount());
queue.removeConsumer(cons2);
Assert.assertEquals(1, queue.getConsumerCount());
queue.removeConsumer(cons3);
Assert.assertEquals(0, queue.getConsumerCount());
queue.removeConsumer(cons3);
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testRoundRobinWithQueueing.
@Test
public void testRoundRobinWithQueueing() throws Exception {
QueueImpl queue = getTemporaryQueue();
final int numMessages = 10;
List<MessageReference> refs = new ArrayList<>();
queue.pause();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i);
refs.add(ref);
queue.addTail(ref);
}
FakeConsumer cons1 = new FakeConsumer();
FakeConsumer cons2 = new FakeConsumer();
queue.addConsumer(cons1);
queue.addConsumer(cons2);
queue.resume();
// Need to make sure the consumers will receive the messages before we do these assertions
long timeout = System.currentTimeMillis() + 5000;
while (cons1.getReferences().size() != numMessages / 2 && timeout > System.currentTimeMillis()) {
Thread.sleep(1);
}
while (cons2.getReferences().size() != numMessages / 2 && timeout > System.currentTimeMillis()) {
Thread.sleep(1);
}
Assert.assertEquals(numMessages / 2, cons1.getReferences().size());
Assert.assertEquals(numMessages / 2, cons2.getReferences().size());
for (int i = 0; i < numMessages; i++) {
MessageReference ref;
ref = i % 2 == 0 ? cons1.getReferences().get(i / 2) : cons2.getReferences().get(i / 2);
Assert.assertEquals(refs.get(i), ref);
}
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testaddHeadadd.
@Test
public void testaddHeadadd() throws Exception {
QueueImpl queue = getTemporaryQueue();
final int numMessages = 10;
List<MessageReference> refs1 = new ArrayList<>();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i);
refs1.add(ref);
queue.addTail(ref);
}
LinkedList<MessageReference> refs2 = new LinkedList<>();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i + numMessages);
refs2.addFirst(ref);
queue.addHead(ref, false);
}
List<MessageReference> refs3 = new ArrayList<>();
for (int i = 0; i < numMessages; i++) {
MessageReference ref = generateReference(queue, i + 2 * numMessages);
refs3.add(ref);
queue.addTail(ref);
}
FakeConsumer consumer = new FakeConsumer();
queue.addConsumer(consumer);
queue.deliverNow();
List<MessageReference> allRefs = new ArrayList<>();
allRefs.addAll(refs2);
allRefs.addAll(refs1);
allRefs.addAll(refs3);
assertRefListsIdenticalRefs(allRefs, consumer.getReferences());
}
Aggregations