use of com.coreos.jetcd.api.PutResponse in project jetcd by coreos.
the class LeaseTest method testkeepAlive.
@Test(dependsOnMethods = "testRevoke")
public void testkeepAlive() throws Exception {
long leaseID = leaseClient.grant(5).get().getID();
PutResponse putRep = kvClient.put(testKey, testName, PutOption.newBuilder().withLeaseId(leaseID).build()).get();
test.assertEquals(kvClient.get(testKey).get().getCount(), 1);
leaseClient.startKeepAliveService();
leaseClient.keepAlive(leaseID, new LeaseHandler() {
@Override
public void onKeepAliveRespond(LeaseKeepAliveResponse keepAliveResponse) {
}
@Override
public void onLeaseExpired(long leaseId) {
}
@Override
public void onError(Throwable throwable) {
}
});
Thread.sleep(6000);
test.assertEquals(kvClient.get(testKey).get().getCount(), 1);
leaseClient.cancelKeepAlive(leaseID);
test.assertEquals(kvClient.get(testKey).get().getCount(), 0);
}
use of com.coreos.jetcd.api.PutResponse in project jetcd by coreos.
the class LeaseTest method testGrant.
@Test
public void testGrant() throws Exception {
long leaseID = leaseClient.grant(5).get().getID();
PutResponse putRep = kvClient.put(testKey, testName, PutOption.newBuilder().withLeaseId(leaseID).build()).get();
test.assertEquals(kvClient.get(testKey).get().getCount(), 1);
Thread.sleep(6000);
test.assertEquals(kvClient.get(testKey).get().getCount(), 0);
}
use of com.coreos.jetcd.api.PutResponse in project jetcd by coreos.
the class LeaseTest method testRevoke.
@Test(dependsOnMethods = "testGrant")
public void testRevoke() throws Exception {
long leaseID = leaseClient.grant(5).get().getID();
PutResponse putRep = kvClient.put(testKey, testName, PutOption.newBuilder().withLeaseId(leaseID).build()).get();
test.assertEquals(kvClient.get(testKey).get().getCount(), 1);
leaseClient.revoke(leaseID).get();
test.assertEquals(kvClient.get(testKey).get().getCount(), 0);
}
use of com.coreos.jetcd.api.PutResponse in project jetcd by coreos.
the class KVTest method testTxn.
@Test
public void testTxn() throws Exception {
ByteString sampleKey = ByteString.copyFrom("txn_key", "UTF-8");
ByteString sampleValue = ByteString.copyFrom("xyz", "UTF-8");
ByteString cmpValue = ByteString.copyFrom("abc", "UTF-8");
ByteString putValue = ByteString.copyFrom("XYZ", "UTF-8");
ByteString putValueNew = ByteString.copyFrom("ABC", "UTF-8");
ListenableFuture<PutResponse> feature = kvClient.put(sampleKey, sampleValue);
try {
// put the original txn key value pair
PutResponse putResp = feature.get();
// construct txn operation
Cmp cmp = new Cmp(sampleKey, Cmp.Op.GREATER, CmpTarget.value(cmpValue));
Txn txn = Txn.newBuilder().If(cmp).Then(Op.put(sampleKey, putValue, PutOption.DEFAULT)).Else(Op.put(sampleKey, putValueNew, PutOption.DEFAULT)).build();
ListenableFuture<TxnResponse> txnResp = kvClient.commit(txn);
txnResp.get();
// get the value
RangeResponse getResp = kvClient.get(sampleKey).get();
test.assertEquals(getResp.getKvsList().size(), 1);
test.assertEquals(getResp.getKvs(0).getValue().toStringUtf8(), "XYZ");
} catch (Exception e) {
// empty
}
}
use of com.coreos.jetcd.api.PutResponse in project jetcd by coreos.
the class KVTest method testGet.
@Test
public void testGet() throws Exception {
ByteString sampleKey = ByteString.copyFrom("sample_key2", "UTF-8");
ByteString sampleValue = ByteString.copyFrom("sample_value2", "UTF-8");
ListenableFuture<PutResponse> feature = kvClient.put(sampleKey, sampleValue);
try {
feature.get();
ListenableFuture<RangeResponse> getFeature = kvClient.get(sampleKey);
RangeResponse response = getFeature.get();
test.assertEquals(response.getKvsCount(), 1);
test.assertEquals(response.getKvs(0).getValue().toStringUtf8(), "sample_value2");
test.assertTrue(!response.getMore());
} catch (Exception e) {
// empty
}
}
Aggregations