]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2833] added ZoneTableConfig::getSegmentType() interface.
authorJINMEI Tatuya <jinmei@isc.org>
Thu, 28 Mar 2013 23:10:52 +0000 (16:10 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Thu, 28 Mar 2013 23:10:52 +0000 (16:10 -0700)
src/lib/datasrc/tests/zone_table_config_unittest.cc
src/lib/datasrc/zone_table_config.cc
src/lib/datasrc/zone_table_config.h

index 8b91833c661c5a0dbb9583d3d0555c821d904ef5..325eb774f8637004ee23cdf66e44a8f9466bdcee 100644 (file)
@@ -164,4 +164,23 @@ TEST_F(ZoneTableConfigTest, badConstructWithMock) {
                  isc::InvalidParameter);
 }
 
+TEST_F(ZoneTableConfigTest, getSegmentType) {
+    // Default type
+    EXPECT_EQ("local",
+              ZoneTableConfig("MasterFiles", 0,
+                              *master_config_).getSegmentType());
+
+    // If we explicitly configure it, that value should be used.
+    ConstElementPtr config(Element::fromJSON("{\"cache-type\": \"mapped\","
+                                             " \"params\": {}}" ));
+    EXPECT_EQ("mapped",
+              ZoneTableConfig("MasterFiles", 0, *config).getSegmentType());
+
+    // Wrong types: should be rejected at construction time
+    ConstElementPtr badconfig(Element::fromJSON("{\"cache-type\": 1,"
+                                                " \"params\": {}}"));
+    EXPECT_THROW(ZoneTableConfig("MasterFiles", 0, *badconfig),
+                 isc::data::TypeError);
+}
+
 }
index 45df32a39797f2dba28650394ffaf1af01da1ee0..33284ca31faca5606e8962e200e1807c2c4503c0 100644 (file)
@@ -28,9 +28,22 @@ namespace isc {
 namespace datasrc {
 namespace internal {
 
+namespace {
+std::string
+getSegmentTypeFromConf(const Element& conf) {
+    // If cache-zones is not explicitly configured, use the default type.
+    // (Ideally we should retrieve the default from the spec).
+    if (!conf.contains("cache-type")) {
+        return ("local");
+    }
+    return (conf.get("cache-type")->stringValue());
+}
+}
+
 ZoneTableConfig::ZoneTableConfig(const std::string& datasrc_type,
                                  const DataSourceClient* datasrc_client,
                                  const Element& datasrc_conf) :
+    segment_type_(getSegmentTypeFromConf(datasrc_conf)),
     datasrc_client_(datasrc_client)
 {
     ConstElementPtr params = datasrc_conf.get("params");
index 84edf42dd240b33cd25bb25d97ef6494369962a0..b948414e0d1a6e39a0d514e394b8aaf483a5fe0b 100644 (file)
@@ -50,6 +50,9 @@ public:
                     const DataSourceClient* datasrc_client,
                     const data::Element& datasrc_conf);
 
+    /// \brief Return the memory segment type to be used for the zone table.
+    const std::string& getSegmentType() const { return (segment_type_); }
+
     /// Return corresponding \c LoadAction for the given name of zone.
     /// It would return a different functor depending on the details of the
     /// underlying data source.
@@ -65,6 +68,7 @@ public:
     const Zones& getZoneConfig() const { return (zone_config_); }
 
 private:
+    const std::string segment_type_;
     // client of underlying data source, will be NULL for MasterFile datasrc
     const DataSourceClient* datasrc_client_;
     Zones zone_config_;