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