use of com.alipay.sofa.jraft.rhea.storage.KVEntry in project sofa-jraft by sofastack.
the class RocksKVStoreTest 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.KVEntry in project sofa-jraft by sofastack.
the class RocksKVStoreTest method putListTest.
/**
* Test method: {@link RocksRawKVStore#put(List, KVStoreClosure)}
*/
@Test
public void putListTest() {
final List<KVEntry> entries = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
entries.add(new KVEntry(makeKey("batch_put_test_key" + i), makeValue("batch_put_test_value" + i)));
}
this.kvStore.put(entries, null);
final List<KVEntry> entries2 = new SyncKVStore<List<KVEntry>>() {
@Override
public void execute(RawKVStore kvStore, KVStoreClosure closure) {
kvStore.scan(makeKey("batch_put_test_key"), makeKey("batch_put_test_key" + 99), closure);
}
}.apply(this.kvStore);
assertEquals(entries.size(), entries2.size());
for (int i = 0; i < entries.size(); i++) {
assertArrayEquals(entries.get(i).getKey(), entries2.get(i).getKey());
assertArrayEquals(entries.get(i).getValue(), entries2.get(i).getValue());
}
}
use of com.alipay.sofa.jraft.rhea.storage.KVEntry in project sofa-jraft by sofastack.
the class RocksKVStoreTest method getApproximateKeysInRangeTest.
@Test
public void getApproximateKeysInRangeTest() {
final List<KVEntry> entries = Lists.newArrayList();
for (int i = 0; i < 10000; i++) {
entries.add(new KVEntry(makeKey("approximate_test" + i), makeValue("approximate_test_value")));
}
this.kvStore.put(entries, null);
long approximateKeys = this.kvStore.getApproximateKeysInRange(makeKey("approximate_test" + 9999), null);
assertEquals(1, approximateKeys);
approximateKeys = this.kvStore.getApproximateKeysInRange(null, makeKey("approximate_test" + 9999));
assertEquals(10000, approximateKeys);
approximateKeys = this.kvStore.getApproximateKeysInRange(makeKey("approximate_test" + 9990), makeKey("approximate_test" + 9999));
assertEquals(10, approximateKeys);
}
use of com.alipay.sofa.jraft.rhea.storage.KVEntry in project sofa-jraft by sofastack.
the class MemoryKVStoreTest method deleteListTest.
/**
* Test method: {@link MemoryRawKVStore#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);
}
}
use of com.alipay.sofa.jraft.rhea.storage.KVEntry in project sofa-jraft by sofastack.
the class MemoryKVStoreTest method getApproximateKeysInRangeTest.
@Test
public void getApproximateKeysInRangeTest() {
final List<KVEntry> entries = Lists.newArrayList();
for (int i = 0; i < 10000; i++) {
entries.add(new KVEntry(makeKey("approximate_test" + i), makeValue("approximate_test_value")));
}
this.kvStore.put(entries, null);
long approximateKeys = this.kvStore.getApproximateKeysInRange(makeKey("approximate_test" + 9999), null);
assertEquals(1, approximateKeys);
approximateKeys = this.kvStore.getApproximateKeysInRange(null, makeKey("approximate_test" + 9999));
assertEquals(10000, approximateKeys, 1);
approximateKeys = this.kvStore.getApproximateKeysInRange(makeKey("approximate_test" + 9990), makeKey("approximate_test" + 9999));
assertEquals(10, approximateKeys, 1);
}
Aggregations