Search in sources :

Example 6 with PutResponse

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

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

the class KVTest method testPut.

@Test
public void testPut() throws Exception {
    ByteString sampleKey = ByteString.copyFrom("sample_key", "UTF-8");
    ByteString sampleValue = ByteString.copyFrom("sample_value", "UTF-8");
    ListenableFuture<PutResponse> feature = kvClient.put(sampleKey, sampleValue);
    try {
        PutResponse response = feature.get();
        test.assertTrue(response.hasHeader());
        test.assertTrue(!response.hasPrevKv());
    } catch (Exception e) {
        // empty
        e.printStackTrace();
    }
}
Also used : ByteString(com.google.protobuf.ByteString) PutResponse(com.coreos.jetcd.api.PutResponse) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with PutResponse

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

the class KVTest method testPutWithNotExistLease.

@Test
public void testPutWithNotExistLease() throws Exception {
    ByteString sampleKey = ByteString.copyFrom("sample_key", "UTF-8");
    ByteString sampleValue = ByteString.copyFrom("sample_value", "UTF-8");
    PutOption option = PutOption.newBuilder().withLeaseId(99999).build();
    ListenableFuture<PutResponse> feature = kvClient.put(sampleKey, sampleValue, option);
    try {
        PutResponse response = feature.get();
        test.assertTrue(response.hasHeader());
    } catch (Exception e) {
    // empty
    }
}
Also used : ByteString(com.google.protobuf.ByteString) PutOption(com.coreos.jetcd.options.PutOption) PutResponse(com.coreos.jetcd.api.PutResponse) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

PutResponse (com.coreos.jetcd.api.PutResponse)8 BeforeTest (org.testng.annotations.BeforeTest)8 Test (org.testng.annotations.Test)8 ByteString (com.google.protobuf.ByteString)5 ExecutionException (java.util.concurrent.ExecutionException)5 DeleteRangeResponse (com.coreos.jetcd.api.DeleteRangeResponse)3 RangeResponse (com.coreos.jetcd.api.RangeResponse)3 LeaseHandler (com.coreos.jetcd.Lease.LeaseHandler)1 LeaseKeepAliveResponse (com.coreos.jetcd.api.LeaseKeepAliveResponse)1 TxnResponse (com.coreos.jetcd.api.TxnResponse)1 Cmp (com.coreos.jetcd.op.Cmp)1 Txn (com.coreos.jetcd.op.Txn)1 GetOption (com.coreos.jetcd.options.GetOption)1 PutOption (com.coreos.jetcd.options.PutOption)1