Search in sources :

Example 31 with SequentialFile

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

the class AlignedJournalImplTest method testReloadInvalidCheckSizeOnTransaction.

@Test
public void testReloadInvalidCheckSizeOnTransaction() throws Exception {
    final int JOURNAL_SIZE = 2000;
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(2, factory.listFiles("tt").size());
    Assert.assertEquals(0, records.size());
    Assert.assertEquals(0, transactions.size());
    for (int i = 0; i < 2; i++) {
        journalImpl.appendAddRecordTransactional(1L, i, (byte) 0, new SimpleEncoding(1, (byte) 15));
    }
    journalImpl.appendCommitRecord(1L, false);
    journalImpl.debugWait();
    System.out.println("Files = " + factory.listFiles("tt"));
    SequentialFile file = factory.createSequentialFile("tt-1.tt");
    file.open();
    ByteBuffer buffer = ByteBuffer.allocate(100);
    // Messing up with the first record (removing the position)
    file.position(100);
    file.read(buffer);
    // jumping RecordType, FileId, TransactionID, RecordID, VariableSize,
    // RecordType, RecordBody (that we know it is 1 )
    buffer.position(1 + 4 + 8 + 8 + 4 + 1 + 1 + 1);
    int posCheckSize = buffer.position();
    Assert.assertEquals(JournalImpl.SIZE_ADD_RECORD_TX + 2, buffer.getInt());
    buffer.position(posCheckSize);
    buffer.putInt(-1);
    buffer.rewind();
    // Changing the check bufferSize, so reload will ignore this record
    file.position(100);
    file.writeDirect(buffer, true);
    file.close();
    setupAndLoadJournal(JOURNAL_SIZE, 100);
    Assert.assertEquals(0, records.size());
    journalImpl.checkReclaimStatus();
    Assert.assertEquals(0, journalImpl.getDataFilesCount());
    Assert.assertEquals(2, factory.listFiles("tt").size());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 32 with SequentialFile

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

the class JournalImplTestUnit method testMaxInt.

// Validates the if the journal will work when the IDs are over MaxInt
@Test
public void testMaxInt() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    stopJournal();
    fileFactory.start();
    List<String> files = fileFactory.listFiles(fileExtension);
    long fileID = Integer.MAX_VALUE;
    for (String fileStr : files) {
        SequentialFile file = fileFactory.createSequentialFile(fileStr);
        file.open();
        JournalImpl.initFileHeader(fileFactory, file, journal.getUserVersion(), fileID++);
        file.close();
    }
    fileFactory.stop();
    startJournal();
    load();
    for (long i = 0; i < 100; i++) {
        add(i);
        stopJournal();
        startJournal();
        loadAndCheck();
    }
    stopJournal();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) Test(org.junit.Test)

Example 33 with SequentialFile

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

the class JournalImplTestUnit method testVersionCheck.

@Test
public void testVersionCheck() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    stopJournal();
    fileFactory.start();
    List<String> files = fileFactory.listFiles(fileExtension);
    for (String fileStr : files) {
        SequentialFile file = fileFactory.createSequentialFile(fileStr);
        ByteBuffer buffer = fileFactory.newBuffer(JournalImpl.SIZE_HEADER);
        for (int i = 0; i < JournalImpl.SIZE_HEADER; i++) {
            buffer.put(Byte.MAX_VALUE);
        }
        buffer.rewind();
        file.open();
        file.position(0);
        file.writeDirect(buffer, sync);
        file.close();
    }
    fileFactory.stop();
    startJournal();
    boolean exceptionHappened = false;
    try {
        load();
    } catch (ActiveMQIOErrorException ioe) {
        exceptionHappened = true;
    } catch (ActiveMQException e) {
        Assert.fail("invalid exception type:" + e.getType());
    }
    Assert.assertTrue("Exception was expected", exceptionHappened);
    stopJournal();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 34 with SequentialFile

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

the class JournalImplTestUnit method tearDown.

@Override
@After
public void tearDown() throws Exception {
    // stop journal first to let it manage its files
    stopComponent(journal);
    List<String> files = fileFactory.listFiles(fileExtension);
    for (String file : files) {
        SequentialFile seqFile = fileFactory.createSequentialFile(file);
        Assert.assertEquals(fileSize, seqFile.size());
    }
    super.tearDown();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) After(org.junit.After)

Example 35 with SequentialFile

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

the class SequentialFileFactoryTestBase method testCreateAndListFiles.

@Test
public void testCreateAndListFiles() throws Exception {
    List<String> expectedFiles = new ArrayList<>();
    final int numFiles = 10;
    for (int i = 0; i < numFiles; i++) {
        String fileName = UUID.randomUUID().toString() + ".amq";
        expectedFiles.add(fileName);
        SequentialFile sf = factory.createSequentialFile(fileName);
        sf.open();
        Assert.assertEquals(fileName, sf.getFileName());
        sf.close();
    }
    // Create a couple with a different extension - they shouldn't be picked
    // up
    SequentialFile sf1 = factory.createSequentialFile("different.file");
    sf1.open();
    SequentialFile sf2 = factory.createSequentialFile("different.cheese");
    sf2.open();
    List<String> fileNames = factory.listFiles("amq");
    Assert.assertEquals(expectedFiles.size(), fileNames.size());
    for (String fileName : expectedFiles) {
        Assert.assertTrue(fileNames.contains(fileName));
    }
    fileNames = factory.listFiles("file");
    Assert.assertEquals(1, fileNames.size());
    Assert.assertTrue(fileNames.contains("different.file"));
    fileNames = factory.listFiles("cheese");
    Assert.assertEquals(1, fileNames.size());
    Assert.assertTrue(fileNames.contains("different.cheese"));
    sf1.close();
    sf2.close();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)53 Test (org.junit.Test)21 ByteBuffer (java.nio.ByteBuffer)15 ArrayList (java.util.ArrayList)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)7 Pair (org.apache.activemq.artemis.api.core.Pair)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)4 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)4 Page (org.apache.activemq.artemis.core.paging.impl.Page)4 JDBCSequentialFile (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile)4 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)3 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)3 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2