use of org.apache.activemq.artemis.core.journal.EncodingSupport in project activemq-artemis by apache.
the class NIOSequentialFileFactoryTest method testInterrupts.
@Test
public void testInterrupts() throws Throwable {
final EncodingSupport fakeEncoding = new EncodingSupport() {
@Override
public int getEncodeSize() {
return 10;
}
@Override
public void encode(ActiveMQBuffer buffer) {
buffer.writeBytes(new byte[10]);
}
@Override
public void decode(ActiveMQBuffer buffer) {
}
};
final AtomicInteger calls = new AtomicInteger(0);
final NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getTestDir()), new IOCriticalErrorListener() {
@Override
public void onIOException(Throwable code, String message, SequentialFile file) {
new Exception("shutdown").printStackTrace();
calls.incrementAndGet();
}
}, 1);
Thread threadOpen = new Thread() {
@Override
public void run() {
try {
Thread.currentThread().interrupt();
SequentialFile file = factory.createSequentialFile("file.txt");
file.open();
} catch (Exception e) {
e.printStackTrace();
}
}
};
threadOpen.start();
threadOpen.join();
Thread threadClose = new Thread() {
@Override
public void run() {
try {
SequentialFile file = factory.createSequentialFile("file.txt");
file.open();
file.write(fakeEncoding, true);
Thread.currentThread().interrupt();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
threadClose.start();
threadClose.join();
Thread threadWrite = new Thread() {
@Override
public void run() {
try {
SequentialFile file = factory.createSequentialFile("file.txt");
file.open();
Thread.currentThread().interrupt();
file.write(fakeEncoding, true);
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
threadWrite.start();
threadWrite.join();
Thread threadFill = new Thread() {
@Override
public void run() {
try {
SequentialFile file = factory.createSequentialFile("file.txt");
file.open();
Thread.currentThread().interrupt();
file.fill(1024);
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
threadFill.start();
threadFill.join();
Thread threadWriteDirect = new Thread() {
@Override
public void run() {
try {
SequentialFile file = factory.createSequentialFile("file.txt");
file.open();
ByteBuffer buffer = ByteBuffer.allocate(10);
buffer.put(new byte[10]);
Thread.currentThread().interrupt();
file.writeDirect(buffer, true);
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
threadWriteDirect.start();
threadWriteDirect.join();
Thread threadRead = new Thread() {
@Override
public void run() {
try {
SequentialFile file = factory.createSequentialFile("file.txt");
file.open();
file.write(fakeEncoding, true);
file.position(0);
ByteBuffer readBytes = ByteBuffer.allocate(fakeEncoding.getEncodeSize());
Thread.currentThread().interrupt();
file.read(readBytes);
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
threadRead.start();
threadRead.join();
// An interrupt exception shouldn't issue a shutdown
Assert.assertEquals(0, calls.get());
}
use of org.apache.activemq.artemis.core.journal.EncodingSupport 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.core.journal.EncodingSupport 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.core.journal.EncodingSupport 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();
}
use of org.apache.activemq.artemis.core.journal.EncodingSupport in project activemq-artemis by apache.
the class JournalImplTestUnit method testXAMultiple.
@Test
public void testXAMultiple() throws Exception {
setup(10, 10 * 1024, true);
createJournal();
startJournal();
load();
add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
addTx(1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
addTx(2, 21, 22, 23, 24, 25, 26, 27);
updateTx(1, 1, 3, 6, 11, 14, 17);
addTx(3, 28, 29, 30, 31, 32, 33, 34, 35);
updateTx(3, 7, 8, 9, 10);
deleteTx(2, 4, 5, 6, 23, 25, 27);
EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
prepare(2, xid);
deleteTx(1, 1, 2, 11, 14, 15);
prepare(1, xid);
deleteTx(3, 28, 31, 32, 9);
prepare(3, xid);
commit(1);
rollback(2);
commit(3);
}
Aggregations