Search in sources :

Example 6 with TestClosure

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

Example 7 with TestClosure

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

Example 8 with TestClosure

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

Example 9 with TestClosure

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

Example 10 with TestClosure

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