Search in sources :

Example 1 with DeleteOption

use of io.etcd.jetcd.options.DeleteOption 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);
}
Also used : DeleteOption(io.etcd.jetcd.options.DeleteOption) DeleteResponse(io.etcd.jetcd.kv.DeleteResponse) TestUtil.randomString(io.etcd.jetcd.impl.TestUtil.randomString) GetResponse(io.etcd.jetcd.kv.GetResponse) ByteSequence(io.etcd.jetcd.ByteSequence) Test(org.junit.jupiter.api.Test)

Aggregations

ByteSequence (io.etcd.jetcd.ByteSequence)1 TestUtil.randomString (io.etcd.jetcd.impl.TestUtil.randomString)1 DeleteResponse (io.etcd.jetcd.kv.DeleteResponse)1 GetResponse (io.etcd.jetcd.kv.GetResponse)1 DeleteOption (io.etcd.jetcd.options.DeleteOption)1 Test (org.junit.jupiter.api.Test)1