Commit de096122 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

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

parent 2cc90475
......@@ -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);
}
}
......@@ -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");
......
......@@ -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_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment