use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class AlignedJournalImplTest method testReloadInvalidCheckSizeOnTransaction.
@Test
public void testReloadInvalidCheckSizeOnTransaction() throws Exception {
final int JOURNAL_SIZE = 2000;
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(2, factory.listFiles("tt").size());
Assert.assertEquals(0, records.size());
Assert.assertEquals(0, transactions.size());
for (int i = 0; i < 2; i++) {
journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
}
journalImpl.appendCommitRecord(1L, false);
journalImpl.debugWait();
System.out.println("Files = " + factory.listFiles("tt"));
SequentialFile file = factory.createSequentialFile("tt-1.tt");
file.open();
ByteBuffer buffer = ByteBuffer.allocate(100);
// Messing up with the first record (removing the position)
file.position(100);
file.read(buffer);
// jumping RecordType, FileId, TransactionID, RecordID, VariableSize,
// RecordType, RecordBody (that we know it is 1 )
buffer.position(1 + 4 + 8 + 8 + 4 + 1 + 1 + 1);
int posCheckSize = buffer.position();
Assert.assertEquals(JournalImpl.SIZE_ADD_RECORD_TX + 2, buffer.getInt());
buffer.position(posCheckSize);
buffer.putInt(-1);
buffer.rewind();
// Changing the check bufferSize, so reload will ignore this record
file.position(100);
file.writeDirect(buffer, true);
file.close();
setupAndLoadJournal(JOURNAL_SIZE, 100);
Assert.assertEquals(0, records.size());
journalImpl.checkReclaimStatus();
Assert.assertEquals(0, journalImpl.getDataFilesCount());
Assert.assertEquals(2, factory.listFiles("tt").size());
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalAsyncTest method doAsynchronousTest.
public void doAsynchronousTest(final boolean isCommit) throws Exception {
final int JOURNAL_SIZE = 20000;
setupJournal(JOURNAL_SIZE, 100, 5);
factory.setHoldCallbacks(true, null);
final CountDownLatch latch = new CountDownLatch(1);
class LocalThread extends Thread {
Exception e;
@Override
public void run() {
try {
for (int i = 0; i < 10; i++) {
journalImpl.appendAddRecordTransactional(1L, i, (byte) 1, new SimpleEncoding(1, (byte) 0));
}
journalImpl.debugWait();
latch.countDown();
factory.setHoldCallbacks(false, null);
if (isCommit) {
journalImpl.appendCommitRecord(1L, true);
} else {
journalImpl.appendRollbackRecord(1L, true);
}
} catch (Exception e) {
e.printStackTrace();
this.e = e;
}
}
}
LocalThread t = new LocalThread();
t.start();
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Thread.yield();
Thread.sleep(100);
Assert.assertTrue(t.isAlive());
factory.flushAllCallbacks();
t.join();
if (t.e != null) {
throw t.e;
}
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalImplTestUnit method testXASimpleCommit.
@Test
public void testXASimpleCommit() throws Exception {
setup(10, 10 * 1024, true);
createJournal();
startJournal();
load();
addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
updateTx(1, 1, 2, 3, 4, 7, 8);
deleteTx(1, 1, 2, 3, 4, 5);
EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
prepare(1, xid);
commit(1);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalImplTestUnit method testSimpleAddTXXAReload.
@Test
public void testSimpleAddTXXAReload() throws Exception {
setup(2, 10 * 1024, true);
createJournal();
startJournal();
load();
addTx(1, 1);
EncodingSupport xid = new SimpleEncoding(10, (byte) 'p');
prepare(1, xid);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding in project activemq-artemis by apache.
the class JournalImplTestUnit method testXASimpleRollback.
@Test
public void testXASimpleRollback() throws Exception {
setup(10, 10 * 1024, true);
createJournal();
startJournal();
load();
addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
updateTx(1, 1, 2, 3, 4, 7, 8);
deleteTx(1, 1, 2, 3, 4, 5);
EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
prepare(1, xid);
rollback(1);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
}
Aggregations