use of com.alipay.sofa.jraft.option.LogStorageOptions in project sofa-jraft by sofastack.
the class RocksDBSegmentLogStorageTest method testTruncateSuffixWithDifferentValueSize.
@Test
public void testTruncateSuffixWithDifferentValueSize() throws Exception {
// shutdown the old one
this.logStorage.shutdown();
// Set value threshold to be 32 bytes.
this.logStorage = new RocksDBSegmentLogStorage(this.path, new RaftOptions(), 32, 64);
final LogStorageOptions opts = newLogStorageOptions();
this.logStorage.init(opts);
int term = 1;
for (int i = 0; i < 10; i++) {
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(i, term, i)));
}
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(10, term, 64)));
for (int i = 11; i < 20; i++) {
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(i, term, i)));
}
for (int i = 0; i < 20; i++) {
assertNotNull(this.logStorage.getEntry(i));
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 179);
this.logStorage.truncateSuffix(15);
for (int i = 0; i < 20; i++) {
if (i <= 15) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 102);
this.logStorage.truncateSuffix(13);
for (int i = 0; i < 20; i++) {
if (i <= 13) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 102);
this.logStorage.truncateSuffix(5);
for (int i = 0; i < 20; i++) {
if (i <= 5) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertNull(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead());
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(20, term, 10)));
assertNotNull(this.logStorage.getEntry(20));
}
Aggregations