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()));
}
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));
}
Aggregations