org.apache.activemq.artemis.core.journal.EncodingSupport

Here are the examples of the java api class org.apache.activemq.artemis.core.journal.EncodingSupport taken from open source projects.

1. JournalImplTestUnit#testXAChangesisibleCommit()

Project: activemq-artemis
File: JournalImplTestUnit.java
@Test
public void testXAChangesisibleCommit() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    add(1, 2, 3, 4, 5, 6);
    addTx(1, 7, 8, 9, 10);
    updateTx(1, 1, 2, 3, 7, 8, 9);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    commit(1);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}

2. JournalImplTestUnit#testXAChangesNotVisibleRollback()

Project: activemq-artemis
File: JournalImplTestUnit.java
@Test
public void testXAChangesNotVisibleRollback() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    add(1, 2, 3, 4, 5, 6);
    addTx(1, 7, 8, 9, 10);
    updateTx(1, 1, 2, 3, 7, 8, 9);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    rollback(1);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}

3. JournalImplTestUnit#testXAChangesNotVisiblePrepared()

Project: activemq-artemis
File: JournalImplTestUnit.java
@Test
public void testXAChangesNotVisiblePrepared() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    add(1, 2, 3, 4, 5, 6);
    addTx(1, 7, 8, 9, 10);
    updateTx(1, 1, 2, 3, 7, 8, 9);
    deleteTx(1, 1, 2, 3, 4, 5);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}

4. JournalImplTestUnit#testXASimpleRollback()

Project: activemq-artemis
File: JournalImplTestUnit.java
@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();
}

5. JournalImplTestUnit#testXASimpleCommit()

Project: activemq-artemis
File: JournalImplTestUnit.java
@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();
}

6. JournalImplTestUnit#testXASimplePrepared()

Project: activemq-artemis
File: JournalImplTestUnit.java
@Test
public void testXASimplePrepared() 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);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}

7. JournalImplTestUnit#testSimpleAddTXXAReload()

Project: activemq-artemis
File: JournalImplTestUnit.java
@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();
}

8. JournalImplTestUnit#testXAMultiple()

Project: activemq-artemis
File: JournalImplTestUnit.java
@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);
}

9. JournalImplTestUnit#testPrepareNoReclaim()

Project: activemq-artemis
File: JournalImplTestUnit.java
@Test
public void testPrepareNoReclaim() throws Exception {
    setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
    createJournal();
    startJournal();
    load();
    List<String> files1 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(2, files1.size());
    Assert.assertEquals(0, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getIDMapSize());
    // in file 0
    addTx(1, 1);
    // Make sure we move on to the next file
    // in file 1
    addWithSize(1024 - JournalImpl.SIZE_ADD_RECORD, 2);
    List<String> files2 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(3, files2.size());
    Assert.assertEquals(calculateNumberOfFiles(fileSize, journal.getAlignment(), 2, recordLength), journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    // in file 1
    prepare(1, xid);
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    // in file 1
    delete(2);
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(0, journal.getIDMapSize());
    // Move on to another file
    // in file 2
    addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD - 1, 3);
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    checkAndReclaimFiles();
    List<String> files6 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(4, files6.size());
    Assert.assertEquals(2, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(1, journal.getIDMapSize());
    // in file 3
    addWithSize(recordLength - JournalImpl.SIZE_ADD_RECORD - 1, 4);
    List<String> files7 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(5, files7.size());
    Assert.assertEquals(3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(2, journal.getIDMapSize());
    // in file 4
    commit(1);
    List<String> files8 = fileFactory.listFiles(fileExtension);
    Assert.assertEquals(5, files8.size());
    Assert.assertEquals(3, journal.getDataFilesCount());
    Assert.assertEquals(0, journal.getFreeFilesCount());
    Assert.assertEquals(1, journal.getOpenedFilesCount());
    Assert.assertEquals(3, journal.getIDMapSize());
    // Restart
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}

10. JournalImplTestUnit#testEmptyPrepare()

Project: activemq-artemis
File: JournalImplTestUnit.java
@Test
public void testEmptyPrepare() throws Exception {
    setup(2, calculateRecordSize(JournalImpl.SIZE_HEADER, getAlignment()) + calculateRecordSize(recordLength, getAlignment()) + 512, true);
    createJournal();
    startJournal();
    load();
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(1, xid);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    commit(1);
    xid = new SimpleEncoding(10, (byte) 1);
    prepare(2, xid);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    rollback(2);
    stopJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}

11. NIOSequentialFileFactoryTest#testInterrupts()

Project: activemq-artemis
File: NIOSequentialFileFactoryTest.java
@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());
}

12. NIOImportExportTest#testExportImport3()

Project: activemq-artemis
File: NIOImportExportTest.java
@Test
public void testExportImport3() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    add(1, 2);
    journal.forceMoveNextFile();
    delete(1, 2);
    add(3, 4);
    journal.forceMoveNextFile();
    addTx(5, 6, 7, 8);
    journal.forceMoveNextFile();
    addTx(5, 9);
    commit(5);
    journal.forceMoveNextFile();
    deleteTx(10, 6, 7, 8, 9);
    commit(10);
    addTx(11, 12, 13);
    EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
    prepare(11, xid);
    stopJournal();
    exportImportJournal();
    createJournal();
    startJournal();
    loadAndCheck();
    commit(11);
    stopJournal();
    exportImportJournal();
    createJournal();
    startJournal();
    loadAndCheck();
}