use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingTest method testCommitOnSend.
@Test
public void testCommitOnSend() throws Exception {
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig();
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int numberOfIntegers = 10;
final int numberOfMessages = 500;
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(null, null, false, false, false, false, 0);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
for (int j = 1; j <= numberOfIntegers; j++) {
bodyLocal.writeInt(j);
}
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
}
session.commit();
session.close();
locator.close();
locator = createInVMNonHALocator();
server.stop();
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
sf = createSessionFactory(locator);
session = sf.createSession(null, null, false, false, false, false, 0);
ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
session.start();
for (int i = 0; i < numberOfMessages; i++) {
if (i == 55) {
System.out.println("i = 55");
}
ClientMessage msg = consumer.receive(5000);
Assert.assertNotNull(msg);
msg.acknowledge();
session.commit();
}
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingTest method testPreparePersistent.
@Test
public void testPreparePersistent() throws Exception {
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int numberOfMessages = 5000;
final int numberOfTX = 10;
final int messagesPerTX = numberOfMessages / numberOfTX;
locator = createInVMNonHALocator();
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
byte[] body = new byte[MESSAGE_SIZE];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= MESSAGE_SIZE; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(true);
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 = null;
sf.close();
locator.close();
server.stop();
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
locator = createInVMNonHALocator();
sf = createSessionFactory(locator);
Queue queue = server.locateQueue(ADDRESS);
assertEquals(numberOfMessages, getMessageCount(queue));
LinkedList<Xid> xids = new LinkedList<>();
int msgReceived = 0;
for (int i = 0; i < numberOfTX; i++) {
ClientSession sessionConsumer = sf.createSession(true, false, false);
Xid xid = newXID();
xids.add(xid);
sessionConsumer.start(xid, XAResource.TMNOFLAGS);
sessionConsumer.start();
ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
for (int msgCount = 0; msgCount < messagesPerTX; msgCount++) {
if (msgReceived == numberOfMessages) {
break;
}
msgReceived++;
ClientMessage msg = consumer.receive(10000);
assertNotNull(msg);
msg.acknowledge();
}
sessionConsumer.end(xid, XAResource.TMSUCCESS);
sessionConsumer.prepare(xid);
sessionConsumer.close();
}
ClientSession sessionCheck = sf.createSession(true, true);
ClientConsumer consumer = sessionCheck.createConsumer(PagingTest.ADDRESS);
assertNull(consumer.receiveImmediate());
sessionCheck.close();
assertEquals(numberOfMessages, getMessageCount(queue));
sf.close();
locator.close();
server.stop();
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
waitForServerToStart(server);
queue = server.locateQueue(ADDRESS);
locator = createInVMNonHALocator();
sf = createSessionFactory(locator);
session = sf.createSession(true, false, false);
consumer = session.createConsumer(PagingTest.ADDRESS);
session.start();
assertEquals(numberOfMessages, getMessageCount(queue));
ClientMessage msg = consumer.receive(5000);
if (msg != null) {
while (true) {
ClientMessage msg2 = consumer.receive(1000);
if (msg2 == null) {
break;
}
}
}
assertNull(msg);
for (int i = xids.size() - 1; i >= 0; i--) {
Xid xid = xids.get(i);
session.rollback(xid);
}
xids.clear();
session.close();
session = sf.createSession(false, false, false);
session.start();
consumer = session.createConsumer(PagingTest.ADDRESS);
for (int i = 0; i < numberOfMessages; i++) {
msg = consumer.receive(1000);
assertNotNull(msg);
msg.acknowledge();
assertEquals(i, msg.getIntProperty("id").intValue());
if (i % 500 == 0) {
session.commit();
}
}
session.commit();
session.close();
sf.close();
locator.close();
assertEquals(0, getMessageCount(queue));
waitForNotPaging(queue);
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingTest method testRollbackOnSend.
@Test
public void testRollbackOnSend() throws Exception {
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig();
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int numberOfIntegers = 256;
final int numberOfMessages = 10;
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(null, null, false, false, true, false, 0);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
for (int j = 1; j <= numberOfIntegers; j++) {
bodyLocal.writeInt(j);
}
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
}
session.rollback();
ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
session.start();
Assert.assertNull(consumer.receiveImmediate());
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingTest method testDeleteQueueRestart.
@Test
public void testDeleteQueueRestart() throws Exception {
clearDataRecreateServerDirs();
// disable compact
Configuration config = createDefaultInVMConfig().setJournalDirectory(getJournalDir()).setJournalSyncNonTransactional(false).setJournalCompactMinFiles(0);
ActiveMQServer server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int numberOfMessages = 5000;
locator = createInVMNonHALocator().setConsumerWindowSize(10 * 1024 * 1024).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
SimpleString QUEUE2 = ADDRESS.concat("-2");
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, false, false);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
session.createQueue(PagingTest.ADDRESS, QUEUE2, null, true);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
// This is just to hold some messages as being delivered
ClientConsumerInternal cons = (ClientConsumerInternal) session.createConsumer(ADDRESS);
ClientConsumerInternal cons2 = (ClientConsumerInternal) session.createConsumer(QUEUE2);
ClientMessage message = null;
byte[] body = new byte[MESSAGE_SIZE];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= MESSAGE_SIZE; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
producer.send(message);
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
producer.close();
session.start();
long timeout = System.currentTimeMillis() + 30000;
// I want the buffer full to make sure there are pending messages on the server's side
while (System.currentTimeMillis() < timeout && (cons.getBufferSize() < 1000 || cons2.getBufferSize() < 1000)) {
System.out.println("cons1 buffer = " + cons.getBufferSize() + ", cons2 buffer = " + cons2.getBufferSize());
Thread.sleep(100);
}
assertTrue(cons.getBufferSize() >= 1000);
assertTrue(cons2.getBufferSize() >= 1000);
session.close();
Queue queue = server.locateQueue(QUEUE2);
long deletedQueueID = queue.getID();
server.destroyQueue(QUEUE2);
sf.close();
locator.close();
locator = null;
sf = null;
server.stop();
final HashMap<Integer, AtomicInteger> recordsType = countJournal(config);
for (Map.Entry<Integer, AtomicInteger> entry : recordsType.entrySet()) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
assertNull("The system is acking page records instead of just delete data", recordsType.get(new Integer(JournalRecordIds.ACKNOWLEDGE_CURSOR)));
Pair<List<RecordInfo>, List<PreparedTransactionInfo>> journalData = loadMessageJournal(config);
HashSet<Long> deletedQueueReferences = new HashSet<>();
for (RecordInfo info : journalData.getA()) {
if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
DescribeJournal.ReferenceDescribe ref = (ReferenceDescribe) DescribeJournal.newObjectEncoding(info);
if (ref.refEncoding.queueID == deletedQueueID) {
deletedQueueReferences.add(new Long(info.id));
}
} else if (info.getUserRecordType() == JournalRecordIds.ACKNOWLEDGE_REF) {
AckDescribe ref = (AckDescribe) DescribeJournal.newObjectEncoding(info);
if (ref.refEncoding.queueID == deletedQueueID) {
deletedQueueReferences.remove(new Long(info.id));
}
}
}
if (!deletedQueueReferences.isEmpty()) {
for (Long value : deletedQueueReferences) {
System.out.println("Deleted Queue still has a reference:" + value);
}
fail("Deleted queue still have references");
}
server.start();
locator = createInVMNonHALocator();
locator.setConsumerWindowSize(10 * 1024 * 1024);
sf = locator.createSessionFactory();
session = sf.createSession(false, false, false);
cons = (ClientConsumerInternal) session.createConsumer(ADDRESS);
session.start();
for (int i = 0; i < numberOfMessages; i++) {
message = cons.receive(5000);
assertNotNull(message);
message.acknowledge();
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
producer.close();
session.close();
queue = server.locateQueue(PagingTest.ADDRESS);
assertEquals(0, getMessageCount(queue));
timeout = System.currentTimeMillis() + 10000;
while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging()) {
Thread.sleep(100);
}
assertFalse(queue.getPageSubscription().getPagingStore().isPaging());
server.stop();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingTest method testTwoQueuesAndOneInativeQueue.
@Test
public void testTwoQueuesAndOneInativeQueue() throws Exception {
boolean persistentMessages = true;
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
try {
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(120000).setConnectionTTL(5000000).setCallTimeout(120000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, false, false);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS.concat("=1"), null, true);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS.concat("=2"), null, true);
// A queue with an impossible filter
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS.concat("-3"), new SimpleString("nothing='something'"), true);
PagingStore store = server.getPagingManager().getPageStore(ADDRESS);
Queue queue = server.locateQueue(PagingTest.ADDRESS.concat("=1"));
queue.getPageSubscription().getPagingStore().startPaging();
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(new byte[1024]);
producer.send(message);
session.commit();
session.start();
for (int msg = 1; msg <= 2; msg++) {
ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS.concat("=" + msg));
message = consumer.receive(5000);
assertNotNull(message);
message.acknowledge();
assertNull(consumer.receiveImmediate());
consumer.close();
}
session.commit();
session.close();
store.getCursorProvider().cleanup();
waitForNotPaging(server.locateQueue(PagingTest.ADDRESS.concat("=1")));
sf.close();
locator.close();
} finally {
try {
server.stop();
} catch (Throwable ignored) {
}
}
}
Aggregations