use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.
the class PagingTest method testPendingACKOutOfOrder.
@Test
public void testPendingACKOutOfOrder() throws Throwable {
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
try {
ServerLocator locator = createInVMNonHALocator();
locator.setBlockOnDurableSend(false);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(true, true, 0);
session.createQueue(ADDRESS.toString(), "Q1", true);
PagingStore store = server.getPagingManager().getPageStore(ADDRESS);
store.startPaging();
ClientProducer prod = session.createProducer(ADDRESS);
for (int i = 0; i < 100; i++) {
ClientMessage msg = session.createMessage(true);
msg.putIntProperty("count", i);
prod.send(msg);
session.commit();
if ((i + 1) % 5 == 0 && i < 50) {
store.forceAnotherPage();
}
}
session.start();
ClientConsumer cons1 = session.createConsumer("Q1");
for (int i = 0; i < 100; i++) {
ClientMessage msg = cons1.receive(5000);
assertNotNull(msg);
if (i == 13) {
msg.individualAcknowledge();
}
}
session.close();
locator.close();
server.stop();
server.start();
store = server.getPagingManager().getPageStore(ADDRESS);
locator = createInVMNonHALocator();
sf = locator.createSessionFactory();
session = sf.createSession(true, true, 0);
cons1 = session.createConsumer("Q1");
session.start();
for (int i = 0; i < 99; i++) {
ClientMessage msg = cons1.receive(5000);
assertNotNull(msg);
System.out.println("count = " + msg.getIntProperty("count"));
msg.acknowledge();
}
assertNull(cons1.receiveImmediate());
session.close();
waitForNotPaging(store);
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.
the class PagingTest method testMoveMessages.
// Test a scenario where a page was complete and now needs to be cleared
@Test
public void testMoveMessages() throws Throwable {
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int LARGE_MESSAGE_SIZE = 1024 * 1024;
try {
ServerLocator locator = createInVMNonHALocator();
locator.setBlockOnDurableSend(false);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(true, true, 0);
session.createQueue("Q1", "Q1", true);
session.createQueue("Q2", "Q2", true);
PagingStore store = server.getPagingManager().getPageStore(new SimpleString("Q1"));
ClientProducer prod = session.createProducer("Q1");
for (int i = 0; i < 50; i++) {
ClientMessage msg = session.createMessage(true);
msg.putIntProperty("count", i);
if (i > 0 && i % 10 == 0) {
msg.setBodyInputStream(createFakeLargeStream(LARGE_MESSAGE_SIZE));
}
prod.send(msg);
}
session.commit();
store.startPaging();
for (int i = 50; i < 100; i++) {
ClientMessage msg = session.createMessage(true);
msg.putIntProperty("count", i);
if (i % 10 == 0) {
msg.setBodyInputStream(createFakeLargeStream(LARGE_MESSAGE_SIZE));
}
prod.send(msg);
if (i % 10 == 0) {
session.commit();
store.forceAnotherPage();
}
}
session.commit();
Queue queue = server.locateQueue(new SimpleString("Q1"));
queue.moveReferences(10, (Filter) null, new SimpleString("Q2"), false, server.getPostOffice().getBinding(new SimpleString("Q2")));
waitForNotPaging(store);
session.close();
locator.close();
server.stop();
server.start();
locator = createInVMNonHALocator();
locator.setBlockOnDurableSend(false);
sf = locator.createSessionFactory();
session = sf.createSession(true, true, 0);
session.start();
ClientConsumer cons = session.createConsumer("Q2");
for (int i = 0; i < 100; i++) {
ClientMessage msg = cons.receive(10000);
assertNotNull(msg);
if (i > 0 && i % 10 == 0) {
byte[] largeMessageRead = new byte[LARGE_MESSAGE_SIZE];
msg.getBodyBuffer().readBytes(largeMessageRead);
for (int j = 0; j < LARGE_MESSAGE_SIZE; j++) {
assertEquals(largeMessageRead[j], getSamplebyte(j));
}
}
msg.acknowledge();
assertEquals(i, msg.getIntProperty("count").intValue());
}
assertNull(cons.receiveImmediate());
waitForNotPaging(server.locateQueue(new SimpleString("Q2")));
session.close();
sf.close();
locator.close();
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.
the class PagingTest method testSpreadMessagesWithFilter.
// https://issues.jboss.org/browse/HORNETQ-1042 - spread messages because of filters
public void testSpreadMessagesWithFilter(boolean deadConsumer) throws Exception {
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
try {
ServerLocator locator = createInVMNonHALocator();
locator.setBlockOnDurableSend(false);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(true, false);
session.createQueue(ADDRESS.toString(), "Q1", "destQ=1 or both=true", true);
session.createQueue(ADDRESS.toString(), "Q2", "destQ=2 or both=true", true);
if (deadConsumer) {
// This queue won't receive any messages
session.createQueue(ADDRESS.toString(), "Q3", "destQ=3", true);
}
session.createQueue(ADDRESS.toString(), "Q_initial", "initialBurst=true", true);
ClientSession sessionConsumerQ3 = null;
final AtomicInteger consumerQ3Msgs = new AtomicInteger(0);
if (deadConsumer) {
sessionConsumerQ3 = sf.createSession(true, true);
ClientConsumer consumerQ3 = sessionConsumerQ3.createConsumer("Q3");
consumerQ3.setMessageHandler(new MessageHandler() {
@Override
public void onMessage(ClientMessage message) {
System.out.println("Received an unexpected message");
consumerQ3Msgs.incrementAndGet();
}
});
sessionConsumerQ3.start();
}
final int initialBurst = 100;
final int messagesSentAfterBurst = 100;
final int MESSAGE_SIZE = 300;
final byte[] bodyWrite = new byte[MESSAGE_SIZE];
Queue serverQueue = server.locateQueue(new SimpleString("Q1"));
PagingStore pageStore = serverQueue.getPageSubscription().getPagingStore();
ClientProducer producer = session.createProducer(ADDRESS);
// send an initial burst that will put the system into page mode. The initial burst will be towards Q1 only
for (int i = 0; i < initialBurst; i++) {
ClientMessage m = session.createMessage(true);
m.getBodyBuffer().writeBytes(bodyWrite);
m.putIntProperty("destQ", 1);
m.putBooleanProperty("both", false);
m.putBooleanProperty("initialBurst", true);
producer.send(m);
if (i % 100 == 0) {
session.commit();
}
}
session.commit();
pageStore.forceAnotherPage();
for (int i = 0; i < messagesSentAfterBurst; i++) {
{
ClientMessage m = session.createMessage(true);
m.getBodyBuffer().writeBytes(bodyWrite);
m.putIntProperty("destQ", 1);
m.putBooleanProperty("initialBurst", false);
m.putIntProperty("i", i);
m.putBooleanProperty("both", i % 10 == 0);
producer.send(m);
}
if (i % 10 != 0) {
ClientMessage m = session.createMessage(true);
m.getBodyBuffer().writeBytes(bodyWrite);
m.putIntProperty("destQ", 2);
m.putIntProperty("i", i);
m.putBooleanProperty("both", false);
m.putBooleanProperty("initialBurst", false);
producer.send(m);
}
if (i > 0 && i % 10 == 0) {
session.commit();
if (i + 10 < messagesSentAfterBurst) {
pageStore.forceAnotherPage();
}
}
}
session.commit();
ClientConsumer consumerQ1 = session.createConsumer("Q1");
ClientConsumer consumerQ2 = session.createConsumer("Q2");
session.start();
for (int i = 0; i < initialBurst; i++) {
ClientMessage m = consumerQ1.receive(5000);
assertNotNull(m);
assertEquals(1, m.getIntProperty("destQ").intValue());
m.acknowledge();
session.commit();
}
// This will consume messages from the beginning of the queue only
ClientConsumer consumerInitial = session.createConsumer("Q_initial");
for (int i = 0; i < initialBurst; i++) {
ClientMessage m = consumerInitial.receive(5000);
assertNotNull(m);
assertEquals(1, m.getIntProperty("destQ").intValue());
m.acknowledge();
}
assertNull(consumerInitial.receiveImmediate());
session.commit();
for (int i = 0; i < messagesSentAfterBurst; i++) {
ClientMessage m = consumerQ1.receive(5000);
assertNotNull(m);
if (!m.getBooleanProperty("both")) {
assertEquals(1, m.getIntProperty("destQ").intValue());
}
assertEquals(i, m.getIntProperty("i").intValue());
m.acknowledge();
session.commit();
}
for (int i = 0; i < messagesSentAfterBurst; i++) {
ClientMessage m = consumerQ2.receive(5000);
assertNotNull(m);
if (!m.getBooleanProperty("both")) {
assertEquals(2, m.getIntProperty("destQ").intValue());
}
assertEquals(i, m.getIntProperty("i").intValue());
m.acknowledge();
session.commit();
}
waitForNotPaging(serverQueue);
if (sessionConsumerQ3 != null) {
sessionConsumerQ3.close();
}
assertEquals(0, consumerQ3Msgs.intValue());
session.close();
locator.close();
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.
the class PagingTest method testTwoQueuesOneNoRouting.
@Test
public void testTwoQueuesOneNoRouting() throws Exception {
boolean persistentMessages = true;
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int numberOfMessages = 1000;
locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS.concat("-invalid"), new SimpleString(Filter.GENERIC_IGNORED_FILTER), true);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
byte[] body = new byte[MESSAGE_SIZE];
for (int i = 0; i < numberOfMessages; i++) {
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.start();
ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
for (int i = 0; i < numberOfMessages; i++) {
message = consumer.receive(5000);
assertNotNull(message);
message.acknowledge();
assertEquals(i, message.getIntProperty("id").intValue());
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
session.commit();
session.commit();
PagingStore store = server.getPagingManager().getPageStore(ADDRESS);
store.getCursorProvider().cleanup();
long timeout = System.currentTimeMillis() + 5000;
while (store.isPaging() && timeout > System.currentTimeMillis()) {
Thread.sleep(100);
}
// It's async, so need to wait a bit for it happening
assertFalse(server.getPagingManager().getPageStore(ADDRESS).isPaging());
}
use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.
the class PagingTest method testTwoQueuesDifferentFilters.
@Test
public void testTwoQueuesDifferentFilters() throws Exception {
boolean persistentMessages = true;
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int numberOfMessages = 200;
locator = createInVMNonHALocator().setClientFailureCheckPeriod(120000).setConnectionTTL(5000000).setCallTimeout(120000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
// note: if you want to change this, numberOfMessages has to be a multiple of NQUEUES
int NQUEUES = 2;
for (int i = 0; i < NQUEUES; i++) {
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS.concat("=" + i), new SimpleString("propTest=" + i), true);
}
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
byte[] body = new byte[MESSAGE_SIZE];
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty("propTest", i % NQUEUES);
message.putIntProperty("id", i);
producer.send(message);
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
session.start();
for (int nqueue = 0; nqueue < NQUEUES; nqueue++) {
ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS.concat("=" + nqueue));
for (int i = 0; i < (numberOfMessages / NQUEUES); i++) {
message = consumer.receive(500000);
assertNotNull(message);
message.acknowledge();
assertEquals(nqueue, message.getIntProperty("propTest").intValue());
}
assertNull(consumer.receiveImmediate());
consumer.close();
session.commit();
}
PagingStore store = server.getPagingManager().getPageStore(ADDRESS);
store.getCursorProvider().cleanup();
long timeout = System.currentTimeMillis() + 5000;
while (store.isPaging() && timeout > System.currentTimeMillis()) {
Thread.sleep(100);
}
// It's async, so need to wait a bit for it happening
assertFalse(server.getPagingManager().getPageStore(ADDRESS).isPaging());
}
Aggregations