expose key version in etcd::Value
This commit is contained in:
parent
1118222b3d
commit
1a9c937e7a
|
|
@ -55,6 +55,11 @@ namespace etcd
|
|||
*/
|
||||
int64_t modified_index() const;
|
||||
|
||||
/**
|
||||
* Returns the version of this value.
|
||||
*/
|
||||
int64_t version() const;
|
||||
|
||||
/**
|
||||
* Returns the ttl of this value or 0 if ttl is not set
|
||||
*/
|
||||
|
|
@ -78,6 +83,7 @@ namespace etcd
|
|||
std::string value;
|
||||
int64_t created;
|
||||
int64_t modified;
|
||||
int64_t _version;
|
||||
int _ttl;
|
||||
int64_t leaseId;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ etcd::Value::Value()
|
|||
: dir(false),
|
||||
created(0),
|
||||
modified(0),
|
||||
_version(0),
|
||||
_ttl(0),
|
||||
leaseId(0)
|
||||
{
|
||||
|
|
@ -20,6 +21,7 @@ etcd::Value::Value(etcdv3::KeyValue const & kv)
|
|||
value = kv.kvs.value();
|
||||
created = kv.kvs.create_revision();
|
||||
modified = kv.kvs.mod_revision();
|
||||
_version = kv.kvs.version();
|
||||
leaseId = kv.kvs.lease();
|
||||
_ttl = kv.get_ttl();
|
||||
}
|
||||
|
|
@ -31,6 +33,7 @@ etcd::Value::Value(mvccpb::KeyValue const & kv)
|
|||
value = kv.value();
|
||||
created = kv.create_revision();
|
||||
modified = kv.mod_revision();
|
||||
_version = kv.version();
|
||||
leaseId = kv.lease();
|
||||
_ttl = -1;
|
||||
}
|
||||
|
|
@ -60,6 +63,11 @@ int64_t etcd::Value::modified_index() const
|
|||
return modified;
|
||||
}
|
||||
|
||||
int64_t etcd::Value::version() const
|
||||
{
|
||||
return _version;
|
||||
}
|
||||
|
||||
int etcd::Value::ttl() const
|
||||
{
|
||||
return _ttl;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ TEST_CASE("add a new key after authenticate")
|
|||
CHECK(!val.is_dir());
|
||||
CHECK(0 < val.created_index());
|
||||
CHECK(0 < val.modified_index());
|
||||
CHECK(1 == val.version());
|
||||
CHECK(0 < resp.index());
|
||||
CHECK(etcd::ERROR_KEY_ALREADY_EXISTS == etcd->add("/test/key1", "43").get().error_code()); // Key already exists
|
||||
CHECK(etcd::ERROR_KEY_ALREADY_EXISTS == etcd->add("/test/key1", "42").get().error_code()); // Key already exists
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ TEST_CASE("add a new key")
|
|||
CHECK(!val.is_dir());
|
||||
CHECK(0 < val.created_index());
|
||||
CHECK(0 < val.modified_index());
|
||||
CHECK(1 == val.version());
|
||||
CHECK(0 < resp.index());
|
||||
CHECK(etcd::ERROR_KEY_ALREADY_EXISTS == etcd.add("/test/key1", "43").get().error_code()); // Key already exists
|
||||
CHECK(etcd::ERROR_KEY_ALREADY_EXISTS == etcd.add("/test/key1", "42").get().error_code()); // Key already exists
|
||||
|
|
@ -117,6 +118,7 @@ TEST_CASE("delete a value")
|
|||
int index = etcd.get("/test/key1").get().index();
|
||||
int create_index = etcd.get("/test/key1").get().value().created_index();
|
||||
int modify_index = etcd.get("/test/key1").get().value().modified_index();
|
||||
int version = etcd.get("/test/key1").get().value().version();
|
||||
|
||||
std::cerr << "index = " << index
|
||||
<< ", create index = " << create_index
|
||||
|
|
@ -131,9 +133,11 @@ TEST_CASE("delete a value")
|
|||
CHECK( "/test/key1" == resp.prev_value().key());
|
||||
CHECK( create_index == resp.prev_value().created_index());
|
||||
CHECK( modify_index == resp.prev_value().modified_index());
|
||||
CHECK( version == resp.prev_value().version());
|
||||
CHECK("delete" == resp.action());
|
||||
CHECK( modify_index == resp.value().modified_index());
|
||||
CHECK( create_index == resp.value().created_index());
|
||||
CHECK( version == resp.value().version());
|
||||
CHECK("" == resp.value().as_string());
|
||||
CHECK( "/test/key1" == resp.value().key());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ TEST_CASE("add a new key after authenticate")
|
|||
CHECK(!val.is_dir());
|
||||
CHECK(0 < val.created_index());
|
||||
CHECK(0 < val.modified_index());
|
||||
CHECK(1 == val.version());
|
||||
CHECK(0 < resp.index());
|
||||
CHECK(etcd::ERROR_KEY_ALREADY_EXISTS == etcd->add("/test/key1", "43").get().error_code()); // Key already exists
|
||||
CHECK(etcd::ERROR_KEY_ALREADY_EXISTS == etcd->add("/test/key1", "42").get().error_code()); // Key already exists
|
||||
|
|
|
|||
Loading…
Reference in New Issue