Search in sources :

Example 6 with DeleteResponse

use of io.etcd.jetcd.kv.DeleteResponse in project jetcd by coreos.

the class KVNamespaceTest method deleteKVsWithAssertion.

private static void deleteKVsWithAssertion(KV kvClient, ByteSequence key, ByteSequence end, List<TestKeyValue> previousKVs) throws Exception {
    CompletableFuture<DeleteResponse> deleteFuture = kvClient.delete(key, DeleteOption.newBuilder().withRange(end).withPrevKV(true).build());
    DeleteResponse deleteResponse = deleteFuture.get();
    assertThat(deleteResponse.getDeleted()).isEqualTo(previousKVs.size());
    assertThat(deleteResponse.getPrevKvs().size()).isEqualTo(previousKVs.size());
    for (KeyValue keyValue : deleteResponse.getPrevKvs()) {
        boolean exist = false;
        for (TestKeyValue previousKV : previousKVs) {
            if (previousKV.key.equals(keyValue.getKey())) {
                exist = true;
                assertThat(keyValue.getValue()).isEqualTo(previousKV.value);
                break;
            }
        }
        assertThat(exist).isTrue();
    }
}
Also used : DeleteResponse(io.etcd.jetcd.kv.DeleteResponse) KeyValue(io.etcd.jetcd.KeyValue)

Aggregations

DeleteResponse (io.etcd.jetcd.kv.DeleteResponse)6 ByteSequence (io.etcd.jetcd.ByteSequence)3 GetResponse (io.etcd.jetcd.kv.GetResponse)3 Test (org.junit.jupiter.api.Test)3 TestUtil.randomString (io.etcd.jetcd.impl.TestUtil.randomString)2 KeyValue (io.etcd.jetcd.KeyValue)1 TxnResponse (io.etcd.jetcd.kv.TxnResponse)1 Cmp (io.etcd.jetcd.op.Cmp)1 Op (io.etcd.jetcd.op.Op)1 DeleteOption (io.etcd.jetcd.options.DeleteOption)1 Errors (io.etcd.jetcd.support.Errors)1