Search in sources :

Example 11 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory 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());
    }
}
Also used : PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) ArrayList(java.util.ArrayList) 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 12 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class CleanBufferTest method testCleanOnNIO.

// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testCleanOnNIO() {
    SequentialFileFactory factory = new NIOSequentialFileFactory(new File("Whatever"), 1);
    testBuffer(factory);
}
Also used : File(java.io.File) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 13 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory 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 14 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory 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());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) ByteBuffer(java.nio.ByteBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) File(java.io.File) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 15 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class NIONoBufferJournalImplTest method getFileFactory.

@Override
protected SequentialFileFactory getFileFactory() throws Exception {
    File file = new File(getTestDir());
    NIONoBufferJournalImplTest.log.debug("deleting directory " + getTestDir());
    deleteDirectory(file);
    file.mkdir();
    return new NIOSequentialFileFactory(new File(getTestDir()), false, 1);
}
Also used : File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)

Aggregations

NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)33 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)19 File (java.io.File)18 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)15 Test (org.junit.Test)11 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)7 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)6 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)4 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)3 Journal (org.apache.activemq.artemis.core.journal.Journal)3 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)3 ByteBuffer (java.nio.ByteBuffer)2