journal.appendCommitRecord(transactionId, true); transactionCounter = 0; transactionId = nextID.incrementAndGet(); journal.appendCommitRecord(transactionId, true);
AtomicInteger counter = getCounter(txID, txCounters); if (counter.get() == numberOfRecords) { journal.appendCommitRecord(txID, false); } else { System.err.println("Transaction " + txID +
AtomicInteger counter = getCounter(txID, txCounters); if (counter.get() == numberOfRecords) { journal.appendCommitRecord(txID, false); } else { System.err.println("Transaction " + txID +
@Override public void run() { try { latchReady.countDown(); ActiveMQTestBase.waitForLatch(latchStart); for (int i = 0; i < NUMBER_OF_ELEMENTS; i++) { Integer toDelete = queueDelete.poll(10, TimeUnit.SECONDS); if (toDelete == null) { break; } if (transactional) { journalImpl.appendDeleteRecordTransactional(toDelete, toDelete, new SimpleEncoding(50, (byte) 1)); journalImpl.appendCommitRecord(i, false); } else { journalImpl.appendDeleteRecord(toDelete, false); } } finishedOK.incrementAndGet(); } catch (Exception e) { e.printStackTrace(); } } };
@Override public void run() { try { latchReady.countDown(); ActiveMQTestBase.waitForLatch(latchStart); for (int i = 0; i < NUMBER_OF_ELEMENTS; i++) { if (transactional) { journalImpl.appendAddRecordTransactional(i, i, (byte) 1, new SimpleEncoding(50, (byte) 1)); journalImpl.appendCommitRecord(i, false); } else { journalImpl.appendAddRecord(i, (byte) 1, new SimpleEncoding(50, (byte) 1), false); } queueDelete.offer(i); } finishedOK.incrementAndGet(); } catch (Exception e) { e.printStackTrace(); } } };
@Test public void testTotalSize() throws Exception { final int JOURNAL_SIZE = 2000; setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(0, records.size()); Assert.assertEquals(0, transactions.size()); journalImpl.appendAddRecordTransactional(1L, 2L, (byte) 3, new SimpleEncoding(1900 - JournalImpl.SIZE_ADD_RECORD_TX - 1, (byte) 4)); journalImpl.appendCommitRecord(1L, false); journalImpl.debugWait(); setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(1, records.size()); }
@Test public void testDecreaseAlignment() throws Exception { final int JOURNAL_SIZE = 512 * 4; setupAndLoadJournal(JOURNAL_SIZE, 512); for (int i = 0; i < 10; i++) { journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 0)); } journalImpl.appendCommitRecord(1L, false); setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(10, records.size()); setupAndLoadJournal(JOURNAL_SIZE, 1); Assert.assertEquals(10, records.size()); }
@Test public void testIncreaseAlignment() throws Exception { final int JOURNAL_SIZE = 512 * 4; setupAndLoadJournal(JOURNAL_SIZE, 1); for (int i = 0; i < 10; i++) { journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 0)); } journalImpl.appendCommitRecord(1L, false); setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(10, records.size()); setupAndLoadJournal(JOURNAL_SIZE, 512); Assert.assertEquals(10, records.size()); }
@Test public void testCommitWithMultipleFiles() throws Exception { final int JOURNAL_SIZE = 20000; setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(0, records.size()); Assert.assertEquals(0, transactions.size()); for (int i = 0; i < 50; i++) { if (i == 10) { journalImpl.forceMoveNextFile(); } journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15)); } journalImpl.appendCommitRecord(1L, false); for (int i = 0; i < 10; i++) { if (i == 5) { journalImpl.forceMoveNextFile(); } journalImpl.appendDeleteRecordTransactional(2L, i); } journalImpl.appendCommitRecord(2L, false); journalImpl.forceMoveNextFile(); journalImpl.checkReclaimStatus(); setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(40, records.size()); }
@Test public void testReloadWithTransaction() throws Exception { final int JOURNAL_SIZE = 2000; setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(0, records.size()); Assert.assertEquals(0, transactions.size()); journalImpl.appendAddRecordTransactional(1, 1, (byte) 1, new SimpleEncoding(1, (byte) 1)); setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(0, records.size()); Assert.assertEquals(0, transactions.size()); try { journalImpl.appendCommitRecord(1L, true); // This was supposed to throw an exception, as the transaction was // forgotten (interrupted by a reload). Assert.fail("Supposed to throw exception"); } catch (Exception e) { UnitTestLogger.LOGGER.warn(e); } setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(0, records.size()); Assert.assertEquals(0, transactions.size()); }
journalImpl.appendCommitRecord(1L, false); journalImpl.appendCommitRecord(2L, false);
journalImpl.appendCommitRecord(1L, false);
@Test public void testPrepareAloneOnSeparatedFile() throws Exception { final int JOURNAL_SIZE = 20000; setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(0, records.size()); Assert.assertEquals(0, transactions.size()); for (int i = 0; i < 10; i++) { journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15)); } journalImpl.forceMoveNextFile(); SimpleEncoding xidEncoding = new SimpleEncoding(10, (byte) 'a'); journalImpl.appendPrepareRecord(1L, xidEncoding, false); journalImpl.appendCommitRecord(1L, false); for (int i = 0; i < 10; i++) { journalImpl.appendDeleteRecordTransactional(2L, i); } journalImpl.appendCommitRecord(2L, false); journalImpl.appendAddRecord(100L, (byte) 0, new SimpleEncoding(1, (byte) 10), false); // Add // anything // to // keep // holding // the // file journalImpl.forceMoveNextFile(); journalImpl.checkReclaimStatus(); setupAndLoadJournal(JOURNAL_SIZE, 100); Assert.assertEquals(1, records.size()); }
journalImpl.appendCommitRecord(1L, false);
journalImpl.appendCommitRecord(1L, false);
journalImpl.appendCommitRecord(77L, true);
journalImpl.appendCommitRecord(1L, false); journalImpl.appendCommitRecord(2L, false);
journalImpl.appendCommitRecord(1L, false); journalImpl.appendCommitRecord(2L, false);
@Test public void testEmptyPrepare() throws Exception { final int JOURNAL_SIZE = 512 * 4; setupAndLoadJournal(JOURNAL_SIZE, 1); journalImpl.appendPrepareRecord(2L, new SimpleEncoding(10, (byte) 'j'), false); journalImpl.forceMoveNextFile(); journalImpl.appendAddRecord(1L, (byte) 0, new SimpleEncoding(10, (byte) 'k'), false); setupAndLoadJournal(JOURNAL_SIZE, 1); Assert.assertEquals(1, journalImpl.getDataFilesCount()); Assert.assertEquals(1, transactions.size()); journalImpl.forceMoveNextFile(); setupAndLoadJournal(JOURNAL_SIZE, 1); Assert.assertEquals(1, journalImpl.getDataFilesCount()); Assert.assertEquals(1, transactions.size()); journalImpl.appendCommitRecord(2L, false); journalImpl.appendDeleteRecord(1L, false); journalImpl.forceMoveNextFile(); setupAndLoadJournal(JOURNAL_SIZE, 0); journalImpl.forceMoveNextFile(); journalImpl.debugWait(); journalImpl.checkReclaimStatus(); Assert.assertEquals(0, transactions.size()); Assert.assertEquals(0, journalImpl.getDataFilesCount()); }
@Test public void testPreviousError() throws Exception { final int JOURNAL_SIZE = 20000; setupJournal(JOURNAL_SIZE, 100, 5); factory.setHoldCallbacks(true, null); factory.setGenerateErrors(true); journalImpl.appendAddRecordTransactional(1L, 1, (byte) 1, new SimpleEncoding(1, (byte) 0)); journalImpl.debugWait(); factory.flushAllCallbacks(); factory.setGenerateErrors(false); factory.setHoldCallbacks(false, null); try { journalImpl.appendAddRecordTransactional(1L, 2, (byte) 1, new SimpleEncoding(1, (byte) 0)); journalImpl.appendCommitRecord(1L, true); Assert.fail("Exception expected"); // An exception already happened in one of the elements on this transaction. // We can't accept any more elements on the transaction } catch (Exception ignored) { } }