Search in sources :

Example 1 with KVStateOutputList

use of com.alipay.sofa.jraft.rhea.storage.KVStateOutputList in project sofa-jraft by sofastack.

the class RocksKVStoreTest method batchPutIfAbsentTest.

/**
 * Test method: {@link RocksRawKVStore#batchPutIfAbsent(KVStateOutputList)}
 */
@Test
public void batchPutIfAbsentTest() {
    final KVStateOutputList kvStates = KVStateOutputList.newInstance();
    final int batchWriteSize = RocksRawKVStore.MAX_BATCH_WRITE_SIZE + 1;
    for (int i = 1; i <= batchWriteSize; i++) {
        final byte[] key = makeKey("put_test" + i);
        final byte[] value = makeValue("put_test_value" + i);
        KVStoreClosure kvStoreClosure = new BaseKVStoreClosure() {

            @Override
            public void run(Status status) {
                assertEquals(status, Status.OK());
            }
        };
        kvStates.add(KVState.of(KVOperation.createPutIfAbsent(key, value), kvStoreClosure));
    }
    this.kvStore.batchPutIfAbsent(kvStates);
    kvStates.forEach(kvState -> assertNull(kvState.getDone().getData()));
    kvStates.clear();
    for (int i = 1; i <= batchWriteSize; i++) {
        final byte[] key = makeKey("put_test" + i);
        final byte[] value = makeValue("put_test_value" + i);
        KVStoreClosure kvStoreClosure = new BaseKVStoreClosure() {

            @Override
            public void run(Status status) {
                assertEquals(status, Status.OK());
            }
        };
        kvStates.add(KVState.of(KVOperation.createPutIfAbsent(key, value), kvStoreClosure));
    }
    this.kvStore.batchPutIfAbsent(kvStates);
    kvStates.forEach(kvState -> assertArrayEquals(kvState.getOp().getValue(), (byte[]) kvState.getDone().getData()));
}
Also used : Status(com.alipay.sofa.jraft.Status) KVStateOutputList(com.alipay.sofa.jraft.rhea.storage.KVStateOutputList) 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 2 with KVStateOutputList

use of com.alipay.sofa.jraft.rhea.storage.KVStateOutputList in project sofa-jraft by sofastack.

the class RocksKVStoreTest method batchCompareAndPutTest.

/**
 * Test method: {@link RocksRawKVStore#batchCompareAndPut(KVStateOutputList)}
 */
@Test
public void batchCompareAndPutTest() {
    final KVStateOutputList kvStates = KVStateOutputList.newInstance();
    final int batchWriteSize = RocksRawKVStore.MAX_BATCH_WRITE_SIZE + 1;
    for (int i = 1; i <= batchWriteSize; i++) {
        final byte[] key = makeKey("put_test" + i);
        final byte[] value = makeValue("put_test_value" + i);
        kvStates.add(KVState.of(KVOperation.createPut(key, value), null));
    }
    this.kvStore.batchPut(kvStates);
    kvStates.clear();
    for (int i = 1; i <= batchWriteSize; i++) {
        final byte[] key = makeKey("put_test" + i);
        final byte[] value = makeValue("put_test_value" + i);
        final byte[] update = makeValue("put_test_update" + i);
        KVStoreClosure kvStoreClosure = new BaseKVStoreClosure() {

            @Override
            public void run(Status status) {
                assertEquals(status, Status.OK());
            }
        };
        kvStates.add(KVState.of(KVOperation.createCompareAndPut(key, update, value), kvStoreClosure));
    }
    this.kvStore.batchCompareAndPut(kvStates);
    kvStates.forEach(kvState -> assertEquals(kvState.getDone().getData(), Boolean.FALSE));
    kvStates.clear();
    for (int i = 1; i <= batchWriteSize; i++) {
        final byte[] key = makeKey("put_test" + i);
        final byte[] value = makeValue("put_test_value" + i);
        final byte[] update = makeValue("put_test_update" + i);
        KVStoreClosure kvStoreClosure = new BaseKVStoreClosure() {

            @Override
            public void run(Status status) {
                assertEquals(status, Status.OK());
            }
        };
        kvStates.add(KVState.of(KVOperation.createCompareAndPut(key, value, update), kvStoreClosure));
    }
    this.kvStore.batchCompareAndPut(kvStates);
    kvStates.forEach(kvState -> assertEquals(kvState.getDone().getData(), Boolean.TRUE));
}
Also used : Status(com.alipay.sofa.jraft.Status) KVStateOutputList(com.alipay.sofa.jraft.rhea.storage.KVStateOutputList) 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)

Aggregations

Status (com.alipay.sofa.jraft.Status)2 BaseKVStoreClosure (com.alipay.sofa.jraft.rhea.storage.BaseKVStoreClosure)2 KVStateOutputList (com.alipay.sofa.jraft.rhea.storage.KVStateOutputList)2 KVStoreClosure (com.alipay.sofa.jraft.rhea.storage.KVStoreClosure)2 Test (org.junit.Test)2