Search in sources :

Example 1 with KVEntry

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);
}
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 2 with KVEntry

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

Example 3 with KVEntry

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

Example 4 with KVEntry

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);
    }
}
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 5 with KVEntry

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

Aggregations

KVEntry (com.alipay.sofa.jraft.rhea.storage.KVEntry)36 List (java.util.List)17 Test (org.junit.Test)14 Status (com.alipay.sofa.jraft.Status)8 Region (com.alipay.sofa.jraft.rhea.metadata.Region)8 KVStoreClosure (com.alipay.sofa.jraft.rhea.storage.KVStoreClosure)8 RawKVStore (com.alipay.sofa.jraft.rhea.storage.RawKVStore)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 RouteTable (com.alipay.sofa.jraft.RouteTable)6 PeerId (com.alipay.sofa.jraft.entity.PeerId)6 DescriberManager (com.alipay.sofa.jraft.rhea.DescriberManager)6 FollowerStateListener (com.alipay.sofa.jraft.rhea.FollowerStateListener)6 JRaftHelper (com.alipay.sofa.jraft.rhea.JRaftHelper)6 LeaderStateListener (com.alipay.sofa.jraft.rhea.LeaderStateListener)6 RegionEngine (com.alipay.sofa.jraft.rhea.RegionEngine)6 StateListener (com.alipay.sofa.jraft.rhea.StateListener)6 StateListenerContainer (com.alipay.sofa.jraft.rhea.StateListenerContainer)6 StoreEngine (com.alipay.sofa.jraft.rhea.StoreEngine)6 FailoverClosure (com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure)6 ListRetryCallable (com.alipay.sofa.jraft.rhea.client.failover.ListRetryCallable)6