// Public --------------------------------------------------------
public void testSequence() throws Exception
{
NIOSequentialFileFactory factory = new NIOSequentialFileFactory(getTestDir());
Journal journal = new JournalImpl(10 * 1024, 2, 0, 0, factory, "test-data", "tst", 1);
journal.start();
journal.load(new ArrayList<RecordInfo>(), new ArrayList<PreparedTransactionInfo>(), null);
BatchingIDGenerator batch = new BatchingIDGenerator(0, 1000, journal);
long id1 = batch.generateID();
long id2 = batch.generateID();
Assert.assertTrue(id2 > id1);
journal.stop();
batch = new BatchingIDGenerator(0, 1000, journal);
loadIDs(journal, batch);
long id3 = batch.generateID();
Assert.assertEquals(1000, id3);
long id4 = batch.generateID();
Assert.assertTrue(id4 > id3 && id4 < 2000);
batch.close();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, journal);
loadIDs(journal, batch);
long id5 = batch.generateID();
Assert.assertTrue(id5 > id4 && id5 < 2000);
long lastId = id5;
boolean close = true;
for (int i = 0; i < 100000; i++)
{
if (i % 1000 == 0)
{
System.out.println("lastId = " + lastId);
// interchanging closes and simulated crashes
if (close)
{
batch.close();
}
close = !close;
journal.stop();
batch = new BatchingIDGenerator(0, 1000, journal);
loadIDs(journal, batch);
}
long id = batch.generateID();
Assert.assertTrue(id > lastId);
lastId = id;
}
batch.close();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, journal);
loadIDs(journal, batch);
lastId = batch.getCurrentID();
journal.stop();
batch = new BatchingIDGenerator(0, 1000, journal);
loadIDs(journal, batch);
Assert.assertEquals("No Ids were generated, so the currentID was supposed to stay the same",
lastId,