public void testInsertUpdateAndLoad() throws Exception
{
SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDir());
JournalImpl impl = new JournalImpl(10 * 1024 * 1024,
AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL,
0,
0,
factory,
"hq",
"hq",
1000);
impl.start();
impl.load(AddAndRemoveStressTest.dummyLoader);
for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++)
{
if (i % 10000 == 0)
{
System.out.println("Append " + i);
}
impl.appendAddRecord(i, (byte)21, new SimpleEncoding(40, (byte)'f'), false);
impl.appendUpdateRecord(i, (byte)22, new SimpleEncoding(40, (byte)'g'), false);
}
impl.stop();
factory = new AIOSequentialFileFactory(getTestDir());
impl = new JournalImpl(10 * 1024 * 1024, 10, 0, 0, factory, "hq", "hq", 1000);
impl.start();
impl.load(AddAndRemoveStressTest.dummyLoader);
for (long i = 1; i <= AddAndRemoveStressTest.NUMBER_OF_MESSAGES; i++)
{
if (i % 10000 == 0)
{
System.out.println("Delete " + i);
}
impl.appendDeleteRecord(i, false);
}
impl.stop();
factory = new AIOSequentialFileFactory(getTestDir());
impl = new JournalImpl(10 * 1024 * 1024,
AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL,
0,
0,
factory,
"hq",
"hq",
1000);
impl.start();
ArrayList<RecordInfo> info = new ArrayList<RecordInfo>();
ArrayList<PreparedTransactionInfo> trans = new ArrayList<PreparedTransactionInfo>();
impl.load(info, trans, null);
if (info.size() > 0)
{
System.out.println("Info ID: " + info.get(0).id);
}
impl.forceMoveNextFile();
impl.checkReclaimStatus();
impl.stop();
Assert.assertEquals(0, info.size());
Assert.assertEquals(0, trans.size());
Assert.assertEquals(0, impl.getDataFilesCount());
System.out.println("Size = " + impl.getDataFilesCount());
}