use of com.alipay.sofa.jraft.rhea.storage.TestClosure in project sofa-jraft by sofastack.
the class RocksKVStoreTest method deleteRangeTest.
@SuppressWarnings("unchecked")
@Test
public void deleteRangeTest() {
final List<KVEntry> entries = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
entries.add(new KVEntry(makeKey("del_range_test" + i), makeValue("del_range_test" + i)));
}
this.kvStore.put(entries, null);
// delete [del_range_test5, del_range_test8)
this.kvStore.deleteRange(makeKey("del_range_test5"), makeKey("del_range_test8"), null);
TestClosure closure = new TestClosure();
this.kvStore.scan(makeKey("del_range_test"), makeKey("del_range_test" + 99), closure);
final List<KVEntry> entries2 = (List<KVEntry>) closure.getData();
assertEquals(entries.size() - 3, entries2.size());
closure = new TestClosure();
this.kvStore.get(makeKey("del_range_test5"), closure);
byte[] value = (byte[]) closure.getData();
assertNull(value);
closure = new TestClosure();
this.kvStore.get(makeKey("del_range_test6"), closure);
value = (byte[]) closure.getData();
assertNull(value);
closure = new TestClosure();
this.kvStore.get(makeKey("del_range_test7"), closure);
value = (byte[]) closure.getData();
assertNull(value);
closure = new TestClosure();
this.kvStore.get(makeKey("del_range_test8"), closure);
value = (byte[]) closure.getData();
assertNotNull(value);
}
use of com.alipay.sofa.jraft.rhea.storage.TestClosure in project sofa-jraft by sofastack.
the class RocksKVStoreTest method putIfAbsentTest.
/**
* Test method: {@link RocksRawKVStore#putIfAbsent(byte[], byte[], KVStoreClosure)}
*/
@Test
public void putIfAbsentTest() {
byte[] key = makeKey("put_if_absent_test");
byte[] value = makeValue("put_if_absent_test_value");
TestClosure closure = new TestClosure();
this.kvStore.putIfAbsent(key, value, closure);
assertNull(closure.getData());
this.kvStore.putIfAbsent(key, value, closure);
assertArrayEquals(value, (byte[]) closure.getData());
}
use of com.alipay.sofa.jraft.rhea.storage.TestClosure in project sofa-jraft by sofastack.
the class RocksKVStoreTest method deleteListTest.
/**
* Test method: {@link RocksRawKVStore#delete(List, KVStoreClosure)}
*/
@SuppressWarnings("unchecked")
@Test
public void deleteListTest() {
final List<KVEntry> entries = Lists.newArrayList();
final List<byte[]> keys = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
final byte[] key = makeKey("batch_del_test" + i);
entries.add(new KVEntry(key, makeValue("batch_del_test_value")));
keys.add(key);
}
this.kvStore.put(entries, null);
this.kvStore.delete(keys, null);
TestClosure closure = new TestClosure();
this.kvStore.scan(makeKey("batch_del_test"), makeKey("batch_del_test" + 99), closure);
List<KVEntry> entries2 = (List<KVEntry>) closure.getData();
assertEquals(0, entries2.size());
for (int i = 0; i < keys.size(); i++) {
closure = new TestClosure();
this.kvStore.get(keys.get(i), closure);
byte[] value = (byte[]) closure.getData();
assertNull(value);
}
}
Aggregations