use of org.apache.activemq.artemis.core.persistence.impl.journal.BatchingIDGenerator 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();
}
use of org.apache.activemq.artemis.core.persistence.impl.journal.BatchingIDGenerator in project activemq-artemis by apache.
the class XmlImportExportTest method checkForLongs.
protected void checkForLongs() {
if (forceLongs) {
JournalStorageManager manager = (JournalStorageManager) server.getStorageManager();
BatchingIDGenerator idGenerator = (BatchingIDGenerator) manager.getIDGenerator();
idGenerator.forceNextID((Integer.MAX_VALUE) + 1L);
}
}
Aggregations