diff --git a/etcd/Value.hpp b/etcd/Value.hpp index ce13e94..fc87e50 100644 --- a/etcd/Value.hpp +++ b/etcd/Value.hpp @@ -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; }; diff --git a/src/Value.cpp b/src/Value.cpp index 41a5cde..809ac91 100644 --- a/src/Value.cpp +++ b/src/Value.cpp @@ -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; diff --git a/tst/AuthTest.cpp b/tst/AuthTest.cpp index aaa3ba3..9efc91f 100644 --- a/tst/AuthTest.cpp +++ b/tst/AuthTest.cpp @@ -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 diff --git a/tst/EtcdTest.cpp b/tst/EtcdTest.cpp index 5810d51..84278d4 100644 --- a/tst/EtcdTest.cpp +++ b/tst/EtcdTest.cpp @@ -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()); } diff --git a/tst/SecurityChannelTest.cpp b/tst/SecurityChannelTest.cpp index bb7ee61..fda754e 100644 --- a/tst/SecurityChannelTest.cpp +++ b/tst/SecurityChannelTest.cpp @@ -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