Search in sources :

Example 1 with JournalFileImpl

use of org.apache.activemq.artemis.core.journal.impl.JournalFileImpl in project activemq-artemis by apache.

the class NIOJournalCompactTest method testControlFile.

// General tests
// =============
@Test
public void testControlFile() throws Exception {
    ArrayList<JournalFile> dataFiles = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        SequentialFile file = fileFactory.createSequentialFile("file-" + i + ".tst");
        dataFiles.add(new JournalFileImpl(file, 0, JournalImpl.FORMAT_VERSION));
    }
    ArrayList<JournalFile> newFiles = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        SequentialFile file = fileFactory.createSequentialFile("file-" + i + ".tst.new");
        newFiles.add(new JournalFileImpl(file, 0, JournalImpl.FORMAT_VERSION));
    }
    ArrayList<Pair<String, String>> renames = new ArrayList<>();
    renames.add(new Pair<>("a", "b"));
    renames.add(new Pair<>("c", "d"));
    AbstractJournalUpdateTask.writeControlFile(fileFactory, dataFiles, newFiles, renames);
    ArrayList<String> strDataFiles = new ArrayList<>();
    ArrayList<String> strNewFiles = new ArrayList<>();
    ArrayList<Pair<String, String>> renamesRead = new ArrayList<>();
    Assert.assertNotNull(JournalCompactor.readControlFile(fileFactory, strDataFiles, strNewFiles, renamesRead));
    Assert.assertEquals(dataFiles.size(), strDataFiles.size());
    Assert.assertEquals(newFiles.size(), strNewFiles.size());
    Assert.assertEquals(renames.size(), renamesRead.size());
    Iterator<String> iterDataFiles = strDataFiles.iterator();
    for (JournalFile file : dataFiles) {
        Assert.assertEquals(file.getFile().getFileName(), iterDataFiles.next());
    }
    Assert.assertFalse(iterDataFiles.hasNext());
    Iterator<String> iterNewFiles = strNewFiles.iterator();
    for (JournalFile file : newFiles) {
        Assert.assertEquals(file.getFile().getFileName(), iterNewFiles.next());
    }
    Assert.assertFalse(iterNewFiles.hasNext());
    Iterator<Pair<String, String>> iterRename = renames.iterator();
    for (Pair<String, String> rename : renamesRead) {
        Pair<String, String> original = iterRename.next();
        Assert.assertEquals(original.getA(), rename.getA());
        Assert.assertEquals(original.getB(), rename.getB());
    }
    Assert.assertFalse(iterNewFiles.hasNext());
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ArrayList(java.util.ArrayList) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) JournalFileImpl(org.apache.activemq.artemis.core.journal.impl.JournalFileImpl) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Pair (org.apache.activemq.artemis.api.core.Pair)1 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)1 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)1 JournalFileImpl (org.apache.activemq.artemis.core.journal.impl.JournalFileImpl)1 Test (org.junit.Test)1