// Test the delta store strips partially written data.
public void testRecoverFromTruncatedDeltas() throws Exception {
// Create an entry with one record. Shrink the file byte by byte and ensure
// we can read it without crashing.
DeltaStore store = newDeltaStore();
WaveletDeltaRecord written = createRecord();
File deltaFile = FileDeltaCollection.deltasFile(path.getAbsolutePath(), WAVE1_WAVELET1);
long toRemove = 1;
while (true) {
// This generates the full file.
DeltasAccess wavelet = store.open(WAVE1_WAVELET1);
wavelet.append(ImmutableList.of(written));
wavelet.close();
RandomAccessFile file = new RandomAccessFile(deltaFile, "rw");
if (toRemove > file.length()) {
file.close();
break;
}
// eat the planned number of bytes
LOG.info("trying to remove " + toRemove + " bytes");
file.setLength(file.length() - toRemove);
file.close();
wavelet = store.open(WAVE1_WAVELET1);
WaveletDeltaRecord read = wavelet.getDelta(0);
assertNull("got an unexpected record " + read, read);
wavelet.close();
toRemove++;
}
}