public void testRecordFreeing2() throws HeapException {
createHeap(true);
/*
* create record #0
*/
DataRecordIdentifier identifier = heapDataManager
.getNewDataRecordIdentifier();
byte[] data = new byte[100];
heapDataManager.writeDataRecord(identifier, data);
final DataRecordIdentifier expectedIdentifier = new DataRecordIdentifier(
0);
assertEquals("must create record #0", expectedIdentifier, identifier);
/*
* create record #1
*/
identifier = heapDataManager.getNewDataRecordIdentifier();
data = new byte[100];
heapDataManager.writeDataRecord(identifier, data);
final DataRecordIdentifier expectedIdentifier1 = new DataRecordIdentifier(
1);
assertEquals("must create record #1", expectedIdentifier1, identifier);
heapDataManager.flush();
final long record1PositionInFile = heapDataManager
.getRecordPositionInfile(expectedIdentifier1);
/*
* create record #2
*/
identifier = heapDataManager.getNewDataRecordIdentifier();
data = new byte[100];
heapDataManager.writeDataRecord(identifier, data);
final DataRecordIdentifier expectedIdentifier2 = new DataRecordIdentifier(
2);
assertEquals("must create record #2", expectedIdentifier2, identifier);
heapDataManager.flush();
final long record2PositionInFile = heapDataManager
.getRecordPositionInfile(expectedIdentifier2);
/*
* delete #2
*/
identifier = new DataRecordIdentifier(2);
assertTrue("must delete #2",
heapDataManager.deleteDataRecord(identifier));
heapDataManager.flush();
if (manageRecordPositionInFile()) {
final long lastRecordPositionInFile = heapDataManager
.getLastRecordPositionInFile();
assertEquals(LAST_RECORD_MISMATCH, record2PositionInFile,
lastRecordPositionInFile);
}
/*
* delete #1
*/
identifier = new DataRecordIdentifier(1);
assertTrue(MUST_DELETE_1, heapDataManager.deleteDataRecord(identifier));
heapDataManager.flush();
if (manageFreeRecord()) {
final long lastRecordPositionInFile = heapDataManager
.getLastRecordPositionInFile();