/** @throws Exception */ private void printJournal() throws Exception { NIOSequentialFileFactory factory = new NIOSequentialFileFactory(getJournalDir()); JournalImpl journal = new JournalImpl( HornetQDefaultConfiguration.getDefaultJournalFileSize(), 2, 0, 0, factory, "hornetq-data", "hq", 100); ArrayList<RecordInfo> records = new ArrayList<RecordInfo>(); ArrayList<PreparedTransactionInfo> transactions = new ArrayList<PreparedTransactionInfo>(); 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(); }
/** * This will simulate what would happen with topic creationg where a single record is supposed to * be created on the journal * * @throws Exception */ @Test public void testDuplicateDestinationsOnTopic() throws Exception { for (int i = 0; i < 5; i++) { if (server.locateQueue(SimpleString.toSimpleString("jms.topic.tt")) == null) { server.createQueue( SimpleString.toSimpleString("jms.topic.tt"), SimpleString.toSimpleString("jms.topic.tt"), SimpleString.toSimpleString(HornetQServerImpl.GENERIC_IGNORED_FILTER), true, false); } server.stop(); SequentialFileFactory messagesFF = new NIOSequentialFileFactory(getBindingsDir(), null); JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, 0, 0, messagesFF, "hornetq-bindings", "bindings", 1); messagesJournal.start(); LinkedList<RecordInfo> infos = new LinkedList<RecordInfo>(); messagesJournal.load(infos, null, null); int bindings = 0; for (RecordInfo info : infos) { if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) { bindings++; } } assertEquals(1, bindings); System.out.println("Bindings: " + bindings); messagesJournal.stop(); if (i < 4) server.start(); } }
/** * @param journalLocation * @return * @throws Exception */ protected static PageCursorsInfo loadCursorACKs(final String journalLocation) throws Exception { SequentialFileFactory messagesFF = new NIOSequentialFileFactory(journalLocation, null); // 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(), 0, 0, messagesFF, "hornetq-data", "hq", 1); messagesJournal.start(); ArrayList<RecordInfo> records = new ArrayList<RecordInfo>(); ArrayList<PreparedTransactionInfo> txs = new ArrayList<PreparedTransactionInfo>(); messagesJournal.load(records, txs, null, false); PageCursorsInfo cursorInfo = new PageCursorsInfo(); for (RecordInfo record : records) { byte[] data = record.data; HornetQBuffer buff = HornetQBuffers.wrappedBuffer(data); if (record.userRecordType == JournalRecordIds.ACKNOWLEDGE_CURSOR) { CursorAckRecordEncoding encoding = new CursorAckRecordEncoding(); encoding.decode(buff); Set<PagePosition> set = cursorInfo.getCursorRecords().get(encoding.queueID); if (set == null) { set = new HashSet<PagePosition>(); cursorInfo.getCursorRecords().put(encoding.queueID, set); } set.add(encoding.position); } else if (record.userRecordType == JournalRecordIds.PAGE_CURSOR_COMPLETE) { CursorAckRecordEncoding encoding = new CursorAckRecordEncoding(); encoding.decode(buff); Long queueID = Long.valueOf(encoding.queueID); Long pageNR = Long.valueOf(encoding.position.getPageNr()); if (!cursorInfo.getCompletePages(queueID).add(pageNR)) { System.err.println( "Page " + pageNR + " has been already set as complete on queue " + queueID); } } else if (record.userRecordType == JournalRecordIds.PAGE_TRANSACTION) { if (record.isUpdate) { PageUpdateTXEncoding pageUpdate = new PageUpdateTXEncoding(); pageUpdate.decode(buff); cursorInfo.getPgTXs().add(pageUpdate.pageTX); } else { PageTransactionInfoImpl pageTransactionInfo = new PageTransactionInfoImpl(); pageTransactionInfo.decode(buff); pageTransactionInfo.setRecordID(record.id); cursorInfo.getPgTXs().add(pageTransactionInfo.getTransactionID()); } } } return cursorInfo; }