From: Marcin Siodelski Date: Wed, 27 Mar 2019 16:47:47 +0000 (+0100) Subject: [#103,!289] Hold database id in the StampedElement. X-Git-Tag: Kea-1.6.0-beta~282 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=845d0adf319b6592172bb5175cd145f3e62c3e4c;p=thirdparty%2Fkea.git [#103,!289] Hold database id in the StampedElement. --- diff --git a/src/lib/cc/stamped_element.cc b/src/lib/cc/stamped_element.cc index 32bf59588e..0da5aa3735 100644 --- a/src/lib/cc/stamped_element.cc +++ b/src/lib/cc/stamped_element.cc @@ -12,7 +12,7 @@ namespace data { StampedElement::StampedElement() /// @todo Change it to microsec_clock once we transition to subsecond /// precision. - : timestamp_(boost::posix_time::second_clock::local_time()) { + : id_(0), timestamp_(boost::posix_time::second_clock::local_time()) { } void diff --git a/src/lib/cc/stamped_element.h b/src/lib/cc/stamped_element.h index b6a59e913c..63e69d1bf7 100644 --- a/src/lib/cc/stamped_element.h +++ b/src/lib/cc/stamped_element.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -8,19 +8,21 @@ #define STAMPED_ELEMENT_H #include +#include namespace isc { namespace data { /// @brief This class represents configuration element which is -/// associated with the modification timestamp. +/// associated with database identifier and the modification +/// timestamp. /// /// Classes storing Kea configuration should derive from this object -/// to track modification times of the configuration objects. This -/// is specifically required by the Kea Configuration Backend feature -/// which stores configuration in the database and must be able -/// to recognize recently modified objects to fetch incremental -/// changes. +/// to track ids and modification times of the configuration objects. +/// This is specifically required by the Kea Configuration Backend +/// feature which stores and fetches configuration from the database. +/// The configuration elements must be accessible by their database +/// identifiers and modification times. /// /// @note This class is not derived from @c Element and should not /// be confused with the classes being derived from @c Element class. @@ -36,6 +38,18 @@ public: /// Sets timestamp to the current time. StampedElement(); + /// @brief Sets element's database identifier. + /// + /// @param id New id. + void setId(const uint64_t id) { + id_ = id; + } + + /// @brief Returns element's database identifier. + uint64_t getId() const { + return (id_); + } + /// @brief Sets timestamp to the explicitly provided value. /// /// @param timestamp New timestamp value. @@ -53,6 +67,12 @@ public: private: + /// @brief Database identifier of the configuration element. + /// + /// The default value of 0 indicates that the identifier is + /// not set. + uint64_t id_; + /// @brief Holds timestamp value. boost::posix_time::ptime timestamp_; diff --git a/src/lib/cc/tests/stamped_element_unittest.cc b/src/lib/cc/tests/stamped_element_unittest.cc index 402b3811a9..8ca5378297 100644 --- a/src/lib/cc/tests/stamped_element_unittest.cc +++ b/src/lib/cc/tests/stamped_element_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -16,10 +16,13 @@ using namespace isc::data; namespace { // Tests that the modification timestamp is by default set to current -// time. +// time and the identifier is set to 0. TEST(StampedElementTest, create) { StampedElement element; + // Default identifier is 0. + EXPECT_EQ(0, element.getId()); + // Checking that the delta between now and the timestamp is within // 5s range should be sufficient. boost::posix_time::time_duration delta = @@ -28,6 +31,13 @@ TEST(StampedElementTest, create) { EXPECT_LT(delta.seconds(), 5); } +// Tests that default id can be overriden by a new value. +TEST(StampedElementTest, setId) { + StampedElement element; + element.setId(123); + EXPECT_EQ(123, element.getId()); +} + // Tests that the modification timestamp can be set to an arbitrary // value. TEST(StampedElementTest, setModificationTime) {