Here are the examples of the java api class org.apache.activemq.artemis.core.journal.impl.JournalImpl taken from open source projects.
1. CompactJournal#compactJournal()
Project: activemq-artemis
File: CompactJournal.java
File: CompactJournal.java
void compactJournal(final File directory, final String journalPrefix, final String journalSuffix, final int minFiles, final int fileSize, final IOCriticalErrorListener listener) throws Exception { NIOSequentialFileFactory nio = new NIOSequentialFileFactory(directory, listener, 1); JournalImpl journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1); journal.start(); journal.loadInternalOnly(); journal.compact(); journal.stop(); }
2. ValidateTransactionHealthTest#reload()
Project: activemq-artemis
File: ValidateTransactionHealthTest.java
File: ValidateTransactionHealthTest.java
private void reload(final String type, final String journalDir, final long numberOfRecords, final int numberOfThreads) throws Exception { JournalImpl journal = ValidateTransactionHealthTest.createJournal(type, journalDir); journal.start(); Loader loadTest = new Loader(numberOfRecords); journal.load(loadTest); Assert.assertEquals(numberOfRecords * numberOfThreads, loadTest.numberOfAdds); Assert.assertEquals(0, loadTest.numberOfPreparedTransactions); Assert.assertEquals(0, loadTest.numberOfUpdates); Assert.assertEquals(0, loadTest.numberOfDeletes); journal.stop(); if (loadTest.ex != null) { throw loadTest.ex; } }
3. JournalCrashTest#printJournal()
Project: activemq-artemis
File: JournalCrashTest.java
File: JournalCrashTest.java
/** * @throws Exception */ private void printJournal() throws Exception { NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir()), 100); JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 2, 0, 0, factory, "activemq-data", "amq", 100); ArrayList<RecordInfo> records = new ArrayList<>(); ArrayList<PreparedTransactionInfo> transactions = new ArrayList<>(); journal.start(); journal.load(records, transactions, null); // System.out.println("==============================================="); // System.out.println("Journal records at the end:"); // // for (RecordInfo record : records) // { // System.out.println(record.id + ", update = " + record.isUpdate); // } journal.stop(); }
4. JournalImplTestBase#createJournal()
Project: activemq-artemis
File: JournalImplTestBase.java
File: JournalImplTestBase.java
public void createJournal() throws Exception { journal = new JournalImpl(fileSize, minFiles, poolSize, 0, 0, fileFactory, filePrefix, fileExtension, maxAIO) { @Override public void onCompactDone() { latchDone.countDown(); System.out.println("Waiting on Compact"); try { latchWait.await(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Waiting on Compact Done"); } }; journal.setAutoReclaim(false); addActiveMQComponent(journal); }
5. JournalAsyncTest#setupJournal()
Project: activemq-artemis
File: JournalAsyncTest.java
File: JournalAsyncTest.java
// Private ------------------------------------------------------- private void setupJournal(final int journalSize, final int alignment, final int numberOfMinimalFiles) throws Exception { if (factory == null) { factory = new FakeSequentialFileFactory(alignment, true); } if (journalImpl != null) { journalImpl.stop(); } journalImpl = new JournalImpl(journalSize, numberOfMinimalFiles, numberOfMinimalFiles, 0, 0, factory, "tt", "tt", 1000); journalImpl.start(); records.clear(); transactions.clear(); journalImpl.load(records, transactions, null); }
6. MixupCompactorTestBase#createJournal()
Project: activemq-artemis
File: MixupCompactorTestBase.java
File: MixupCompactorTestBase.java
@Override public void createJournal() throws Exception { journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, fileFactory, filePrefix, fileExtension, maxAIO) { @Override public void onCompactDone() { startedCompactingLatch.countDown(); try { releaseCompactingLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } } }; journal.setAutoReclaim(false); }
7. ActiveMQTestBase#countJournal()
Project: activemq-artemis
File: ActiveMQTestBase.java
File: ActiveMQTestBase.java
/** * Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type, * independent of being deleted or not * * @param config * @return * @throws Exception */ protected HashMap<Integer, AtomicInteger> countJournal(Configuration config) throws Exception { final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>(); SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1); JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1); List<JournalFile> filesToRead = messagesJournal.orderFiles(); for (JournalFile file : filesToRead) { JournalImpl.readJournalFile(messagesFF, file, new RecordTypeCounter(recordsType)); } return recordsType; }
8. EncodeJournal#exportJournal()
Project: activemq-artemis
File: EncodeJournal.java
File: EncodeJournal.java
public static void exportJournal(final String directory, final String journalPrefix, final String journalSuffix, final int minFiles, final int fileSize, final PrintStream out) throws Exception { NIOSequentialFileFactory nio = new NIOSequentialFileFactory(new File(directory), null, 1); JournalImpl journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1); List<JournalFile> files = journal.orderFiles(); for (JournalFile file : files) { out.println("#File," + file); exportJournalFile(out, nio, file); } }
9. AddAndRemoveStressTest#testInsertUpdateAndLoad()
Project: activemq-artemis
File: AddAndRemoveStressTest.java
File: AddAndRemoveStressTest.java
@Test public void testInsertUpdateAndLoad() throws Exception { SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 1000); JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000); impl.start(); impl.load(AddAndRemoveStressTest.dummyLoader); for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) { if (i % 10000 == 0) { System.out.println("Append " + i); } impl.appendAddRecord(i, (byte) 21, new SimpleEncoding(40, (byte) 'f'), false); impl.appendUpdateRecord(i, (byte) 22, new SimpleEncoding(40, (byte) 'g'), false); } impl.stop(); factory = new AIOSequentialFileFactory(getTestDirfile(), 1000); impl = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, factory, "amq", "amq", 1000); impl.start(); impl.load(AddAndRemoveStressTest.dummyLoader); for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) { if (i % 10000 == 0) { System.out.println("Delete " + i); } impl.appendDeleteRecord(i, false); } impl.stop(); factory = new AIOSequentialFileFactory(getTestDirfile(), 1000); impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000); impl.start(); ArrayList<RecordInfo> info = new ArrayList<>(); ArrayList<PreparedTransactionInfo> trans = new ArrayList<>(); impl.load(info, trans, null); if (info.size() > 0) { System.out.println("Info ID: " + info.get(0).id); } impl.forceMoveNextFile(); impl.checkReclaimStatus(); impl.stop(); Assert.assertEquals(0, info.size()); Assert.assertEquals(0, trans.size()); Assert.assertEquals(0, impl.getDataFilesCount()); System.out.println("Size = " + impl.getDataFilesCount()); }
10. AddAndRemoveStressTest#testInsertAndLoad()
Project: activemq-artemis
File: AddAndRemoveStressTest.java
File: AddAndRemoveStressTest.java
// Attributes ---------------------------------------------------- // Static -------------------------------------------------------- // Constructors -------------------------------------------------- // Public -------------------------------------------------------- @Test public void testInsertAndLoad() throws Exception { SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 1000); JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000); impl.start(); impl.load(AddAndRemoveStressTest.dummyLoader); for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) { if (i % 10000 == 0) { System.out.println("Append " + i); } impl.appendAddRecord(i, (byte) 0, new SimpleEncoding(1024, (byte) 'f'), false); } impl.stop(); factory = new AIOSequentialFileFactory(getTestDirfile(), 1000); impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000); impl.start(); impl.load(AddAndRemoveStressTest.dummyLoader); for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++) { if (i % 10000 == 0) { System.out.println("Delete " + i); } impl.appendDeleteRecord(i, false); } impl.stop(); factory = new AIOSequentialFileFactory(getTestDirfile(), 1000); impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, 0, factory, "amq", "amq", 1000); impl.start(); ArrayList<RecordInfo> info = new ArrayList<>(); ArrayList<PreparedTransactionInfo> trans = new ArrayList<>(); impl.load(info, trans, null); impl.forceMoveNextFile(); if (info.size() > 0) { System.out.println("Info ID: " + info.get(0).id); } impl.stop(); Assert.assertEquals(0, info.size()); Assert.assertEquals(0, trans.size()); Assert.assertEquals(0, impl.getDataFilesCount()); }
11. BridgeTest#loadQueues()
Project: activemq-artemis
File: BridgeTest.java
File: BridgeTest.java
/** * It will inspect the journal directly and determine if there are queues on this journal, * * @param serverToInvestigate * @return a Map containing the reference counts per queue * @throws Exception */ protected Map<Long, AtomicInteger> loadQueues(ActiveMQServer serverToInvestigate) throws Exception { SequentialFileFactory messagesFF = new NIOSequentialFileFactory(serverToInvestigate.getConfiguration().getJournalLocation(), 1); JournalImpl messagesJournal = new JournalImpl(serverToInvestigate.getConfiguration().getJournalFileSize(), serverToInvestigate.getConfiguration().getJournalMinFiles(), serverToInvestigate.getConfiguration().getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1); List<RecordInfo> records = new LinkedList<>(); List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>(); messagesJournal.start(); messagesJournal.load(records, preparedTransactions, null); // These are more immutable integers Map<Long, AtomicInteger> messageRefCounts = new HashMap<>(); for (RecordInfo info : records) { Object o = DescribeJournal.newObjectEncoding(info); if (info.getUserRecordType() == JournalRecordIds.ADD_REF) { DescribeJournal.ReferenceDescribe ref = (DescribeJournal.ReferenceDescribe) o; AtomicInteger count = messageRefCounts.get(ref.refEncoding.queueID); if (count == null) { count = new AtomicInteger(1); messageRefCounts.put(ref.refEncoding.queueID, count); } else { count.incrementAndGet(); } } } messagesJournal.stop(); return messageRefCounts; }
12. RedeliveryConsumerTest#internaltestInfiniteDedeliveryMessageOnPersistent()
Project: activemq-artemis
File: RedeliveryConsumerTest.java
File: RedeliveryConsumerTest.java
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()); }
13. PagingTest#testMissingTXEverythingAcked()
Project: activemq-artemis
File: PagingTest.java
File: PagingTest.java
@Test public void testMissingTXEverythingAcked() throws Exception { clearDataRecreateServerDirs(); Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false); server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX, new HashMap<String, AddressSettings>()); 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(); } finally { try { server.stop(); } catch (Throwable ignored) { } } ArrayList<RecordInfo> records = new ArrayList<>(); List<PreparedTransactionInfo> list = new ArrayList<>(); JournalImpl jrn = new JournalImpl(config.getJournalFileSize(), 2, 2, 0, 0, new NIOSequentialFileFactory(server.getConfiguration().getJournalLocation(), 1), "activemq-data", "amq", 1); 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(); server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX, new HashMap<String, AddressSettings>()); 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(); }
14. ActiveMQTestBase#internalCountJournalLivingRecords()
Project: activemq-artemis
File: ActiveMQTestBase.java
File: ActiveMQTestBase.java
/** * 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; }
15. DecodeJournal#importJournal()
Project: activemq-artemis
File: DecodeJournal.java
File: DecodeJournal.java
public static void importJournal(final String directory, final String journalPrefix, final String journalSuffix, final int minFiles, final int fileSize, final Reader reader) throws Exception { File journalDir = new File(directory); if (!journalDir.exists()) { if (!journalDir.mkdirs()) System.err.println("Could not create directory " + directory); } NIOSequentialFileFactory nio = new NIOSequentialFileFactory(new File(directory), null, 1); JournalImpl journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1); if (journal.orderFiles().size() != 0) { throw new IllegalStateException("Import needs to create a brand new journal"); } journal.start(); // The journal is empty, as we checked already. Calling load just to initialize the internal data journal.loadInternalOnly(); BufferedReader buffReader = new BufferedReader(reader); String line; HashMap<Long, AtomicInteger> txCounters = new HashMap<>(); long lineNumber = 0; Map<Long, JournalRecord> journalRecords = journal.getRecords(); while ((line = buffReader.readLine()) != null) { lineNumber++; String[] splitLine = line.split(","); if (splitLine[0].equals("#File")) { txCounters.clear(); continue; } Properties lineProperties = parseLine(splitLine); String operation = null; try { operation = lineProperties.getProperty("operation"); if (operation.equals("AddRecord")) { RecordInfo info = parseRecord(lineProperties); journal.appendAddRecord(info.id, info.userRecordType, info.data, false); } else if (operation.equals("AddRecordTX")) { long txID = parseLong("txID", lineProperties); AtomicInteger counter = getCounter(txID, txCounters); counter.incrementAndGet(); RecordInfo info = parseRecord(lineProperties); journal.appendAddRecordTransactional(txID, info.id, info.userRecordType, info.data); } else if (operation.equals("AddRecordTX")) { long txID = parseLong("txID", lineProperties); AtomicInteger counter = getCounter(txID, txCounters); counter.incrementAndGet(); RecordInfo info = parseRecord(lineProperties); journal.appendAddRecordTransactional(txID, info.id, info.userRecordType, info.data); } else if (operation.equals("UpdateTX")) { long txID = parseLong("txID", lineProperties); AtomicInteger counter = getCounter(txID, txCounters); counter.incrementAndGet(); RecordInfo info = parseRecord(lineProperties); journal.appendUpdateRecordTransactional(txID, info.id, info.userRecordType, info.data); } else if (operation.equals("Update")) { RecordInfo info = parseRecord(lineProperties); journal.appendUpdateRecord(info.id, info.userRecordType, info.data, false); } else if (operation.equals("DeleteRecord")) { long id = parseLong("id", lineProperties); // If not found it means the append/update records were reclaimed already if (journalRecords.get(id) != null) { journal.appendDeleteRecord(id, false); } } else if (operation.equals("DeleteRecordTX")) { long txID = parseLong("txID", lineProperties); long id = parseLong("id", lineProperties); AtomicInteger counter = getCounter(txID, txCounters); counter.incrementAndGet(); // If not found it means the append/update records were reclaimed already if (journalRecords.get(id) != null) { journal.appendDeleteRecordTransactional(txID, id); } } else if (operation.equals("Prepare")) { long txID = parseLong("txID", lineProperties); int numberOfRecords = parseInt("numberOfRecords", lineProperties); AtomicInteger counter = getCounter(txID, txCounters); byte[] data = parseEncoding("extraData", lineProperties); if (counter.get() == numberOfRecords) { journal.appendPrepareRecord(txID, data, false); } else { System.err.println("Transaction " + txID + " at line " + lineNumber + " is incomplete. The prepare record expected " + numberOfRecords + " while the import only had " + counter); } } else if (operation.equals("Commit")) { long txID = parseLong("txID", lineProperties); int numberOfRecords = parseInt("numberOfRecords", lineProperties); AtomicInteger counter = getCounter(txID, txCounters); if (counter.get() == numberOfRecords) { journal.appendCommitRecord(txID, false); } else { System.err.println("Transaction " + txID + " at line " + lineNumber + " is incomplete. The commit record expected " + numberOfRecords + " while the import only had " + counter); } } else if (operation.equals("Rollback")) { long txID = parseLong("txID", lineProperties); journal.appendRollbackRecord(txID, false); } else { System.err.println("Invalid operation " + operation + " at line " + lineNumber); } } catch (Exception ex) { System.err.println("Error at line " + lineNumber + ", operation=" + operation + " msg = " + ex.getMessage()); } } journal.stop(); }
16. AlignedJournalImplTest#testAlignmentOverReload()
Project: activemq-artemis
File: AlignedJournalImplTest.java
File: AlignedJournalImplTest.java
@Test public void testAlignmentOverReload() throws Exception { factory = new FakeSequentialFileFactory(512, false); journalImpl = new JournalImpl(512 + 512 * 3, 20, 20, 0, 0, factory, "amq", "amq", 1000); journalImpl.start(); journalImpl.load(AlignedJournalImplTest.dummyLoader); journalImpl.appendAddRecord(1L, (byte) 0, new SimpleEncoding(100, (byte) 'a'), false); journalImpl.appendAddRecord(2L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false); journalImpl.appendAddRecord(3L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false); journalImpl.appendAddRecord(4L, (byte) 0, new SimpleEncoding(100, (byte) 'b'), false); journalImpl.stop(); journalImpl = new JournalImpl(512 + 1024 + 512, 20, 20, 0, 0, factory, "amq", "amq", 1000); addActiveMQComponent(journalImpl); journalImpl.start(); journalImpl.load(AlignedJournalImplTest.dummyLoader); // It looks silly, but this forceMoveNextFile is in place to replicate one // specific bug caught during development journalImpl.forceMoveNextFile(); journalImpl.appendDeleteRecord(1L, false); journalImpl.appendDeleteRecord(2L, false); journalImpl.appendDeleteRecord(3L, false); journalImpl.appendDeleteRecord(4L, false); journalImpl.stop(); journalImpl = new JournalImpl(512 + 1024 + 512, 20, 20, 0, 0, factory, "amq", "amq", 1000); addActiveMQComponent(journalImpl); journalImpl.start(); ArrayList<RecordInfo> info = new ArrayList<>(); ArrayList<PreparedTransactionInfo> trans = new ArrayList<>(); journalImpl.load(info, trans, null); Assert.assertEquals(0, info.size()); Assert.assertEquals(0, trans.size()); }
17. ValidateTransactionHealthTest#appendData()
Project: activemq-artemis
File: ValidateTransactionHealthTest.java
File: ValidateTransactionHealthTest.java
public static JournalImpl appendData(final String journalType, final String journalDir, final long numberOfElements, final int transactionSize, final int numberOfThreads) throws Exception { final JournalImpl journal = ValidateTransactionHealthTest.createJournal(journalType, journalDir); journal.start(); journal.load(new LoaderCallback() { @Override public void addPreparedTransaction(final PreparedTransactionInfo preparedTransaction) { } @Override public void addRecord(final RecordInfo info) { } @Override public void deleteRecord(final long id) { } @Override public void updateRecord(final RecordInfo info) { } @Override public void failedTransaction(final long transactionID, final List<RecordInfo> records, final List<RecordInfo> recordsToDelete) { } }); LocalThread[] threads = new LocalThread[numberOfThreads]; final AtomicLong sequenceTransaction = new AtomicLong(); for (int i = 0; i < numberOfThreads; i++) { threads[i] = new LocalThread(journal, numberOfElements, transactionSize, sequenceTransaction); threads[i].start(); } Exception e = null; for (LocalThread t : threads) { t.join(); if (t.e != null) { e = t.e; } } if (e != null) { throw e; } return journal; }
18. BackupSyncJournalTest#testReserveFileIdValuesOnBackup()
Project: activemq-artemis
File: BackupSyncJournalTest.java
File: BackupSyncJournalTest.java
@Test public void testReserveFileIdValuesOnBackup() throws Exception { final int totalRounds = 50; createProducerSendSomeMessages(); JournalImpl messageJournal = getMessageJournalFromServer(liveServer); for (int i = 0; i < totalRounds; i++) { messageJournal.forceMoveNextFile(); sendMessages(session, producer, n_msgs); } Queue queue = liveServer.getServer().locateQueue(ADDRESS); PagingStore store = queue.getPageSubscription().getPagingStore(); // what would make the verification on similar journal to fail after the recovery if (store.isPaging()) { store.forceAnotherPage(); } backupServer.start(); // Deliver messages with Backup in-sync waitForRemoteBackup(sessionFactory, BACKUP_WAIT_TIME, false, backupServer.getServer()); final JournalImpl backupMsgJournal = getMessageJournalFromServer(backupServer); sendMessages(session, producer, n_msgs); // what would make the verification on similar journal to fail after the recovery if (store.isPaging()) { store.forceAnotherPage(); } // Deliver messages with Backup up-to-date syncDelay.deliverUpToDateMsg(); waitForRemoteBackup(sessionFactory, BACKUP_WAIT_TIME, true, backupServer.getServer()); // SEND more messages, now with the backup replicating sendMessages(session, producer, n_msgs); // what would make the verification on similar journal to fail after the recovery if (store.isPaging()) { store.forceAnotherPage(); } Set<Pair<Long, Integer>> liveIds = getFileIds(messageJournal); int size = messageJournal.getFileSize(); PagingStore ps = liveServer.getServer().getPagingManager().getPageStore(ADDRESS); if (ps.getPageSizeBytes() == PAGE_SIZE) { assertTrue("isStarted", ps.isStarted()); assertFalse("start paging should return false, because we expect paging to be running", ps.startPaging()); } finishSyncAndFailover(); assertEquals("file sizes must be the same", size, backupMsgJournal.getFileSize()); Set<Pair<Long, Integer>> backupIds = getFileIds(backupMsgJournal); int total = 0; for (Pair<Long, Integer> pair : liveIds) { total += pair.getB(); } int totalBackup = 0; for (Pair<Long, Integer> pair : backupIds) { totalBackup += pair.getB(); } assertEquals("number of records must match ", total, totalBackup); // "+ 2": there two other calls that send N_MSGS. for (int i = 0; i < totalRounds + 3; i++) { receiveMsgsInRange(0, n_msgs); } assertNoMoreMessages(); }
19. AlignedJournalImplTest#setupAndLoadJournal()
Project: activemq-artemis
File: AlignedJournalImplTest.java
File: AlignedJournalImplTest.java
private void setupAndLoadJournal(final int journalSize, final int alignment, final int numberOfMinimalFiles) throws Exception { if (factory == null) { factory = new FakeSequentialFileFactory(alignment, true); } if (journalImpl != null) { journalImpl.stop(); } journalImpl = new JournalImpl(journalSize, numberOfMinimalFiles, numberOfMinimalFiles, 0, 0, factory, "tt", "tt", 1000); addActiveMQComponent(journalImpl); journalImpl.start(); records.clear(); transactions.clear(); incompleteTransactions.clear(); journalImpl.load(records, transactions, new TransactionFailureCallback() { @Override public void failedTransaction(final long transactionID, final List<RecordInfo> records, final List<RecordInfo> recordsToDelete) { System.out.println("records.length = " + records.size()); incompleteTransactions.add(transactionID); } }); }
20. JournalCleanupCompactStressTest#setUp()
Project: activemq-artemis
File: JournalCleanupCompactStressTest.java
File: JournalCleanupCompactStressTest.java
@Override @Before public void setUp() throws Exception { super.setUp(); threadPool = Executors.newFixedThreadPool(20, tFactory); executorFactory = new OrderedExecutorFactory(threadPool); testExecutor = executorFactory.getExecutor(); maxRecords = new Semaphore(MAX_WRITES); errors.set(0); File dir = new File(getTemporaryDir()); dir.mkdirs(); SequentialFileFactory factory; int maxAIO; if (LibaioContext.isLoaded()) { factory = new AIOSequentialFileFactory(dir, 10); maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoAio(); } else { factory = new NIOSequentialFileFactory(dir, true, 1); maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoNio(); } journal = new JournalImpl(50 * 1024, 20, 20, 50, ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage(), factory, "activemq-data", "amq", maxAIO) { @Override protected void onCompactLockingTheJournal() throws Exception { } @Override protected void onCompactStart() throws Exception { testExecutor.execute(new Runnable() { @Override public void run() { try { // System.out.println("OnCompactStart enter"); if (running) { long id = idGen.generateID(); journal.appendAddRecord(id, (byte) 0, new byte[] { 1, 2, 3 }, false); journal.forceMoveNextFile(); journal.appendDeleteRecord(id, id == 20); } // System.out.println("OnCompactStart leave"); } catch (Exception e) { e.printStackTrace(); errors.incrementAndGet(); } } }); } }; journal.start(); journal.loadInternalOnly(); }
21. JournalImplTestUnit#internaltestSpeedNonTransactional()
Project: activemq-artemis
File: JournalImplTestUnit.java
File: JournalImplTestUnit.java
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(); }
22. ValidateTransactionHealthTest#createJournal()
Project: activemq-artemis
File: ValidateTransactionHealthTest.java
File: ValidateTransactionHealthTest.java
public static JournalImpl createJournal(final String journalType, final String journalDir) { JournalImpl journal = new JournalImpl(10485760, 2, 2, 0, 0, ValidateTransactionHealthTest.getFactory(journalType, journalDir), "journaltst", "tst", 500); return journal; }
23. NIOJournalCompactTest#testCompactFirstFileReclaimed()
Project: activemq-artemis
File: NIOJournalCompactTest.java
File: NIOJournalCompactTest.java
@Test public void testCompactFirstFileReclaimed() throws Exception { setup(2, 60 * 1024, false); final byte recordType = (byte) 0; journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, fileFactory, filePrefix, fileExtension, maxAIO); journal.start(); journal.loadInternalOnly(); journal.appendAddRecord(1, recordType, "test".getBytes(), true); journal.forceMoveNextFile(); journal.appendUpdateRecord(1, recordType, "update".getBytes(), true); journal.appendDeleteRecord(1, true); journal.appendAddRecord(2, recordType, "finalRecord".getBytes(), true); for (int i = 10; i < 100; i++) { journal.appendAddRecord(i, recordType, ("tst" + i).getBytes(), true); journal.forceMoveNextFile(); journal.appendUpdateRecord(i, recordType, ("uptst" + i).getBytes(), true); journal.appendDeleteRecord(i, true); } journal.testCompact(); journal.stop(); List<RecordInfo> records1 = new ArrayList<>(); List<PreparedTransactionInfo> preparedRecords = new ArrayList<>(); journal.start(); journal.load(records1, preparedRecords, null); assertEquals(1, records1.size()); }
24. ActiveMQTestBase#loadMessageJournal()
Project: activemq-artemis
File: ActiveMQTestBase.java
File: ActiveMQTestBase.java
/** * Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type, * independent of being deleted or not * * @param config * @return * @throws Exception */ protected Pair<List<RecordInfo>, List<PreparedTransactionInfo>> loadMessageJournal(Configuration config) throws Exception { JournalImpl messagesJournal = null; try { SequentialFileFactory messagesFF = new NIOSequentialFileFactory(new File(getJournalDir()), null, 1); messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1); final List<RecordInfo> committedRecords = new LinkedList<>(); final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>(); messagesJournal.start(); messagesJournal.load(committedRecords, preparedTransactions, null, false); return new Pair<>(committedRecords, preparedTransactions); } finally { try { if (messagesJournal != null) { messagesJournal.stop(); } } catch (Throwable ignored) { } } }
25. DescribeJournal#describeMessagesJournal()
Project: activemq-artemis
File: DescribeJournal.java
File: DescribeJournal.java
public static DescribeJournal describeMessagesJournal(final File messagesDir) throws Exception { SequentialFileFactory messagesFF = new NIOSequentialFileFactory(messagesDir, null, 1); // Will use only default values. The load function should adapt to anything different ConfigurationImpl defaultValues = new ConfigurationImpl(); JournalImpl messagesJournal = new JournalImpl(defaultValues.getJournalFileSize(), defaultValues.getJournalMinFiles(), defaultValues.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1); return describeJournal(messagesFF, messagesJournal, messagesDir); }
26. DescribeJournal#describeBindingsJournal()
Project: activemq-artemis
File: DescribeJournal.java
File: DescribeJournal.java
public static void describeBindingsJournal(final File bindingsDir) throws Exception { SequentialFileFactory bindingsFF = new NIOSequentialFileFactory(bindingsDir, null, 1); JournalImpl bindings = new JournalImpl(1024 * 1024, 2, 2, -1, 0, bindingsFF, "activemq-bindings", "bindings", 1); describeJournal(bindingsFF, bindings, bindingsDir); }