Search in sources :

Example 11 with TestClosure

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);
}
Also used : TestClosure(com.alipay.sofa.jraft.rhea.storage.TestClosure) KVEntry(com.alipay.sofa.jraft.rhea.storage.KVEntry) List(java.util.List) KVStateOutputList(com.alipay.sofa.jraft.rhea.storage.KVStateOutputList) Test(org.junit.Test)

Example 12 with TestClosure

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());
}
Also used : TestClosure(com.alipay.sofa.jraft.rhea.storage.TestClosure) Test(org.junit.Test)

Example 13 with TestClosure

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);
    }
}
Also used : TestClosure(com.alipay.sofa.jraft.rhea.storage.TestClosure) KVEntry(com.alipay.sofa.jraft.rhea.storage.KVEntry) List(java.util.List) KVStateOutputList(com.alipay.sofa.jraft.rhea.storage.KVStateOutputList) Test(org.junit.Test)

Aggregations

TestClosure (com.alipay.sofa.jraft.rhea.storage.TestClosure)13 Test (org.junit.Test)13 KVEntry (com.alipay.sofa.jraft.rhea.storage.KVEntry)6 List (java.util.List)6 BaseKVStoreClosure (com.alipay.sofa.jraft.rhea.storage.BaseKVStoreClosure)4 KVStoreClosure (com.alipay.sofa.jraft.rhea.storage.KVStoreClosure)4 KVStateOutputList (com.alipay.sofa.jraft.rhea.storage.KVStateOutputList)3 Status (com.alipay.sofa.jraft.Status)2 RawKVStore (com.alipay.sofa.jraft.rhea.storage.RawKVStore)2 KVStoreSnapshotFile (com.alipay.sofa.jraft.rhea.storage.KVStoreSnapshotFile)1 MemoryRawKVStore (com.alipay.sofa.jraft.rhea.storage.MemoryRawKVStore)1 RocksRawKVStore (com.alipay.sofa.jraft.rhea.storage.RocksRawKVStore)1 SstColumnFamily (com.alipay.sofa.jraft.rhea.storage.SstColumnFamily)1 File (java.io.File)1 EnumMap (java.util.EnumMap)1