+ randomFileAccess.getPageSet().toString());
}
// check page 0 wrote
assertEquals(BAD_READ_ACCESS, 0, probe.readLogSize());
assertEquals(BAD_WRITE_ACCESS, 1, probe.writeLogSize());
FileAccessRecordForTests record = probe.pollFirstWrote();
assertNotNull("must write at 3*PAGE_SIZE", record);
assertEquals(BAD_POSITION_IN_FILE, 3 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('3'), record.getStrData());
if (flushMode) {
randomFileAccess.flush();
} else {
randomFileAccess.close();
}
// check wrote at close or flush
assertEquals(BAD_READ_ACCESS, 0, probe.readLogSize());
assertEquals(BAD_WRITE_ACCESS, 4, probe.writeLogSize());
record = probe.pollFirstWrote();
assertEquals(BAD_POSITION_IN_FILE, 0 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('0'), record.getStrData());
record = probe.pollFirstWrote();
assertEquals(BAD_POSITION_IN_FILE, 1 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('1'), record.getStrData());
record = probe.pollFirstWrote();
assertEquals(BAD_POSITION_IN_FILE, 2 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('2'), record.getStrData());
record = probe.pollFirstWrote();
assertEquals(BAD_POSITION_IN_FILE, 4 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('4'), record.getStrData());
// check in read cache
if (flushMode) {
randomFileAccess.seek(0);
} else {
randomFileAccess.open();
}
int read = randomFileAccess.read(buffer);
assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
assertEquals(BAD_DATA, createStrPageData('0'), new String(buffer));
read = randomFileAccess.read(buffer);
assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
assertEquals(BAD_DATA, createStrPageData('1'), new String(buffer));
read = randomFileAccess.read(buffer);
assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
assertEquals(BAD_DATA, createStrPageData('2'), new String(buffer));
read = randomFileAccess.read(buffer);
assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
assertEquals(BAD_DATA, createStrPageData('3'), new String(buffer));
read = randomFileAccess.read(buffer);
assertEquals(BAD_NUMBER_OF_READ, PAGE_SIZE, read);
assertEquals(BAD_DATA, createStrPageData('4'), new String(buffer));
read = randomFileAccess.read(buffer);
assertEquals(BAD_NUMBER_OF_READ, -1, read);
if (LOGGER.debugEnabled) {
LOGGER.debug("after read 0,1,2,3,4 : "
+ randomFileAccess.getPageSet().toString());
}
if (flushMode) {
// data kept in cache
assertEquals(BAD_READ_ACCESS + '\n' + probe.readLogToString(), 2,
probe.readLogSize());
assertEquals(BAD_WRITE_ACCESS, 0, probe.writeLogSize());
record = probe.pollFirstRead();
assertEquals(BAD_POSITION_IN_FILE, 3 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('3'), record.getStrData());
record = probe.pollFirstRead();
assertEquals(BAD_POSITION_IN_FILE, 4 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('4'), record.getStrData());
} else {
// cache was cleared, so check read 5 records
assertEquals(BAD_READ_ACCESS + '\n' + probe.readLogToString(), 5,
probe.readLogSize());
assertEquals(BAD_WRITE_ACCESS, 0, probe.writeLogSize());
record = probe.pollFirstRead();
assertEquals(BAD_POSITION_IN_FILE, 0 * PAGE_SIZE,
record.getPositionInFile());
record = probe.pollFirstRead();
assertEquals(BAD_POSITION_IN_FILE, 1 * PAGE_SIZE,
record.getPositionInFile());
record = probe.pollFirstRead();
assertEquals(BAD_POSITION_IN_FILE, 2 * PAGE_SIZE,
record.getPositionInFile());
record = probe.pollFirstRead();
assertEquals(BAD_POSITION_IN_FILE, 3 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('3'), record.getStrData());
record = probe.pollFirstRead();
assertEquals(BAD_POSITION_IN_FILE, 4 * PAGE_SIZE,
record.getPositionInFile());
assertEquals(BAD_DATA, createStrPageData('4'), record.getStrData());
}
randomFileAccess.close();
}