Browse Source

[2834] return null functor from getLoadAction if not configured for cache.

this would be more convenient in actual usage.
JINMEI Tatuya 12 years ago
parent
commit
a5ec1487b1
2 changed files with 6 additions and 7 deletions
  1. 3 2
      src/lib/datasrc/cache_config.cc
  2. 3 5
      src/lib/datasrc/tests/cache_config_unittest.cc

+ 3 - 2
src/lib/datasrc/cache_config.cc

@@ -161,11 +161,12 @@ memory::LoadAction
 CacheConfig::getLoadAction(const dns::RRClass& rrclass,
                            const dns::Name& zone_name) const
 {
+    // First, check if the specified zone is configured to be cached.
     Zones::const_iterator found = zone_config_.find(zone_name);
     if (found == zone_config_.end()) {
-        isc_throw(Unexpected, "zone not found for getting LoadAction: "
-                  << zone_name << "/" << rrclass);
+        return (memory::LoadAction());
     }
+
     if (!found->second.empty()) {
         // This is "MasterFiles" data source.
         return (boost::bind(loadZoneDataFromFile, _1, rrclass, zone_name,

+ 3 - 5
src/lib/datasrc/tests/cache_config_unittest.cc

@@ -170,9 +170,8 @@ TEST_F(CacheConfigTest, getLoadActionWithMasterFiles) {
     ZoneData::destroy(msgmt_, zone_data, RRClass::IN());
 
     // If the specified zone name is not configured to be cached,
-    // getLoadAction should result in exception.
-    EXPECT_THROW(cache_conf.getLoadAction(RRClass::IN(), Name("example.com")),
-                 isc::Unexpected);
+    // getLoadAction returns empty (false) functor.
+    EXPECT_FALSE(cache_conf.getLoadAction(RRClass::IN(), Name("example.com")));
 }
 
 TEST_F(CacheConfigTest, constructWithMock) {
@@ -275,8 +274,7 @@ TEST_F(CacheConfigTest, getLoadActionWithMock) {
     ZoneData::destroy(msgmt_, zone_data, RRClass::IN());
 
     // Zone not configured for the cache
-    EXPECT_THROW(cache_conf.getLoadAction(RRClass::IN(), Name("example.com")),
-                 isc::Unexpected);
+    EXPECT_FALSE(cache_conf.getLoadAction(RRClass::IN(), Name("example.com")));
 
     // Zone configured for the cache but doesn't exist in the underling data
     // source.