Added new interface for leasegrant and leaseId in add, set, modify, modify_if
This commit is contained in:
parent
ac54e84f6d
commit
888946b589
|
|
@ -24,16 +24,22 @@ namespace etcd
|
|||
|
||||
Response get(std::string const & key);
|
||||
Response set(std::string const & key, std::string const & value, int ttl = 0);
|
||||
Response set(std::string const & key, std::string const & value, int64_t leaseId);
|
||||
Response add(std::string const & key, std::string const & value, int ttl = 0);
|
||||
Response add(std::string const & key, std::string const & value, int64_t leaseId);
|
||||
Response modify(std::string const & key, std::string const & value, int ttl = 0);
|
||||
Response modify(std::string const & key, std::string const & value, int64_t leaseId);
|
||||
Response modify_if(std::string const & key, std::string const & value, std::string const & old_value, int ttl = 0);
|
||||
Response modify_if(std::string const & key, std::string const & value, std::string const & old_value, int64_t leaseId);
|
||||
Response modify_if(std::string const & key, std::string const & value, int old_index, int ttl = 0);
|
||||
Response modify_if(std::string const & key, std::string const & value, int old_index, int64_t leaseId);
|
||||
Response rm(std::string const & key);
|
||||
Response rm_if(std::string const & key, std::string const & old_value);
|
||||
Response rm_if(std::string const & key, int old_index);
|
||||
Response ls(std::string const & key);
|
||||
Response mkdir(std::string const & key, int ttl = 0);
|
||||
Response rmdir(std::string const & key, bool recursive = false);
|
||||
Response leasegrant(int ttl);
|
||||
|
||||
/**
|
||||
* Watches for changes of a key or a subtree. Please note that if you watch e.g. "/testdir" and
|
||||
|
|
|
|||
|
|
@ -25,26 +25,51 @@ etcd::Response etcd::SyncClient::set(std::string const & key, std::string const
|
|||
CHECK_EXCEPTIONS(client.set(key, value, ttl).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::set(std::string const & key, std::string const & value, int64_t leaseId)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.set(key, value, leaseId).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::add(std::string const & key, std::string const & value, int ttl)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.add(key, value, ttl).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::add(std::string const & key, std::string const & value, int64_t leaseId)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.add(key, value, leaseId).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::modify(std::string const & key, std::string const & value, int ttl)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.modify(key, value, ttl).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::modify(std::string const & key, std::string const & value, int64_t leaseId)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.modify(key, value, leaseId).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string const & value, std::string const & old_value, int ttl)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.modify_if(key, value, old_value, ttl).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string const & value, std::string const & old_value, int64_t leaseId)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.modify_if(key, value, old_value, leaseId).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string const & value, int old_index, int ttl)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.modify_if(key, value, old_index, ttl).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::modify_if(std::string const & key, std::string const & value, int old_index, int64_t leaseId)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.modify_if(key, value, old_index, leaseId).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::rm(std::string const & key)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.rm(key).get());
|
||||
|
|
@ -71,6 +96,11 @@ etcd::Response etcd::SyncClient::ls(std::string const & key)
|
|||
CHECK_EXCEPTIONS(client.ls(key).get());
|
||||
}
|
||||
|
||||
etcd::Response etcd::SyncClient::leasegrant(int ttl)
|
||||
{
|
||||
CHECK_EXCEPTIONS(client.leasegrant(ttl).get());
|
||||
}
|
||||
|
||||
// etcd::Response etcd::SyncClient::watch(std::string const & key, bool recursive)
|
||||
// {
|
||||
// web::http::uri_builder uri("/v2/keys" + key);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,46 @@ TEST_CASE("sync operations")
|
|||
CHECK(101 == etcd.rm_if("/test/key1", index - 1).error_code());
|
||||
CHECK(0 == etcd.rm_if("/test/key1", index).error_code());
|
||||
|
||||
//leasegrant
|
||||
etcd::Response res = etcd.leasegrant(60);
|
||||
REQUIRE(res.is_ok());
|
||||
CHECK(60 == res.value().ttl());
|
||||
CHECK(0 < res.value().lease());
|
||||
int64_t leaseid = res.value().lease();
|
||||
|
||||
//add with lease
|
||||
res = etcd.add("/test/key1111", "43", leaseid);
|
||||
REQUIRE(0 == res.error_code()); // overwrite
|
||||
CHECK("create" == res.action());
|
||||
CHECK(leaseid == res.value().lease());
|
||||
|
||||
//set with lease
|
||||
res = etcd.set("/test/key1", "43", leaseid);
|
||||
REQUIRE(0 == res.error_code());
|
||||
CHECK("set" == res.action());
|
||||
CHECK(leaseid == res.value().lease());
|
||||
|
||||
//modify with lease
|
||||
res = etcd.modify("/test/key1", "44", leaseid);
|
||||
REQUIRE(0 == res.error_code());
|
||||
CHECK("update" == res.action());
|
||||
CHECK(leaseid == res.value().lease());
|
||||
CHECK("44" == res.value().as_string());
|
||||
|
||||
res = etcd.modify_if("/test/key1", "45", "44", leaseid);
|
||||
index = res.index();
|
||||
REQUIRE(res.is_ok());
|
||||
CHECK("compareAndSwap" == res.action());
|
||||
CHECK(leaseid == res.value().lease());
|
||||
CHECK("45" == res.value().as_string());
|
||||
|
||||
res = etcd.modify_if("/test/key1", "44", index, leaseid);
|
||||
index = res.index();
|
||||
REQUIRE(res.is_ok());
|
||||
CHECK("compareAndSwap" == res.action());
|
||||
CHECK(leaseid == res.value().lease());
|
||||
CHECK("44" == res.value().as_string());
|
||||
|
||||
// TEST_CASE("wait for a value change")
|
||||
// {
|
||||
// etcd::Client etcd(etcd_uri);
|
||||
|
|
|
|||
|
|
@ -417,11 +417,6 @@ TEST_CASE("lease grant")
|
|||
REQUIRE(!res.is_ok());
|
||||
REQUIRE(5 == res.error_code());
|
||||
CHECK("etcdserver: requested lease not found" == res.error_message());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("cleanup")
|
||||
|
|
|
|||
Loading…
Reference in New Issue