use of com.alipay.sofa.jraft.rhea.storage.TestClosure in project sofa-jraft by sofastack.
the class RocksKVStoreTest method putTest.
/**
* Test method: {@link RocksRawKVStore#put(byte[], byte[], KVStoreClosure)}
*/
@Test
public void putTest() {
final byte[] key = makeKey("put_test");
TestClosure closure = new TestClosure();
this.kvStore.get(key, closure);
byte[] value = (byte[]) closure.getData();
assertNull(value);
value = makeValue("put_test_value");
this.kvStore.put(key, value, null);
byte[] newValue = new SyncKVStore<byte[]>() {
@Override
public void execute(RawKVStore kvStore, KVStoreClosure closure) {
kvStore.get(key, closure);
}
}.apply(this.kvStore);
assertArrayEquals(value, newValue);
}
use of com.alipay.sofa.jraft.rhea.storage.TestClosure in project sofa-jraft by sofastack.
the class RocksKVStoreTest method getAndPutTest.
/**
* Test method: {@link RocksRawKVStore#getAndPut(byte[], byte[], KVStoreClosure)}
*/
@Test
public void getAndPutTest() {
final byte[] key = makeKey("put_test");
TestClosure closure = new TestClosure();
this.kvStore.get(key, closure);
byte[] value = (byte[]) closure.getData();
assertNull(value);
value = makeValue("put_test_value");
KVStoreClosure kvStoreClosure = new BaseKVStoreClosure() {
@Override
public void run(Status status) {
assertEquals(status, Status.OK());
}
};
this.kvStore.getAndPut(key, value, kvStoreClosure);
assertNull(kvStoreClosure.getData());
byte[] newVal = makeValue("put_test_value_new");
this.kvStore.getAndPut(key, newVal, kvStoreClosure);
assertArrayEquals(value, (byte[]) kvStoreClosure.getData());
}
use of com.alipay.sofa.jraft.rhea.storage.TestClosure in project sofa-jraft by sofastack.
the class MemoryKVStoreTest method putTest.
/**
* Test method: {@link MemoryRawKVStore#put(byte[], byte[], KVStoreClosure)}
*/
@Test
public void putTest() {
final byte[] key = makeKey("put_test");
TestClosure closure = new TestClosure();
this.kvStore.get(key, closure);
byte[] value = (byte[]) closure.getData();
assertNull(value);
value = makeValue("put_test_value");
this.kvStore.put(key, value, null);
byte[] newValue = new SyncKVStore<byte[]>() {
@Override
public void execute(RawKVStore kvStore, KVStoreClosure closure) {
kvStore.get(key, closure);
}
}.apply(this.kvStore);
assertArrayEquals(value, newValue);
}
use of com.alipay.sofa.jraft.rhea.storage.TestClosure in project sofa-jraft by sofastack.
the class MemoryKVStoreTest method deleteTest.
@SuppressWarnings("unchecked")
@Test
public void deleteTest() {
final List<KVEntry> entries = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
entries.add(new KVEntry(makeKey("del_test" + i), makeValue("del_test_value")));
}
this.kvStore.put(entries, null);
this.kvStore.delete(makeKey("del_test5"), null);
TestClosure closure = new TestClosure();
this.kvStore.scan(makeKey("del_test"), makeKey("del_test" + 99), closure);
List<KVEntry> entries2 = (List<KVEntry>) closure.getData();
assertEquals(entries.size() - 1, entries2.size());
closure = new TestClosure();
this.kvStore.get(makeKey("del_test5"), closure);
byte[] value = (byte[]) closure.getData();
assertNull(value);
}
use of com.alipay.sofa.jraft.rhea.storage.TestClosure in project sofa-jraft by sofastack.
the class MemoryKVStoreTest 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);
}
Aggregations