use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo 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.PreparedTransactionInfo 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.PreparedTransactionInfo in project activemq-artemis by apache.
the class PagingTest method testMissingTXEverythingAcked.
@Test
public void testMissingTXEverythingAcked() 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;
try {
locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
session.createQueue(ADDRESS.toString(), "q1", true);
session.createQueue(ADDRESS.toString(), "q2", 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 % messagesPerTX == 0) {
session.commit();
}
}
session.commit();
session.close();
ArrayList<RecordInfo> records = new ArrayList<>();
List<PreparedTransactionInfo> list = new ArrayList<>();
server.getStorageManager().getMessageJournal().stop();
Journal jrn = server.getStorageManager().getMessageJournal();
jrn.start();
jrn.load(records, list, null);
// Delete everything from the journal
for (RecordInfo info : records) {
if (!info.isUpdate && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_VALUE && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_INC && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COMPLETE) {
jrn.appendDeleteRecord(info.id, false);
}
}
jrn.stop();
} finally {
try {
server.stop();
} catch (Throwable ignored) {
}
}
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession sess = csf.createSession();
sess.start();
ClientConsumer cons = sess.createConsumer("q1");
assertNull(cons.receiveImmediate());
ClientConsumer cons2 = sess.createConsumer("q2");
assertNull(cons2.receiveImmediate());
Queue q1 = server.locateQueue(new SimpleString("q1"));
Queue q2 = server.locateQueue(new SimpleString("q2"));
q1.getPageSubscription().cleanupEntries(false);
q2.getPageSubscription().cleanupEntries(false);
PageCursorProvider provider = q1.getPageSubscription().getPagingStore().getCursorProvider();
provider.cleanup();
waitForNotPaging(q1);
sess.close();
}
use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class JournalPageCountSizeTest method testPageCountRecordSize.
@Test
public void testPageCountRecordSize() throws Exception {
long tx = server.getStorageManager().generateID();
server.getStorageManager().storePageCounter(tx, 1, 1, 100);
server.getStorageManager().commit(tx);
server.getStorageManager().stop();
JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
List<RecordInfo> committedRecords = new LinkedList<>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
try {
journalStorageManager.getMessageJournal().start();
journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
PageCountRecord encoding = new PageCountRecord();
encoding.decode(buff);
Assert.assertEquals(100, encoding.getPersistentSize());
} finally {
journalStorageManager.getMessageJournal().stop();
}
}
use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class JournalPageCountSizeTest method testPageCursorCounterRecordSize.
@Test
public void testPageCursorCounterRecordSize() throws Exception {
server.getStorageManager().storePageCounterInc(1, 1, 1000);
server.getStorageManager().stop();
JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
List<RecordInfo> committedRecords = new LinkedList<>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
try {
journalStorageManager.getMessageJournal().start();
journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
PageCountRecordInc encoding = new PageCountRecordInc();
encoding.decode(buff);
Assert.assertEquals(1000, encoding.getPersistentSize());
} finally {
journalStorageManager.getMessageJournal().stop();
}
}
Aggregations