use of org.apache.activemq.artemis.core.journal.RecordInfo in project activemq-artemis by apache.
the class RedeliveryConsumerTest method internaltestInfiniteDedeliveryMessageOnPersistent.
private void internaltestInfiniteDedeliveryMessageOnPersistent(final boolean strict) throws Exception {
setUp(strict);
ClientSession session = factory.createSession(false, false, false);
RedeliveryConsumerTest.log.info("created");
ClientProducer prod = session.createProducer(ADDRESS);
prod.send(createTextMessage(session, "Hello"));
session.commit();
session.close();
int expectedCount = 1;
for (int i = 0; i < 700; i++) {
session = factory.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
assertEquals(expectedCount, msg.getDeliveryCount());
if (i % 100 == 0) {
expectedCount++;
msg.acknowledge();
session.rollback();
}
session.close();
}
factory.close();
server.stop();
setUp(false);
for (int i = 0; i < 700; i++) {
session = factory.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
assertEquals(expectedCount, msg.getDeliveryCount());
session.close();
}
server.stop();
JournalImpl journal = new JournalImpl(server.getConfiguration().getJournalFileSize(), 2, 2, 0, 0, new NIOSequentialFileFactory(server.getConfiguration().getJournalLocation(), 1), "activemq-data", "amq", 1);
final AtomicInteger updates = new AtomicInteger();
journal.start();
journal.load(new LoaderCallback() {
@Override
public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
}
@Override
public void updateRecord(RecordInfo info) {
if (info.userRecordType == JournalRecordIds.UPDATE_DELIVERY_COUNT) {
updates.incrementAndGet();
}
}
@Override
public void deleteRecord(long id) {
}
@Override
public void addRecord(RecordInfo info) {
}
@Override
public void addPreparedTransaction(PreparedTransactionInfo preparedTransaction) {
}
});
journal.stop();
assertEquals(7, updates.get());
}
use of org.apache.activemq.artemis.core.journal.RecordInfo in project activemq-artemis by apache.
the class JournalImplTestUnit method internaltestSpeedNonTransactional.
private void internaltestSpeedNonTransactional() throws Exception {
final long numMessages = 10000;
int numFiles = (int) ((numMessages * 1024 + 512) / (10 * 1024 * 1024) * 1.3);
if (numFiles < 2) {
numFiles = 2;
}
JournalImplTestUnit.log.debug("num Files=" + numFiles);
Journal journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
JournalImplTestUnit.log.debug("Adding data");
SimpleEncoding data = new SimpleEncoding(700, (byte) 'j');
long start = System.currentTimeMillis();
for (int i = 0; i < numMessages; i++) {
journal.appendAddRecord(i, (byte) 0, data, true);
}
long end = System.currentTimeMillis();
double rate = 1000 * (double) numMessages / (end - start);
JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
journal.stop();
journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
journal.stop();
}
use of org.apache.activemq.artemis.core.journal.RecordInfo in project activemq-artemis by apache.
the class JournalImplTestUnit method testSpeedTransactional.
@Test
public void testSpeedTransactional() throws Exception {
Journal journal = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
try {
final int numMessages = 50050;
SimpleEncoding data = new SimpleEncoding(1024, (byte) 'j');
long start = System.currentTimeMillis();
int count = 0;
double[] rates = new double[50];
for (int i = 0; i < 50; i++) {
long startTrans = System.currentTimeMillis();
for (int j = 0; j < 1000; j++) {
journal.appendAddRecordTransactional(i, count++, (byte) 0, data);
}
journal.appendCommitRecord(i, true);
long endTrans = System.currentTimeMillis();
rates[i] = 1000 * (double) 1000 / (endTrans - startTrans);
}
long end = System.currentTimeMillis();
for (double rate : rates) {
JournalImplTestUnit.log.info("Transaction Rate = " + rate + " records/sec");
}
double rate = 1000 * (double) numMessages / (end - start);
JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
} finally {
journal.stop();
}
}
use of org.apache.activemq.artemis.core.journal.RecordInfo in project activemq-artemis by apache.
the class ActiveMQTestBase method internalCountJournalLivingRecords.
/**
* This method will load a journal and count the living records
*
* @param config
* @param messageJournal if true -> MessageJournal, false -> BindingsJournal
* @return
* @throws Exception
*/
protected HashMap<Integer, AtomicInteger> internalCountJournalLivingRecords(Configuration config, boolean messageJournal) throws Exception {
final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
SequentialFileFactory ff;
JournalImpl journal;
if (messageJournal) {
ff = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1);
journal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, ff, "activemq-data", "amq", 1);
} else {
ff = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
journal = new JournalImpl(1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), ff, "activemq-bindings", "bindings", 1);
}
journal.start();
final List<RecordInfo> committedRecords = new LinkedList<>();
final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
journal.load(committedRecords, preparedTransactions, null, false);
for (RecordInfo info : committedRecords) {
Integer ikey = new Integer(info.getUserRecordType());
AtomicInteger value = recordsType.get(ikey);
if (value == null) {
value = new AtomicInteger();
recordsType.put(ikey, value);
}
value.incrementAndGet();
}
journal.stop();
return recordsType;
}
use of org.apache.activemq.artemis.core.journal.RecordInfo 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();
}
Aggregations