use of com.alipay.sofa.jraft.rhea.storage.SstColumnFamily in project sofa-jraft by sofastack.
the class RocksKVStoreTest method sstFilesTest.
@Test
public void sstFilesTest() throws IOException {
for (int i = 0; i < 10000; i++) {
byte[] bytes = BytesUtil.writeUtf8(String.valueOf(i));
this.kvStore.put(bytes, bytes, null);
}
this.kvStore.getSequence(BytesUtil.writeUtf8("seq"), 100, null);
final File defaultSstFile = new File("default.sst");
final File seqSstFile = new File("seq.sst");
final File lockingFile = new File("locking.sst");
final File fencingFile = new File("fencing.sst");
if (defaultSstFile.exists()) {
FileUtils.forceDelete(defaultSstFile);
}
if (seqSstFile.exists()) {
FileUtils.forceDelete(seqSstFile);
}
if (lockingFile.exists()) {
FileUtils.forceDelete(lockingFile);
}
if (fencingFile.exists()) {
FileUtils.forceDelete(fencingFile);
}
final EnumMap<SstColumnFamily, File> sstFileTable = new EnumMap<>(SstColumnFamily.class);
sstFileTable.put(SstColumnFamily.DEFAULT, defaultSstFile);
sstFileTable.put(SstColumnFamily.SEQUENCE, seqSstFile);
sstFileTable.put(SstColumnFamily.LOCKING, lockingFile);
sstFileTable.put(SstColumnFamily.FENCING, fencingFile);
KVStoreAccessHelper.createSstFiles(this.kvStore, sstFileTable, null, null);
// remove keys
for (int i = 0; i < 10000; i++) {
byte[] bytes = BytesUtil.writeUtf8(String.valueOf(i));
this.kvStore.delete(bytes, null);
}
this.kvStore.resetSequence(BytesUtil.writeUtf8("seq"), null);
for (int i = 0; i < 10000; i++) {
byte[] bytes = BytesUtil.writeUtf8(String.valueOf(i));
TestClosure closure = new TestClosure();
this.kvStore.get(bytes, closure);
assertNull(closure.getData());
}
KVStoreAccessHelper.ingestSstFiles(this.kvStore, sstFileTable);
if (defaultSstFile.exists()) {
FileUtils.forceDelete(defaultSstFile);
}
if (seqSstFile.exists()) {
FileUtils.forceDelete(seqSstFile);
}
if (lockingFile.exists()) {
FileUtils.forceDelete(lockingFile);
}
if (fencingFile.exists()) {
FileUtils.forceDelete(fencingFile);
}
for (int i = 0; i < 10000; i++) {
byte[] bytes = BytesUtil.writeUtf8(String.valueOf(i));
TestClosure closure = new TestClosure();
this.kvStore.get(bytes, closure);
assertArrayEquals((byte[]) closure.getData(), bytes);
}
TestClosure closure = new TestClosure();
this.kvStore.getSequence(BytesUtil.writeUtf8("seq"), 100, closure);
assertEquals(((Sequence) closure.getData()).getStartValue(), 100);
}
Aggregations