-// 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
#define STAMPED_ELEMENT_H
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <cstdint>
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.
/// 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.
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_;
-// 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
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 =
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) {