Set<Integer> deletedPositions = new HashSet<Integer>();
int lastPosition;
byte counter = 0;
int freeSpace = localPage.getFreeSpace();
ORecordVersion recordVersion = OVersionFactory.instance().createVersion();
recordVersion.increment();
do {
lastPosition = localPage.appendRecord(recordVersion, new byte[] { counter, counter, counter }, false);
if (lastPosition >= 0) {
Assert.assertEquals(lastPosition, positionCounter.size());
positionCounter.put(lastPosition, counter);
counter++;
Assert.assertEquals(localPage.getFreeSpace(), freeSpace - (19 + OVersionFactory.instance().getVersionSize()));
freeSpace = localPage.getFreeSpace();
}
} while (lastPosition >= 0);
int filledRecordsCount = positionCounter.size();
Assert.assertEquals(localPage.getRecordsCount(), filledRecordsCount);
for (int i = 0; i < filledRecordsCount; i += 2) {
localPage.deleteRecord(i);
deletedPositions.add(i);
positionCounter.remove(i);
}
freeSpace = localPage.getFreeSpace();
do {
lastPosition = localPage.appendRecord(recordVersion, new byte[] { counter, counter, counter }, false);
if (lastPosition >= 0) {
positionCounter.put(lastPosition, counter);
counter++;
Assert.assertEquals(localPage.getFreeSpace(), freeSpace - 15);
freeSpace = localPage.getFreeSpace();
}
} while (lastPosition >= 0);
ORecordVersion deletedVersion = OVersionFactory.instance().createVersion();
deletedVersion.copyFrom(recordVersion);
deletedVersion.increment();
Assert.assertEquals(localPage.getRecordsCount(), filledRecordsCount);
for (Map.Entry<Integer, Byte> entry : positionCounter.entrySet()) {
Assert.assertEquals(localPage.getRecordBinaryValue(entry.getKey(), 0, 3), new byte[] { entry.getValue(), entry.getValue(),
entry.getValue() });