use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class JournalCleanupCompactStressTest method setUp.
@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();
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class NIOMultiThreadCompactorStressTest method testMultiThreadCompact.
@Test
public void testMultiThreadCompact() throws Throwable {
setupServer(getJournalType());
for (int i = 0; i < getNumberOfIterations(); i++) {
System.out.println("######################################");
System.out.println("test # " + i);
internalTestProduceAndConsume();
stopServer();
NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir()), 1);
JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 2, 0, 0, factory, "activemq-data", "amq", 100);
List<RecordInfo> committedRecords = new ArrayList<>();
List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
journal.start();
journal.load(committedRecords, preparedTransactions, null);
Assert.assertEquals(0, committedRecords.size());
Assert.assertEquals(0, preparedTransactions.size());
System.out.println("DataFiles = " + journal.getDataFilesCount());
if (i % 2 == 0 && i > 0) {
System.out.println("DataFiles = " + journal.getDataFilesCount());
journal.forceMoveNextFile();
journal.debugWait();
journal.checkReclaimStatus();
if (journal.getDataFilesCount() != 0) {
System.out.println("DebugJournal:" + journal.debug());
}
Assert.assertEquals(0, journal.getDataFilesCount());
}
journal.stop();
journal = null;
setupServer(getJournalType());
}
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class JournalAsyncTest method setupJournal.
// 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);
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class AlignedJournalImplTest method testAlignmentOverReload.
@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());
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class BatchIDGeneratorUnitTest method testSequence.
@Test
public void testSequence() throws Exception {
NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getTestDir()), 1);
Journal journal = new JournalImpl(10 * 1024, 2, 2, 0, 0, factory, "activemq-bindings", "bindings", 1);
journal.start();
journal.load(new ArrayList<RecordInfo>(), new ArrayList<PreparedTransactionInfo>(), null);
BatchingIDGenerator batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
long id1 = batch.generateID();
long id2 = batch.generateID();
Assert.assertTrue(id2 > id1);
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
long id3 = batch.generateID();
Assert.assertEquals(1001, id3);
long id4 = batch.generateID();
Assert.assertTrue(id4 > id3 && id4 < 2000);
batch.persistCurrentID();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
long id5 = batch.generateID();
Assert.assertTrue(id5 > id4 && id5 < 2000);
long lastId = id5;
boolean close = true;
for (int i = 0; i < 100000; i++) {
if (i % 1000 == 0) {
// interchanging closes and simulated crashes
if (close) {
batch.persistCurrentID();
}
close = !close;
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
}
long id = batch.generateID();
Assert.assertTrue(id > lastId);
lastId = id;
}
batch.persistCurrentID();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
lastId = batch.getCurrentID();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, getJournalStorageManager(journal));
loadIDs(journal, batch);
Assert.assertEquals("No Ids were generated, so the currentID was supposed to stay the same", lastId, batch.getCurrentID());
journal.stop();
}
Aggregations