Search in sources :

Example 1 with GetOption

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

the class KVTest method testGetWithRev.

@Test
public void testGetWithRev() throws Exception {
    ByteString sampleKey = ByteString.copyFrom("sample_key3", "UTF-8");
    ByteString sampleValue = ByteString.copyFrom("sample_value", "UTF-8");
    ByteString sampleValueTwo = ByteString.copyFrom("sample_value2", "UTF-8");
    ListenableFuture<PutResponse> feature = kvClient.put(sampleKey, sampleValue);
    try {
        PutResponse putResp = feature.get();
        kvClient.put(sampleKey, sampleValueTwo).get();
        GetOption option = GetOption.newBuilder().withRevision(putResp.getHeader().getRevision()).build();
        ListenableFuture<RangeResponse> getFeature = kvClient.get(sampleKey, option);
        RangeResponse response = getFeature.get();
        test.assertEquals(response.getKvsCount(), 1);
        test.assertEquals(response.getKvs(0).getValue().toStringUtf8(), "sample_value");
    } catch (Exception e) {
    // empty
    }
}
Also used : DeleteRangeResponse(com.coreos.jetcd.api.DeleteRangeResponse) RangeResponse(com.coreos.jetcd.api.RangeResponse) ByteString(com.google.protobuf.ByteString) GetOption(com.coreos.jetcd.options.GetOption) PutResponse(com.coreos.jetcd.api.PutResponse) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with GetOption

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

the class KVTest method testGetSortedPrefix.

@Test
public void testGetSortedPrefix() throws Exception {
    ByteString key = ByteString.copyFrom("test_key", "UTF-8");
    ByteString testValue = ByteString.copyFrom("test_value", "UTF-8");
    for (int i = 0; i < 3; i++) {
        ByteString testKey = ByteString.copyFrom("test_key" + i, "UTF-8");
        try {
            kvClient.put(testKey, testValue).get();
        } catch (Exception e) {
        // empty
        }
    }
    ByteString endKey = ByteString.copyFrom("\0", "UTF-8");
    GetOption option = GetOption.newBuilder().withSortField(RangeRequest.SortTarget.KEY).withSortOrder(RangeRequest.SortOrder.DESCEND).withRange(endKey).build();
    try {
        ListenableFuture<RangeResponse> getFeature = kvClient.get(key, option);
        RangeResponse response = getFeature.get();
        test.assertEquals(response.getKvsCount(), 3);
        test.assertEquals(response.getKvs(0).getKey().toStringUtf8(), "test_key2");
        test.assertEquals(response.getKvs(0).getValue().toStringUtf8(), "test_value");
        test.assertEquals(response.getKvs(1).getKey().toStringUtf8(), "test_key1");
        test.assertEquals(response.getKvs(1).getValue().toStringUtf8(), "test_value");
        test.assertEquals(response.getKvs(2).getKey().toStringUtf8(), "test_key0");
        test.assertEquals(response.getKvs(2).getValue().toStringUtf8(), "test_value");
    } catch (Exception e) {
    // empty
    }
}
Also used : DeleteRangeResponse(com.coreos.jetcd.api.DeleteRangeResponse) RangeResponse(com.coreos.jetcd.api.RangeResponse) ByteString(com.google.protobuf.ByteString) GetOption(com.coreos.jetcd.options.GetOption) ExecutionException(java.util.concurrent.ExecutionException) 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 GetOption (com.coreos.jetcd.options.GetOption)2 ByteString (com.google.protobuf.ByteString)2 ExecutionException (java.util.concurrent.ExecutionException)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 PutResponse (com.coreos.jetcd.api.PutResponse)1