Search in sources :

Example 1 with DeleteOption

use of com.coreos.jetcd.options.DeleteOption in project jetcd by coreos.

the class KVTest method testGetAndDeleteWithPrefix.

@Test
public void testGetAndDeleteWithPrefix() throws Exception {
    String prefix = randomString();
    ByteString key = ByteString.copyFromUtf8(prefix);
    int numPrefixes = 10;
    putKeysWithPrefix(prefix, numPrefixes);
    // verify get withPrefix.
    ListenableFuture<RangeResponse> getFuture = kvClient.get(key, GetOption.newBuilder().withPrefix(key).build());
    RangeResponse getResp = getFuture.get();
    test.assertEquals(getResp.getCount(), numPrefixes);
    // verify del withPrefix.
    DeleteOption deleteOpt = DeleteOption.newBuilder().withPrefix(key).build();
    ListenableFuture<DeleteRangeResponse> delFuture = kvClient.delete(key, deleteOpt);
    DeleteRangeResponse delResp = delFuture.get();
    test.assertEquals(delResp.getDeleted(), numPrefixes);
}
Also used : DeleteOption(com.coreos.jetcd.options.DeleteOption) DeleteRangeResponse(com.coreos.jetcd.api.DeleteRangeResponse) RangeResponse(com.coreos.jetcd.api.RangeResponse) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) DeleteRangeResponse(com.coreos.jetcd.api.DeleteRangeResponse) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

DeleteRangeResponse (com.coreos.jetcd.api.DeleteRangeResponse)1 RangeResponse (com.coreos.jetcd.api.RangeResponse)1 DeleteOption (com.coreos.jetcd.options.DeleteOption)1 ByteString (com.google.protobuf.ByteString)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1