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);
+}
+
}
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");
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.
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_;