Commit 807607ea authored by Paul Selkirk's avatar Paul Selkirk
Browse files

[2907] add abstract method clientList::getZoneTableAccessor

Also add type ConstZoneTableAccessorPtr for convenience,
pass smart pointer by reference in unit test.
parent a292c65c
......@@ -24,9 +24,9 @@
#include <datasrc/memory/zone_data_loader.h>
#include <datasrc/memory/zone_data_updater.h>
#include <datasrc/logger.h>
#include <datasrc/zone_table_accessor_cache.h>
#include <dns/masterload.h>
#include <util/memory_segment_local.h>
#include <datasrc/zone_table_accessor_cache.h>
#include <memory>
#include <set>
......@@ -400,7 +400,7 @@ ConfigurableClientList::getStatus() const {
return (result);
}
boost::shared_ptr<const ZoneTableAccessor>
ConstZoneTableAccessorPtr
ConfigurableClientList::getZoneTableAccessor(const std::string& datasrc_name,
bool use_cache) const
{
......@@ -418,11 +418,11 @@ ConfigurableClientList::getZoneTableAccessor(const std::string& datasrc_name,
const internal::CacheConfig* config(info.getCacheConfig());
// If caching is disabled for the named data source, this will
// return an accessor to an effectivley empty table.
return (boost::shared_ptr<const ZoneTableAccessor>
return (ConstZoneTableAccessorPtr
(new internal::ZoneTableAccessorCache(*config)));
}
return (boost::shared_ptr<const ZoneTableAccessor>());
return (ConstZoneTableAccessorPtr());
}
}
......
......@@ -121,6 +121,8 @@ private:
MemorySegmentState state_;
};
typedef boost::shared_ptr<const ZoneTableAccessor> ConstZoneTableAccessorPtr;
/// \brief The list of data source clients.
///
/// The purpose of this class is to hold several data source clients and search
......@@ -273,6 +275,19 @@ public:
virtual FindResult find(const dns::Name& zone,
bool want_exact_match = false,
bool want_finder = true) const = 0;
/// \brief Creates a ZoneTableAccessor object for the specified data
/// source.
///
/// \param datasrc_name If not empty, the name of the data source.
/// \param use_cache If true, create a zone table for in-memory cache.
/// \throw NotImplemented if this method is not implemented.
/// \return A pointer to the accessor, or NULL if the requested data
/// source is not found.
virtual ConstZoneTableAccessorPtr
getZoneTableAccessor(const std::string& datasrc_name,
bool use_cache) const = 0;
};
/// \brief Shared pointer to the list.
......@@ -494,7 +509,7 @@ public:
/// \throw NotImplemented if \c use_cache is false.
/// \return A pointer to the accessor, or NULL if the requested data
/// source is not found.
boost::shared_ptr<const ZoneTableAccessor>
ConstZoneTableAccessorPtr
getZoneTableAccessor(const std::string& datasrc_name,
bool use_cache) const;
......
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -254,7 +254,7 @@ public:
}
ConfigurableClientList::CacheStatus doReload(
const Name& origin, const string& datasrc_name = "");
void accessorIterate(boost::shared_ptr<const ZoneTableAccessor> accessor,
void accessorIterate(ConstZoneTableAccessorPtr& accessor,
int numZones, const string& zoneName);
const RRClass rrclass_;
......@@ -1134,31 +1134,25 @@ TEST_F(ListTest, reloadByDataSourceName) {
// through the table, and verifies that the expected number of zones are
// present, as well as the named zone.
void
ListTest::accessorIterate(boost::shared_ptr<const ZoneTableAccessor> accessor,
ListTest::accessorIterate(ConstZoneTableAccessorPtr& accessor,
int numZones, const string& zoneName="")
{
// Confirm basic iterator behavior.
ASSERT_TRUE(accessor);
ZoneTableAccessor::IteratorPtr it = accessor->getIterator();
ASSERT_TRUE(it);
// Iterator does not guarantee ordering, so we look for the target
// name anywhere in the table.
bool found = false;
int i;
for (i = 0; !it->isLast(); ++i, it->next()) {
if (Name(zoneName) == it->getCurrent().origin) {
found = true;
}
}
EXPECT_EQ(i, numZones);
if (numZones > 0) {
EXPECT_FALSE(it->isLast());
EXPECT_EQ(0, it->getCurrent().index);
// Iterator does not guarantee ordering, so we look for the target
// name anywhere in the table.
bool found = false;
int i = 0;
while (!it->isLast()) {
++i;
if (Name(zoneName) == it->getCurrent().origin) {
found = true;
}
it->next();
}
EXPECT_TRUE(found);
EXPECT_EQ(i, numZones);
} else {
EXPECT_TRUE(it->isLast());
}
}
......@@ -1171,8 +1165,7 @@ TEST_F(ListTest, zoneTableAccessor) {
// empty list; expect it to return an empty list
list_->configure(config_elem_, true);
boost::shared_ptr<const ZoneTableAccessor>
z(list_->getZoneTableAccessor("", true));
ConstZoneTableAccessorPtr z(list_->getZoneTableAccessor("", true));
accessorIterate(z, 0);
const ConstElementPtr elem2(Element::fromJSON("["
......
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