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());
}
Aggregations