Search in sources :

Example 6 with RangeResponse

use of com.coreos.jetcd.api.RangeResponse 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 7 with RangeResponse

use of com.coreos.jetcd.api.RangeResponse 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

RangeResponse (com.coreos.jetcd.api.RangeResponse)7 BeforeTest (org.testng.annotations.BeforeTest)7 Test (org.testng.annotations.Test)7 DeleteRangeResponse (com.coreos.jetcd.api.DeleteRangeResponse)6 ByteString (com.google.protobuf.ByteString)6 ExecutionException (java.util.concurrent.ExecutionException)5 PutResponse (com.coreos.jetcd.api.PutResponse)3 GetOption (com.coreos.jetcd.options.GetOption)2 TxnResponse (com.coreos.jetcd.api.TxnResponse)1 Cmp (com.coreos.jetcd.op.Cmp)1 Txn (com.coreos.jetcd.op.Txn)1 DeleteOption (com.coreos.jetcd.options.DeleteOption)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1