Browse Source

[2378] Fixes of ZoneLoader and tests

After the rebase on top of working 2377. The most significant - don't
access updater if it doesn't exist.
Michal 'vorner' Vaner 12 years ago
parent
commit
01461d51fa

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

@@ -288,7 +288,7 @@ TEST_F(ZoneLoaderTest, classMismatch) {
 // Load an unsigned zone, all at once
 TEST_F(ZoneLoaderTest, loadUnsigned) {
     ZoneLoader loader(destination_client_, Name::ROOT_NAME(),
-                      TEST_DATA_DIR "root.zone");
+                      TEST_DATA_DIR "/root.zone");
     // It gets the updater directly in the constructor
     ASSERT_EQ(1, destination_client_.provided_updaters_.size());
     EXPECT_EQ(Name::ROOT_NAME(), destination_client_.provided_updaters_[0]);
@@ -377,8 +377,10 @@ TEST_F(ZoneLoaderTest, loadSigned) {
 
 // Test it throws when there's no such file
 TEST_F(ZoneLoaderTest, loadNoSuchFile) {
-    EXPECT_THROW(ZoneLoader(destination_client_, Name::ROOT_NAME(),
-                            "This file does not exist"), MasterFileError);
+    ZoneLoader loader(destination_client_, Name::ROOT_NAME(),
+                      "This file does not exist");
+    EXPECT_THROW(loader.load(), MasterFileError);
+    EXPECT_FALSE(destination_client_.commit_called_);
 }
 
 // And it also throws when there's a syntax error in the master file

+ 14 - 9
src/lib/datasrc/zone_loader.cc

@@ -59,18 +59,23 @@ ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
 ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
                        const char* filename) :
     updater_(destination.getUpdater(zone_name, true, false)),
-    loader_(new MasterLoader(filename, zone_name,
-                             // TODO: Maybe we should have getClass() on the
-                             // data source?
-                             updater_->getFinder().getClass(),
-                             createMasterLoaderCallbacks(zone_name,
-                                             updater_->getFinder().getClass(),
-                                             &loaded_ok_),
-                             createMasterLoaderAddCallback(*updater_))),
     complete_(false),
     loaded_ok_(true)
 {
-
+    if (updater_ == ZoneUpdaterPtr()) {
+        isc_throw(DataSourceError, "Zone " << zone_name << " not found in "
+                  "destination data source, can't fill it with data");
+    } else {
+        loader_.reset(new
+                      MasterLoader(filename, zone_name,
+                                   // TODO: Maybe we should have getClass()
+                                   // on the data source?
+                                   updater_->getFinder().getClass(),
+                                   createMasterLoaderCallbacks(zone_name,
+                                       updater_->getFinder().getClass(),
+                                       &loaded_ok_),
+                                   createMasterLoaderAddCallback(*updater_)));
+    }
 }
 
 namespace {

+ 1 - 1
src/lib/datasrc/zone_loader.h

@@ -140,7 +140,7 @@ private:
     /// \brief The destination zone updater
     const ZoneUpdaterPtr updater_;
     /// \brief The master loader (for the loader mode)
-    const boost::scoped_ptr<isc::dns::MasterLoader> loader_;
+    boost::scoped_ptr<isc::dns::MasterLoader> loader_;
     /// \brief Indicator if loading was completed
     bool complete_;
     /// \brief Was the loading successful?