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

[2833] make ZoneTableSegment::create generic so it checks segment type.

the actually behavior is still same: it only supports the "local" segment.
parent de096122
......@@ -16,6 +16,8 @@
#include <datasrc/memory/zone_table_segment_local.h>
#include <datasrc/zone_table_config.h>
#include <string>
using namespace isc::dns;
namespace isc {
......@@ -24,14 +26,18 @@ namespace memory {
ZoneTableSegment::create(const RRClass& rrclass,
const internal::ZoneTableConfig&)
const internal::ZoneTableConfig& config)
/// FIXME: For now, we always return ZoneTableSegmentLocal. This
/// should be updated eventually to parse the passed Element
/// argument and construct a corresponding ZoneTableSegment
/// implementation.
const std::string& sgmt_type = config.getSegmentType();
return (new ZoneTableSegmentLocal(rrclass));
// This will be a few sequences of if-else and hardcoded. Not really
// sophisticated, but we don't expect to have too many types at the moment.
// Until that it becomes a real issue we won't be too smart.
if (sgmt_type == "local") {
return (new ZoneTableSegmentLocal(rrclass));
isc_throw(UnknownSegmentType, "Zone table segment type not supported: "
<< sgmt_type);
......@@ -15,6 +15,8 @@
#include <exceptions/exceptions.h>
#include <dns/rrclass.h>
#include <datasrc/memory/zone_table.h>
......@@ -40,6 +42,15 @@ class ZoneTableConfig;
namespace memory {
class ZoneWriter;
/// \brief Exception thrown when unknown or unsupported type of zone table
/// segment is specified.
class UnknownSegmentType : public Exception {
UnknownSegmentType(const char* file, size_t line, const char* what) :
Exception(file, line, what)
/// \brief Memory-management independent entry point that contains a
/// pointer to a zone table in memory.
......@@ -102,9 +113,10 @@ public:
/// dynamically-allocated object. The caller is responsible for
/// destroying it with \c ZoneTableSegment::destroy().
/// FIXME: For now, we always return ZoneTableSegmentLocal
/// regardless of the passed \c config.
/// \throw UnknownSegmentType The memory segment type specified in
/// \c config is not known or not supported in this implementation.
/// \param rrclass The RR class of the zones to be maintained in the table.
/// \param config The configuration based on which a derived object
/// is returned.
/// \return Returns a ZoneTableSegment object
......@@ -49,6 +49,13 @@ protected:
TEST_F(ZoneTableSegmentTest, create) {
// By default, a local zone table segment is created.
EXPECT_NE(static_cast<void*>(NULL), ztable_segment_);
// Unknown types of segment are rejected.
const isc::datasrc::internal::ZoneTableConfig bad_ztconf(
"MasterFiles", 0, *Element::fromJSON("{\"cache-type\": \"unknown\","
" \"params\": {}}"));
EXPECT_THROW(ZoneTableSegment::create(RRClass::IN(), bad_ztconf),
// Helper function to check const and non-const methods.
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