[svn] commit: r2266 - in /branches/trac192/src/lib/datasrc: ./ tests/
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jun 24 17:41:46 UTC 2010
Author: each
Date: Thu Jun 24 17:41:46 2010
New Revision: 2266
Log:
Address review comments:
- add a flag to enable/disable the cache
- add a default cache size limit (currently 30,000)
- separate ZoneInfo and DataSrcMatch classes
Modified:
branches/trac192/src/lib/datasrc/cache.cc
branches/trac192/src/lib/datasrc/cache.h
branches/trac192/src/lib/datasrc/data_source.cc
branches/trac192/src/lib/datasrc/data_source.h
branches/trac192/src/lib/datasrc/query.h
branches/trac192/src/lib/datasrc/sqlite3_datasrc.cc
branches/trac192/src/lib/datasrc/sqlite3_datasrc.h
branches/trac192/src/lib/datasrc/static_datasrc.cc
branches/trac192/src/lib/datasrc/static_datasrc.h
branches/trac192/src/lib/datasrc/tests/cache_unittest.cc
branches/trac192/src/lib/datasrc/tests/datasrc_unittest.cc
branches/trac192/src/lib/datasrc/tests/sqlite3_unittest.cc
branches/trac192/src/lib/datasrc/tests/static_unittest.cc
branches/trac192/src/lib/datasrc/tests/test_datasrc.cc
branches/trac192/src/lib/datasrc/tests/test_datasrc.h
Modified: branches/trac192/src/lib/datasrc/cache.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/cache.cc (original)
+++ branches/trac192/src/lib/datasrc/cache.cc Thu Jun 24 17:41:46 2010
@@ -167,12 +167,15 @@
/// hash table instead.)
class HotCacheImpl {
public:
- HotCacheImpl(int slots);
+ HotCacheImpl(int slots, bool enabled);
~HotCacheImpl();
// Pointers to the head and tail of the LRU list.
CacheNodePtr lru_head_;
CacheNodePtr lru_tail_;
+
+ // Is this cache enabled? (True by default)
+ bool enabled_;
// Number of available slots in the LRU list. (If zero,
// then the list is unbounded; otherwise, items are removed
@@ -196,7 +199,9 @@
};
// HotCacheImpl constructor
-HotCacheImpl::HotCacheImpl(const int slots) : slots_(slots), count_(0) {}
+HotCacheImpl::HotCacheImpl(int slots, bool enabled) :
+ enabled_(enabled), slots_(slots), count_(0)
+{}
// HotCacheImpl destructor
HotCacheImpl::~HotCacheImpl() {
@@ -297,7 +302,7 @@
// HotCache constructor
HotCache::HotCache(const int slots) {
- impl_ = new HotCacheImpl(slots);
+ impl_ = new HotCacheImpl(slots, true);
}
// HotCache destructor
@@ -310,6 +315,10 @@
HotCache::addPositive(RRsetPtr rrset, const uint32_t flags,
const time_t lifespan)
{
+ if (!impl_->enabled_) {
+ return;
+ }
+
impl_->insert(CacheNodePtr(new CacheNode(rrset, flags, lifespan)));
}
@@ -319,6 +328,10 @@
const RRType& rrtype, const uint32_t flags,
const time_t lifespan)
{
+ if (!impl_->enabled_) {
+ return;
+ }
+
if (rrtype == RRType::ANY() || rrclass == RRClass::ANY()) {
return;
}
@@ -333,6 +346,10 @@
HotCache::retrieve(const Name& n, const RRClass& c, const RRType& t,
RRsetPtr& rrset, uint32_t& flags)
{
+ if (!impl_->enabled_) {
+ return (false);
+ }
+
std::map<Question, CacheNodePtr>::const_iterator iter;
iter = impl_->map_.find(Question(n, c, t));
if (iter == impl_->map_.end()) {
@@ -357,6 +374,10 @@
HotCache::setSlots(const int slots) {
impl_->slots_ = slots;
+ if (!impl_->enabled_) {
+ return;
+ }
+
while (impl_->slots_ != 0 && impl_->count_ > impl_->slots_ &&
impl_->lru_tail_)
{
@@ -370,6 +391,18 @@
return (impl_->slots_);
}
+/// Enable or disable the cache
+void
+HotCache::setEnabled(bool e) {
+ impl_->enabled_ = e;
+}
+
+/// Indicate whether the cache is enabled
+bool
+HotCache::getEnabled() {
+ return (impl_->enabled_);
+}
+
// Return the number of entries in the cache
int
HotCache::getCount() const {
Modified: branches/trac192/src/lib/datasrc/cache.h
==============================================================================
--- branches/trac192/src/lib/datasrc/cache.h (original)
+++ branches/trac192/src/lib/datasrc/cache.h Thu Jun 24 17:41:46 2010
@@ -62,10 +62,12 @@
/// and analysis will be needed for this.
///
/// The cache may be configured with a number of available slots for
-/// for entries. The current default is unlimited (see SLOTS_ below),
-/// but if set to a nonzero value, then no more than the specified number
+/// for entries. When set to a nonzero value, no more than that number
/// of entries can exist in the cache. If more entries are inserted,
-/// old entries will be dropped in "least recently used" order.
+/// old entries will be dropped in "least recently used" order. If
+/// set to zero, the cache size is unlimited. The current default is
+/// based on one thousand queries per second, times the number of seconds
+/// in the cache lifespan: 30,000 slots.
///
/// Notes to developers: The current implementation of HotCache uses
/// a std::map (keyed by isc::dns::Question) to locate nodes, so access
@@ -87,7 +89,7 @@
static const int LIFESPAN_ = 30;
/// \brief Default number of slots in cache
- static const int SLOTS_ = 0;
+ static const int SLOTS_ = 1000 * LIFESPAN_;
//@}
/// \name Constructors, Assignment Operator and Destructor.
@@ -194,6 +196,12 @@
/// \brief Returns the number of slots in the cache.
int getSlots() const;
+ /// \brief Enable or disable the cache
+ void setEnabled(bool e);
+
+ /// \brief Indicate whether the cache is enabled
+ bool getEnabled();
+
/// \brief Returns the number of nodes currently stored in the cache.
///
/// Note that this doesn't indicate how many nodes are still valid;
@@ -202,7 +210,11 @@
//@}
private:
+ /// \brief Hidden implementation details
HotCacheImpl* impl_;
+
+ /// \brief True if cache is enabled (set to true by default)
+ bool enabled_;
};
}
Modified: branches/trac192/src/lib/datasrc/data_source.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/data_source.cc (original)
+++ branches/trac192/src/lib/datasrc/data_source.cc Thu Jun 24 17:41:46 2010
@@ -54,7 +54,39 @@
typedef boost::shared_ptr<const Nsec3Param> ConstNsec3ParamPtr;
-namespace {
+class ZoneInfo {
+public:
+ ZoneInfo(DataSrc* ts,
+ const isc::dns::Name& n,
+ const isc::dns::RRClass& c,
+ const isc::dns::RRType& t = isc::dns::RRType::ANY()) :
+ top_source_(ts),
+ dsm_(((t == RRType::DS() && n.getLabelCount() != 1)
+ ? n.split(1, n.getLabelCount() - 1)
+ : n),
+ c, t)
+ {}
+
+ Name* getEnclosingZone() {
+ if (dsm_.getEnclosingZone() == NULL) {
+ top_source_->findClosestEnclosure(dsm_);
+ }
+ return (dsm_.getEnclosingZone());
+ }
+
+ const DataSrc* getDataSource() {
+ if (dsm_.getDataSource() == NULL) {
+ top_source_->findClosestEnclosure(dsm_);
+ }
+ return (dsm_.getDataSource());
+ }
+
+private:
+ const DataSrc* top_source_;
+ DataSrcMatch dsm_;
+};
+
+
// Add a task to the query task queue to look up additional data
// (i.e., address records for the names included in NS or MX records)
void
@@ -138,11 +170,10 @@
QueryTask::FOLLOWCNAME)));
}
-// Check the cache for data which can answer the current
-// query task.
+// Check the cache for data which can answer the current query task.
bool
checkCache(QueryTask& task, RRsetList& target) {
- HotCache& cache = task.q.cache();
+ HotCache& cache = task.q.getCache();
RRsetList rrsets;
RRsetPtr rrset;
int count = 0;
@@ -283,7 +314,7 @@
// Carry out the query specified in a QueryTask object
DataSrc::Result
doQueryTask(QueryTask& task, ZoneInfo& zoneinfo, RRsetList& target) {
- HotCache& cache = task.q.cache();
+ HotCache& cache = task.q.getCache();
RRsetPtr rrset;
// First, check the cache for matching data
@@ -294,8 +325,8 @@
// Requested data weren't in the cache (or were, but had expired),
// so now we proceed with the low-level data source lookup, and cache
// whatever we find.
- const DataSrc* ds = zoneinfo.datasrc();
- Name* zonename = zoneinfo.name();
+ const DataSrc* ds = zoneinfo.getDataSource();
+ Name* zonename = zoneinfo.getEnclosingZone();
if (ds == NULL) {
task.flags |= DataSrc::NO_SUCH_ZONE;
@@ -474,7 +505,7 @@
// referrals.
inline bool
hasDelegation(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo) {
- Name* zonename = zoneinfo.name();
+ Name* zonename = zoneinfo.getEnclosingZone();
if (zonename == NULL) {
if (task->state == QueryTask::GETANSWER) {
q.message().setRcode(Rcode::REFUSED());
@@ -542,7 +573,7 @@
Message& m = q.message();
RRsetList soa;
- Name* zonename = zoneinfo.name();
+ Name* zonename = zoneinfo.getEnclosingZone();
QueryTask newtask(q, *zonename, RRType::SOA(), QueryTask::SIMPLE_QUERY);
RETERR(doQueryTask(newtask, zoneinfo, soa));
if (newtask.flags != 0) {
@@ -571,8 +602,8 @@
inline DataSrc::Result
getNsec3(Query& q, ZoneInfo& zoneinfo, string& hash, RRsetPtr& target) {
- const DataSrc* ds = zoneinfo.datasrc();
- Name* zonename = zoneinfo.name();
+ const DataSrc* ds = zoneinfo.getDataSource();
+ Name* zonename = zoneinfo.getEnclosingZone();
if (ds == NULL) {
q.message().setRcode(Rcode::SERVFAIL());
@@ -591,7 +622,7 @@
DataSrc::Result result;
RRsetList nsec3param;
- Name* zonename = zoneinfo.name();
+ Name* zonename = zoneinfo.getEnclosingZone();
QueryTask newtask(q, *zonename, RRType::NSEC3PARAM(),
QueryTask::SIMPLE_QUERY);
result = doQueryTask(newtask, zoneinfo, nsec3param);
@@ -623,7 +654,7 @@
inline DataSrc::Result
proveNX(Query& q, QueryTaskPtr task, ZoneInfo& zoneinfo, const bool wildcard) {
Message& m = q.message();
- Name* zonename = zoneinfo.name();
+ Name* zonename = zoneinfo.getEnclosingZone();
ConstNsec3ParamPtr nsec3 = getNsec3Param(q, zoneinfo);
if (nsec3 != NULL) {
@@ -676,7 +707,7 @@
} else {
Name nsecname(task->qname);
if ((task->flags & DataSrc::NAME_NOT_FOUND) != 0 || wildcard) {
- const DataSrc* ds = zoneinfo.datasrc();
+ const DataSrc* ds = zoneinfo.getDataSource();
if (ds == NULL) {
m.setRcode(Rcode::SERVFAIL());
return (DataSrc::ERROR);
@@ -717,7 +748,7 @@
return (DataSrc::SUCCESS);
}
- Name* zonename = zoneinfo.name();
+ Name* zonename = zoneinfo.getEnclosingZone();
const int nlen = task->qname.getLabelCount();
const int diff = nlen - zonename->getLabelCount();
if (diff < 1) {
@@ -792,7 +823,6 @@
return (DataSrc::SUCCESS);
}
-} // end of anonymous namespace
//
// doQuery: Processes a query.
@@ -859,7 +889,7 @@
// Query found a referral; let's find out if that was expected--
// i.e., if an NS was at the zone apex, or if we were querying
// specifically for, and found, a DS, NSEC, or DNAME record.
- Name* zonename = zoneinfo.name();
+ Name* zonename = zoneinfo.getEnclosingZone();
if ((task->flags & REFERRAL) != 0 &&
(zonename->getLabelCount() == task->qname.getLabelCount() ||
((task->qtype == RRType::NSEC() ||
@@ -988,7 +1018,7 @@
Name nsecname(task->qname);
if ((task->flags & NAME_NOT_FOUND) != 0) {
- const DataSrc* ds = zoneinfo.datasrc();
+ const DataSrc* ds = zoneinfo.getDataSource();
ds->findPreviousName(task->qname, nsecname, zonename);
}
@@ -1118,23 +1148,23 @@
}
void
-MetaDataSrc::findClosestEnclosure(ZoneInfo& zoneinfo) const {
- if (getClass() != zoneinfo.qclass() &&
- getClass() != RRClass::ANY() && zoneinfo.qclass() != RRClass::ANY()) {
+MetaDataSrc::findClosestEnclosure(DataSrcMatch& match) const {
+ if (getClass() != match.getClass() &&
+ getClass() != RRClass::ANY() && match.getClass() != RRClass::ANY()) {
return;
}
BOOST_FOREACH (ConstDataSrcPtr data_src, data_sources) {
- data_src->findClosestEnclosure(zoneinfo);
- }
-}
-
-ZoneInfo::~ZoneInfo() {
+ data_src->findClosestEnclosure(match);
+ }
+}
+
+DataSrcMatch::~DataSrcMatch() {
delete closest_name_;
}
void
-ZoneInfo::update(const DataSrc& new_source, const Name& container) {
+DataSrcMatch::update(const DataSrc& new_source, const Name& container) {
if (closest_name_ == NULL) {
closest_name_ = new Name(container);
best_source_ = &new_source;
Modified: branches/trac192/src/lib/datasrc/data_source.h
==============================================================================
--- branches/trac192/src/lib/datasrc/data_source.h (original)
+++ branches/trac192/src/lib/datasrc/data_source.h Thu Jun 24 17:41:46 2010
@@ -41,7 +41,7 @@
namespace datasrc {
-class ZoneInfo;
+class DataSrcMatch;
class Query;
class DataSrc;
@@ -111,7 +111,7 @@
// 'Medium-level' methods. This will be implemented by the general
// DataSrc class but MAY be overwritten by subclasses.
- virtual void findClosestEnclosure(ZoneInfo& zoneinfo) const = 0;
+ virtual void findClosestEnclosure(DataSrcMatch& match) const = 0;
// Optional 'low-level' methods. These will have stub implementations
// in the general DataSrc class but MAY be overwritten by subclasses
@@ -181,7 +181,7 @@
virtual void doQuery(Query& q);
- virtual void findClosestEnclosure(ZoneInfo& zoneinfo) const = 0;
+ virtual void findClosestEnclosure(DataSrcMatch& match) const = 0;
const isc::dns::RRClass& getClass() const { return rrclass; }
void setClass(isc::dns::RRClass& c) { rrclass = c; }
@@ -250,7 +250,7 @@
void removeDataSrc(ConstDataSrcPtr data_src);
size_t dataSrcCount() { return data_sources.size(); };
- void findClosestEnclosure(ZoneInfo& zoneinfo) const;
+ void findClosestEnclosure(DataSrcMatch& match) const;
// Actual queries for data should not be sent to a MetaDataSrc object,
// so we return NOT_IMPLEMENTED if we receive any.
@@ -299,15 +299,15 @@
/// \brief Information about the zone for a given query
///
-/// The \c ZoneInfo object is created with the query name and query
+/// The \c DataSrcMatch object is created with the query name and query
/// class (and optionally, query type) for an ongoing query, and the
/// top-level data source. When it becomes necessary to find the
/// closest enclosing zone matching the query and the concrete data
-/// source which is authoritative for that zone, then the \c ZoneInfo
+/// source which is authoritative for that zone, then the \c DataSrcMatch
/// object will search through data sources to make that determination.
/// (This is done only when needed, so that the search can be avoided
/// when the query can be answered from the cache.)
-class ZoneInfo {
+class DataSrcMatch {
///
/// \name Constructors, Assignment Operator and Destructor.
///
@@ -315,74 +315,48 @@
/// defined as private.
//@{
private:
- ZoneInfo(const ZoneInfo& source);
- ZoneInfo& operator=(const ZoneInfo& source);
-public:
- /// \brief Constructor suitable for most typical queries
- ///
- /// \param ds Pointer to the top-level data source
- /// \param qname Query name
- /// \param qclass Query class
- ZoneInfo(const DataSrc* ds, const isc::dns::Name& qname,
- const isc::dns::RRClass& qclass) :
- top_source_(ds), closest_name_(NULL), best_source_(NULL),
- qname_(qname), qclass_(qclass), qtype_(isc::dns::RRType::ANY()) {}
-
- /// \brief Constructor for queries that specify RRtype
+ DataSrcMatch(const DataSrcMatch& source);
+ DataSrcMatch& operator=(const DataSrcMatch& source);
+public:
+ /// \brief Constructor
///
/// Queries for the DS rrtype must be sent to the parent zone, not
/// to the zone matching the query name. Therefore, if a query type of
/// DS is specified here, the query name is altered, so that when
/// we search for the closest enclosing zone, we'll find the right one.
///
+ /// If no type is specified, a default of ANY() is used.
+ ///
/// \param ds Pointer to the top-level data source
/// \param qname Query name
/// \param qclass Query class
/// \param qtype Query type
- ZoneInfo(const DataSrc* ds, const isc::dns::Name& qname,
- const isc::dns::RRClass& qclass, const isc::dns::RRType& qtype) :
- top_source_(ds), closest_name_(NULL), best_source_(NULL),
- qname_(qname.getLabelCount() == 1 || qtype != isc::dns::RRType::DS()
- ? qname
- : qname.split(1, qname.getLabelCount() - 1)),
- qclass_(qclass), qtype_(qtype)
+ DataSrcMatch(const isc::dns::Name& qname,
+ const isc::dns::RRClass& qclass,
+ const isc::dns::RRType& qtype = isc::dns::RRType::ANY()) :
+ closest_name_(NULL), best_source_(NULL),
+ qname_(qname), qclass_(qclass), qtype_(qtype)
{}
- ~ZoneInfo();
+ ~DataSrcMatch();
//@}
/// \name Getter and Setter Methods
//@{
/// \brief Returns the query name.
- const isc::dns::Name& qname() const { return (qname_); }
+ const isc::dns::Name& getName() const { return (qname_); }
/// \brief Returns the query class.
- const isc::dns::RRClass& qclass() const { return (qclass_); }
-
- /// \brief Returns the enclosing zone name for the query.
+ const isc::dns::RRClass& getClass() const { return (qclass_); }
+
+ /// \brief Returns the best enclosing zone name found for the query so far.
///
- /// If the enclosing zone has not yet been found, search the
- /// data source for it.
- ///
- /// \return A pointer to the zone apex \c Name
- isc::dns::Name* name() {
- if (!closest_name_) {
- top_source_->findClosestEnclosure(*this);
- }
- return (closest_name_);
- }
-
- /// \brief Returns the concrete data source serving the zone.
+ /// \return A pointer to the zone apex \c Name, NULL if none found yet.
+ isc::dns::Name* getEnclosingZone() { return (closest_name_); }
+
+ /// \brief Returns the best data source found for the query so far.
///
- /// If the concrete data source has not yet been found, search
- /// down from the top-level data source for it.
- ///
- /// \return A pointer to the concrete data source.
- const DataSrc* datasrc() {
- if (!best_source_) {
- top_source_->findClosestEnclosure(*this);
- }
- return (best_source_);
- }
+ /// \return A pointer to a concrete data source, NULL if none found yet.
+ const DataSrc* getDataSource() { return (best_source_); }
//@}
/// \brief Called by a concrete data source's
@@ -391,7 +365,6 @@
void update(const DataSrc& new_source, const isc::dns::Name& container);
private:
- const DataSrc* top_source_;
isc::dns::Name* closest_name_;
const DataSrc* best_source_;
const isc::dns::Name qname_;
Modified: branches/trac192/src/lib/datasrc/query.h
==============================================================================
--- branches/trac192/src/lib/datasrc/query.h (original)
+++ branches/trac192/src/lib/datasrc/query.h Thu Jun 24 17:41:46 2010
@@ -220,7 +220,7 @@
// \brief The query cache. This is a static member of class \c Query;
// the same cache will be used by all instances.
- HotCache& cache() const { return (*cache_); }
+ HotCache& getCache() const { return (*cache_); }
private:
Status status_;
Modified: branches/trac192/src/lib/datasrc/sqlite3_datasrc.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/sqlite3_datasrc.cc (original)
+++ branches/trac192/src/lib/datasrc/sqlite3_datasrc.cc Thu Jun 24 17:41:46 2010
@@ -344,22 +344,19 @@
}
void
-Sqlite3DataSrc::findClosestEnclosure(ZoneInfo& zoneinfo) const {
- if (zoneinfo.qclass() != getClass() &&
- zoneinfo.qclass() != RRClass::ANY())
- {
+Sqlite3DataSrc::findClosestEnclosure(DataSrcMatch& match) const {
+ if (match.getClass() != getClass() && match.getClass() != RRClass::ANY()) {
return;
}
unsigned int position;
- if (findClosest(zoneinfo.qname(), &position) == -1) {
+ if (findClosest(match.getName(), &position) == -1) {
return;
}
- zoneinfo.update(*this,
- zoneinfo.qname().split(position,
- zoneinfo.qname().getLabelCount() -
- position));
+ match.update(*this, match.getName().split(position,
+ match.getName().getLabelCount() -
+ position));
}
DataSrc::Result
Modified: branches/trac192/src/lib/datasrc/sqlite3_datasrc.h
==============================================================================
--- branches/trac192/src/lib/datasrc/sqlite3_datasrc.h (original)
+++ branches/trac192/src/lib/datasrc/sqlite3_datasrc.h Thu Jun 24 17:41:46 2010
@@ -58,7 +58,7 @@
~Sqlite3DataSrc();
//@}
- void findClosestEnclosure(ZoneInfo& zoneinfo) const;
+ void findClosestEnclosure(DataSrcMatch& match) const;
Result findRRset(const isc::dns::Name& qname,
const isc::dns::RRClass& qclass,
Modified: branches/trac192/src/lib/datasrc/static_datasrc.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/static_datasrc.cc (original)
+++ branches/trac192/src/lib/datasrc/static_datasrc.cc Thu Jun 24 17:41:46 2010
@@ -129,21 +129,20 @@
}
void
-StaticDataSrc::findClosestEnclosure(ZoneInfo& zoneinfo) const {
- const Name& qname = zoneinfo.qname();
-
- if (zoneinfo.qclass() != getClass() &&
- zoneinfo.qclass() != RRClass::ANY()) {
+StaticDataSrc::findClosestEnclosure(DataSrcMatch& match) const {
+ const Name& qname = match.getName();
+
+ if (match.getClass() != getClass() && match.getClass() != RRClass::ANY()) {
return;
}
if (isSubdomain(qname, impl_->version_name)) {
- zoneinfo.update(*this, impl_->version_name);
+ match.update(*this, impl_->version_name);
return;
}
if (isSubdomain(qname, impl_->authors_name)) {
- zoneinfo.update(*this, impl_->authors_name);
+ match.update(*this, impl_->authors_name);
return;
}
}
Modified: branches/trac192/src/lib/datasrc/static_datasrc.h
==============================================================================
--- branches/trac192/src/lib/datasrc/static_datasrc.h (original)
+++ branches/trac192/src/lib/datasrc/static_datasrc.h Thu Jun 24 17:41:46 2010
@@ -56,7 +56,7 @@
~StaticDataSrc();
//@}
- void findClosestEnclosure(ZoneInfo& zoneinfo) const;
+ void findClosestEnclosure(DataSrcMatch& match) const;
Result findRRset(const isc::dns::Name& qname,
const isc::dns::RRClass& qclass,
Modified: branches/trac192/src/lib/datasrc/tests/cache_unittest.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/tests/cache_unittest.cc (original)
+++ branches/trac192/src/lib/datasrc/tests/cache_unittest.cc Thu Jun 24 17:41:46 2010
@@ -284,4 +284,29 @@
EXPECT_EQ(1, cache.getCount());
}
-}
+TEST_F(CacheTest, setEnabled) {
+ cache.setEnabled(false);
+ EXPECT_FALSE(cache.getEnabled());
+ cache.setEnabled(true);
+ EXPECT_TRUE(cache.getEnabled());
+}
+
+TEST_F(CacheTest, disabled) {
+ bool hit;
+ RRsetPtr r;
+ uint32_t f;
+
+ cache.setEnabled(false);
+ hit = cache.retrieve(test_name, RRClass::IN(), RRType::A(), r, f);
+ EXPECT_FALSE(hit);
+
+ cache.setEnabled(true);
+ hit = cache.retrieve(test_name, RRClass::IN(), RRType::A(), r, f);
+ EXPECT_TRUE(hit);
+
+ EXPECT_EQ(test_name, r->getName());
+ EXPECT_EQ(RRClass::IN(), r->getClass());
+ EXPECT_EQ(RRType::A(), r->getType());
+}
+
+}
Modified: branches/trac192/src/lib/datasrc/tests/datasrc_unittest.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/tests/datasrc_unittest.cc (original)
+++ branches/trac192/src/lib/datasrc/tests/datasrc_unittest.cc Thu Jun 24 17:41:46 2010
@@ -868,25 +868,28 @@
EXPECT_EQ(0, ds.dataSrcCount());
}
-TEST_F(DataSrcTest, ZoneInfo) {
+TEST_F(DataSrcTest, DataSrcMatch) {
MetaDataSrc ds;
ConstDataSrcPtr tsp = ConstDataSrcPtr(new TestDataSrc);
ds.addDataSrc(tsp);
- ZoneInfo zoneinfo(&ds, Name("very.very.long.example.com"), RRClass::IN());
- EXPECT_EQ(Name("example.com"), *zoneinfo.name());
- EXPECT_EQ(tsp.get(), zoneinfo.datasrc());
-}
-
-TEST_F(DataSrcTest, ZoneInfoByType) {
+ DataSrcMatch match(Name("very.very.long.example.com"), RRClass::IN());
+ ds.findClosestEnclosure(match);
+ EXPECT_EQ(Name("example.com"), *match.getEnclosingZone());
+ EXPECT_EQ(tsp.get(), match.getDataSource());
+}
+
+TEST_F(DataSrcTest, DISABLED_DataSrcMatchByType) {
MetaDataSrc ds;
ConstDataSrcPtr tsp = ConstDataSrcPtr(new TestDataSrc);
ds.addDataSrc(tsp);
- ZoneInfo zoneinfo1(&ds, Name("sql1.example.com"), RRClass::IN(),
- RRType::NS());
- EXPECT_EQ(Name("sql1.example.com"), *zoneinfo1.name());
- ZoneInfo zoneinfo2(&ds, Name("sql1.example.com"), RRClass::IN(),
- RRType::DS());
- EXPECT_EQ(Name("example.com"), *zoneinfo2.name());
+
+ DataSrcMatch match1(Name("sql1.example.com"), RRClass::IN(), RRType::NS());
+ ds.findClosestEnclosure(match1);
+ EXPECT_EQ(Name("sql1.example.com"), *match1.getEnclosingZone());
+
+ DataSrcMatch match2(Name("sql1.example.com"), RRClass::IN(), RRType::DS());
+ ds.findClosestEnclosure(match2);
+ EXPECT_EQ(Name("example.com"), *match2.getEnclosingZone());
}
#if 0 // currently fails
Modified: branches/trac192/src/lib/datasrc/tests/sqlite3_unittest.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/tests/sqlite3_unittest.cc (original)
+++ branches/trac192/src/lib/datasrc/tests/sqlite3_unittest.cc Thu Jun 24 17:41:46 2010
@@ -374,9 +374,10 @@
EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_EXAMPLE2));
- ZoneInfo zoneinfo(&data_source, www_name, rrclass);
- EXPECT_EQ(NULL, zoneinfo.name());
- EXPECT_EQ(NULL, zoneinfo.datasrc());
+ DataSrcMatch match(www_name, rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(NULL, match.getEnclosingZone());
+ EXPECT_EQ(NULL, match.getDataSource());
}
TEST_F(Sqlite3DataSourceTest, openFail) {
@@ -412,46 +413,52 @@
}
TEST_F(Sqlite3DataSourceTest, findClosestEnclosure) {
- ZoneInfo zoneinfo(&data_source, www_name, rrclass);
- EXPECT_EQ(zone_name, *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(www_name, rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(zone_name, *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
TEST_F(Sqlite3DataSourceTest, findClosestEnclosureMatchRoot) {
EXPECT_EQ(DataSrc::SUCCESS, data_source.close());
EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_EXAMPLE_ROOT));
- ZoneInfo zoneinfo(&data_source, Name("org."), rrclass);
- EXPECT_EQ(Name("."), *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(Name("org."), rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(Name("."), *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
TEST_F(Sqlite3DataSourceTest, findClosestEnclosureAtDelegation) {
// The search name exists both in the parent and child zones, but
// child has a better match.
- ZoneInfo zoneinfo(&data_source, child_name, rrclass);
- EXPECT_EQ(child_name, *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(child_name, rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(child_name, *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
TEST_F(Sqlite3DataSourceTest, findClosestEnclosureNoMatch) {
- ZoneInfo zoneinfo(&data_source, nomatch_name, rrclass);
- EXPECT_EQ(NULL, zoneinfo.name());
- EXPECT_EQ(NULL, zoneinfo.datasrc());
+ DataSrcMatch match(nomatch_name, rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(NULL, match.getEnclosingZone());
+ EXPECT_EQ(NULL, match.getDataSource());
}
TEST_F(Sqlite3DataSourceTest, findClosestClassMismatch) {
- ZoneInfo zoneinfo(&data_source, www_name, rrclass_notmatch);
- EXPECT_EQ(NULL, zoneinfo.name());
- EXPECT_EQ(NULL, zoneinfo.datasrc());
+ DataSrcMatch match(www_name, rrclass_notmatch);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(NULL, match.getEnclosingZone());
+ EXPECT_EQ(NULL, match.getDataSource());
}
// If the query class is ANY, the result should be the same as the case where
// the class exactly matches.
TEST_F(Sqlite3DataSourceTest, findClosestClassAny) {
- ZoneInfo zoneinfo(&data_source, www_name, RRClass::ANY());
- EXPECT_EQ(zone_name, *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(www_name, RRClass::ANY());
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(zone_name, *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
TEST_F(Sqlite3DataSourceTest, findRRsetNormal) {
Modified: branches/trac192/src/lib/datasrc/tests/static_unittest.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/tests/static_unittest.cc (original)
+++ branches/trac192/src/lib/datasrc/tests/static_unittest.cc Thu Jun 24 17:41:46 2010
@@ -196,47 +196,54 @@
}
TEST_F(StaticDataSourceTest, findClosestEnclosureForVersion) {
- ZoneInfo zoneinfo(&data_source, version_name, rrclass);
- EXPECT_EQ(version_name, *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(version_name, rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(version_name, *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
// Class Any query should result in the same answer.
TEST_F(StaticDataSourceTest, findClosestEnclosureForVersionClassAny) {
- ZoneInfo zoneinfo(&data_source, version_name, RRClass::ANY());
- EXPECT_EQ(version_name, *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(version_name, RRClass::ANY());
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(version_name, *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
// If class doesn't match the lookup should fail.
TEST_F(StaticDataSourceTest, findClosestEnclosureForVersionClassMismatch) {
- ZoneInfo zoneinfo(&data_source, version_name, RRClass::IN());
- EXPECT_EQ(NULL, zoneinfo.name());
- EXPECT_EQ(NULL, zoneinfo.datasrc());
+ DataSrcMatch match(version_name, RRClass::IN());
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(NULL, match.getEnclosingZone());
+ EXPECT_EQ(NULL, match.getDataSource());
}
TEST_F(StaticDataSourceTest, findClosestEnclosureForVersionPartial) {
- ZoneInfo zoneinfo(&data_source, Name("foo").concatenate(version_name), rrclass);
- EXPECT_EQ(version_name, *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(Name("foo").concatenate(version_name), rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(version_name, *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
TEST_F(StaticDataSourceTest, findClosestEnclosureForAuthors) {
- ZoneInfo zoneinfo(&data_source, authors_name, rrclass);
- EXPECT_EQ(authors_name, *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(authors_name, rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(authors_name, *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
TEST_F(StaticDataSourceTest, findClosestEnclosureForAuthorsPartial) {
- ZoneInfo zoneinfo(&data_source, Name("foo").concatenate(authors_name), rrclass);
- EXPECT_EQ(authors_name, *zoneinfo.name());
- EXPECT_EQ(&data_source, zoneinfo.datasrc());
+ DataSrcMatch match(Name("foo").concatenate(authors_name), rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(authors_name, *match.getEnclosingZone());
+ EXPECT_EQ(&data_source, match.getDataSource());
}
TEST_F(StaticDataSourceTest, findClosestEnclosureNoMatch) {
- ZoneInfo zoneinfo(&data_source, nomatch_name, rrclass);
- EXPECT_EQ(NULL, zoneinfo.name());
- EXPECT_EQ(NULL, zoneinfo.datasrc());
+ DataSrcMatch match(nomatch_name, rrclass);
+ data_source.findClosestEnclosure(match);
+ EXPECT_EQ(NULL, match.getEnclosingZone());
+ EXPECT_EQ(NULL, match.getDataSource());
}
TEST_F(StaticDataSourceTest, findRRsetVersionTXT) {
Modified: branches/trac192/src/lib/datasrc/tests/test_datasrc.cc
==============================================================================
--- branches/trac192/src/lib/datasrc/tests/test_datasrc.cc (original)
+++ branches/trac192/src/lib/datasrc/tests/test_datasrc.cc Thu Jun 24 17:41:46 2010
@@ -481,26 +481,25 @@
}
void
-TestDataSrc::findClosestEnclosure(ZoneInfo& zoneinfo) const {
- const Name& qname = zoneinfo.qname();
+TestDataSrc::findClosestEnclosure(DataSrcMatch& match) const {
+ const Name& qname = match.getName();
NameComparisonResult::NameRelation cmp;
- if (zoneinfo.qclass() != getClass() &&
- zoneinfo.qclass() != RRClass::ANY()) {
+ if (match.getClass() != getClass() && match.getClass() != RRClass::ANY()) {
return;
}
cmp = qname.compare(sql1).getRelation();
if (cmp == NameComparisonResult::EQUAL ||
cmp == NameComparisonResult::SUBDOMAIN) {
- zoneinfo.update(*this, sql1);
+ match.update(*this, sql1);
return;
}
cmp = qname.compare(example).getRelation();
if (cmp == NameComparisonResult::EQUAL ||
cmp == NameComparisonResult::SUBDOMAIN) {
- zoneinfo.update(*this, example);
+ match.update(*this, example);
return;
}
Modified: branches/trac192/src/lib/datasrc/tests/test_datasrc.h
==============================================================================
--- branches/trac192/src/lib/datasrc/tests/test_datasrc.h (original)
+++ branches/trac192/src/lib/datasrc/tests/test_datasrc.h Thu Jun 24 17:41:46 2010
@@ -48,7 +48,7 @@
~TestDataSrc() {}
//@}
- void findClosestEnclosure(ZoneInfo& zoneinfo) const;
+ void findClosestEnclosure(DataSrcMatch& match) const;
Result findRRset(const isc::dns::Name& qname,
const isc::dns::RRClass& qclass,
More information about the bind10-changes
mailing list