use of io.etcd.jetcd.kv.DeleteResponse in project jetcd by coreos.
the class KVTest method testDelete.
@Test
public void testDelete() throws Exception {
// Put content so that we actually have something to delete
testPut();
ByteSequence keyToDelete = SAMPLE_KEY;
// count keys about to delete
CompletableFuture<GetResponse> getFeature = kvClient.get(keyToDelete);
GetResponse resp = getFeature.get();
// delete the keys
CompletableFuture<DeleteResponse> deleteFuture = kvClient.delete(keyToDelete);
DeleteResponse delResp = deleteFuture.get();
assertThat(delResp.getDeleted()).isEqualTo(resp.getKvs().size());
}
use of io.etcd.jetcd.kv.DeleteResponse in project jetcd by coreos.
the class KVTest method testTxnGetAndDeleteWithPrefix.
@Test
void testTxnGetAndDeleteWithPrefix() throws ExecutionException, InterruptedException {
String prefix = randomString();
ByteSequence sampleKey = bytesOf(prefix);
int numPrefixes = 10;
putKeysWithPrefix(prefix, numPrefixes);
// always false cmp
Cmp cmp = new Cmp(sampleKey, Cmp.Op.EQUAL, CmpTarget.value(bytesOf("not_exists")));
Op.PutOp putOp = Op.put(bytesOf("other_string"), bytesOf("other_value"), PutOption.DEFAULT);
Op.GetOp getByPrefix = Op.get(sampleKey, GetOption.newBuilder().isPrefix(true).build());
Op.DeleteOp delete = Op.delete(sampleKey, DeleteOption.newBuilder().isPrefix(true).withPrevKV(true).build());
TxnResponse txnResponse = kvClient.txn().If(cmp).Then(putOp).Else(getByPrefix, delete).commit().get();
List<GetResponse> getResponse = txnResponse.getGetResponses();
assertThat(getResponse).hasSize(1);
assertThat(getResponse.get(0).getKvs()).hasSize(10);
assertThat(getResponse.get(0).getKvs()).anyMatch(keyValue -> keyValue.getKey().startsWith(sampleKey));
List<DeleteResponse> deleteResponses = txnResponse.getDeleteResponses();
assertThat(deleteResponses).hasSize(1);
assertThat(deleteResponses.get(0).getDeleted()).isEqualTo(10);
assertThat(deleteResponses.get(0).getPrevKvs()).anyMatch(keyValue -> keyValue.getKey().startsWith(sampleKey));
assertThat(txnResponse.getPutResponses()).isEmpty();
}
use of io.etcd.jetcd.kv.DeleteResponse in project jetcd by coreos.
the class KVNamespaceTest method deleteKVWithAssertion.
private static void deleteKVWithAssertion(KV kvClient, ByteSequence key, ByteSequence prevValue) throws Exception {
CompletableFuture<DeleteResponse> deleteFuture = kvClient.delete(key, DeleteOption.newBuilder().withPrevKV(true).build());
DeleteResponse deleteResponse = deleteFuture.get();
assertThat(deleteResponse.getDeleted()).isEqualTo(1);
assertThat(deleteResponse.getPrevKvs().size()).isEqualTo(1);
assertThat(deleteResponse.getPrevKvs().get(0).getKey()).isEqualTo(key);
assertThat(deleteResponse.getPrevKvs().get(0).getValue()).isEqualTo(prevValue);
assertNonexistentKey(kvClient, key);
}
use of io.etcd.jetcd.kv.DeleteResponse in project jetcd by coreos.
the class KVImpl method delete.
@Override
public CompletableFuture<DeleteResponse> delete(ByteSequence key, DeleteOption option) {
checkNotNull(key, "key should not be null");
checkNotNull(option, "option should not be null");
return execute(() -> stub.deleteRange(Requests.mapDeleteRequest(key, option, namespace)), response -> new DeleteResponse(response, namespace), Errors::isRetryable);
}
use of io.etcd.jetcd.kv.DeleteResponse in project jetcd by coreos.
the class KVTest method testGetAndDeleteWithPrefix.
@Test
public void testGetAndDeleteWithPrefix() throws Exception {
String prefix = randomString();
ByteSequence key = bytesOf(prefix);
int numPrefixes = 10;
putKeysWithPrefix(prefix, numPrefixes);
// verify get withPrefix.
CompletableFuture<GetResponse> getFuture = kvClient.get(key, GetOption.newBuilder().isPrefix(true).build());
GetResponse getResp = getFuture.get();
assertThat(getResp.getCount()).isEqualTo(numPrefixes);
// verify del withPrefix.
DeleteOption deleteOpt = DeleteOption.newBuilder().isPrefix(true).build();
CompletableFuture<DeleteResponse> delFuture = kvClient.delete(key, deleteOpt);
DeleteResponse delResp = delFuture.get();
assertThat(delResp.getDeleted()).isEqualTo(numPrefixes);
}
Aggregations