Search in sources :

Example 1 with BatchingIDGenerator

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();
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) Journal(org.apache.activemq.artemis.core.journal.Journal) BatchingIDGenerator(org.apache.activemq.artemis.core.persistence.impl.journal.BatchingIDGenerator) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 2 with BatchingIDGenerator

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);
    }
}
Also used : BatchingIDGenerator(org.apache.activemq.artemis.core.persistence.impl.journal.BatchingIDGenerator) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)

Aggregations

BatchingIDGenerator (org.apache.activemq.artemis.core.persistence.impl.journal.BatchingIDGenerator)2 File (java.io.File)1 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)1 Journal (org.apache.activemq.artemis.core.journal.Journal)1 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)1 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)1 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)1 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)1 Test (org.junit.Test)1