Browse Source

[2833] added ZoneTableConfig::getSegmentType() interface.

JINMEI Tatuya 12 years ago
parent
commit
de096122c7

+ 19 - 0
src/lib/datasrc/tests/zone_table_config_unittest.cc

@@ -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);
+}
+
 }

+ 13 - 0
src/lib/datasrc/zone_table_config.cc

@@ -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");

+ 4 - 0
src/lib/datasrc/zone_table_config.h

@@ -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_;