Search in sources :

Example 1 with DeleteRangeResponse

use of com.coreos.jetcd.api.DeleteRangeResponse in project jetcd by coreos.

the class KVTest method testDelete.

@Test(dependsOnMethods = "testPut")
public void testDelete() throws Exception {
    ByteString keyToDelete = ByteString.copyFrom("sample_key", "UTF-8");
    try {
        // count keys about to delete
        ListenableFuture<RangeResponse> getFeature = kvClient.get(keyToDelete);
        RangeResponse resp = getFeature.get();
        // delete the keys
        ListenableFuture<DeleteRangeResponse> deleteFuture = kvClient.delete(keyToDelete);
        DeleteRangeResponse delResp = deleteFuture.get();
        test.assertEquals(resp.getKvsList().size(), delResp.getDeleted());
    } catch (Exception e) {
    // empty
    }
}
Also used : DeleteRangeResponse(com.coreos.jetcd.api.DeleteRangeResponse) RangeResponse(com.coreos.jetcd.api.RangeResponse) ByteString(com.google.protobuf.ByteString) DeleteRangeResponse(com.coreos.jetcd.api.DeleteRangeResponse) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with DeleteRangeResponse

use of com.coreos.jetcd.api.DeleteRangeResponse 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)2 RangeResponse (com.coreos.jetcd.api.RangeResponse)2 ByteString (com.google.protobuf.ByteString)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 DeleteOption (com.coreos.jetcd.options.DeleteOption)1 ExecutionException (java.util.concurrent.ExecutionException)1