Browse Source

[1332] updated the 'no such zone' case; return an error code with null pointer
instead of exception. Also refactored the test code a bit to minimize
duplicate.

JINMEI Tatuya 13 years ago
parent
commit
dca136175c
2 changed files with 36 additions and 32 deletions
  1. 11 10
      src/lib/datasrc/database.cc
  2. 25 22
      src/lib/datasrc/tests/database_unittest.cc

+ 11 - 10
src/lib/datasrc/database.cc

@@ -1100,19 +1100,12 @@ private:
     // A shortcut typedef to keep the code concise.
     typedef DatabaseAccessor Accessor;
 public:
-    DatabaseJournalReader(shared_ptr<Accessor> accessor, const Name& zone,
+    DatabaseJournalReader(shared_ptr<Accessor> accessor, int zone_id,
                           const RRClass& rrclass, uint32_t begin,
                           uint32_t end) :
         accessor_(accessor), rrclass_(rrclass)
     {
-        const pair<bool, int> zoneinfo(accessor_->getZone(zone.toText()));
-        if (!zoneinfo.first) {
-            // No such zone, can't continue
-            isc_throw(DataSourceError, "Zone " << zone << "/"
-                      << rrclass << " doesn't exist in database: " <<
-                      accessor_->getDBName());
-        }
-        context_ = accessor_->getDiffs(zoneinfo.second, begin, end);
+        context_ = accessor_->getDiffs(zone_id, begin, end);
     }
     virtual ~DatabaseJournalReader() {}
     virtual ConstRRsetPtr getNextDiff() {
@@ -1143,10 +1136,18 @@ DatabaseClient::getJournalReader(const isc::dns::Name& zone,
                                  uint32_t begin_serial,
                                  uint32_t end_serial) const
 {
+    const pair<bool, int> zoneinfo(accessor_->getZone(zone.toText()));
+    if (!zoneinfo.first) {
+        return (pair<ZoneJournalReader::Result, ZoneJournalReaderPtr>(
+                    ZoneJournalReader::NO_SUCH_ZONE,
+                    ZoneJournalReaderPtr()));
+    }
+
     try {
         const pair<ZoneJournalReader::Result, ZoneJournalReaderPtr> ret(
             ZoneJournalReader::SUCCESS,
-            ZoneJournalReaderPtr(new DatabaseJournalReader(accessor_, zone,
+            ZoneJournalReaderPtr(new DatabaseJournalReader(accessor_,
+                                                           zoneinfo.second,
                                                            rrclass_,
                                                            begin_serial,
                                                            end_serial)));

+ 25 - 22
src/lib/datasrc/tests/database_unittest.cc

@@ -3076,19 +3076,28 @@ TEST_F(MockDatabaseClientTest, journalException) {
 // Tests for the ZoneJournalReader
 //
 
-TYPED_TEST(DatabaseClientTest, journalReader) {
-    // Check a simple, normal scenario: making an update from one SOA to
-    // another, and retrieve the corresponding diffs.
-    this->updater_ = this->client_->getUpdater(this->zname_, false, true);
-    this->updater_->deleteRRset(*this->soa_);
-    RRsetPtr soa_end(new RRset(this->zname_, this->qclass_, RRType::SOA(),
-                               this->rrttl_));
-    soa_end->addRdata(rdata::createRdata(RRType::SOA(), this->qclass_,
+// Install a simple, commonly used diff sequence: making an update from one
+// SOA to another.  Return the end SOA RRset for the convenience of the caller.
+ConstRRsetPtr
+makeSimpleDiff(DataSourceClient& client, const Name& zname,
+               const RRClass& rrclass, ConstRRsetPtr begin_soa)
+{
+    ZoneUpdaterPtr updater = client.getUpdater(zname, false, true);
+    updater->deleteRRset(*begin_soa);
+    RRsetPtr soa_end(new RRset(zname, rrclass, RRType::SOA(), RRTTL(3600)));
+    soa_end->addRdata(rdata::createRdata(RRType::SOA(), rrclass,
                                          "ns1.example.org. admin.example.org. "
                                          "1235 3600 1800 2419200 7200"));
-    this->updater_->addRRset(*soa_end);
-    this->updater_->commit();
+    updater->addRRset(*soa_end);
+    updater->commit();
+
+    return (soa_end);
+}
 
+TYPED_TEST(DatabaseClientTest, journalReader) {
+    // Check the simple case made by makeSimpleDiff.
+    ConstRRsetPtr soa_end = makeSimpleDiff(*this->client_, this->zname_,
+                                           this->qclass_, this->soa_);
     ZoneJournalReaderPtr jnl_reader(this->client_->getJournalReader(
                                         this->zname_, 1234, 1235).second);
     ConstRRsetPtr rrset = jnl_reader->getNextDiff();
@@ -3142,27 +3151,21 @@ TYPED_TEST(DatabaseClientTest, readLargeJournal) {
 }
 
 TYPED_TEST(DatabaseClientTest, readJournalForNoRange) {
-    this->updater_ = this->client_->getUpdater(this->zname_, false, true);
-    this->updater_->deleteRRset(*this->soa_);
-    RRsetPtr soa_end(new RRset(this->zname_, this->qclass_, RRType::SOA(),
-                               this->rrttl_));
-    soa_end->addRdata(rdata::createRdata(RRType::SOA(), this->qclass_,
-                                         "ns1.example.org. admin.example.org. "
-                                         "1300 3600 1800 2419200 7200"));
-    this->updater_->addRRset(*soa_end);
-    this->updater_->commit();
+    makeSimpleDiff(*this->client_, this->zname_, this->qclass_, this->soa_);
 
     // The specified range does not exist in the diff storage.  The factory
     // method should result in NO_SUCH_SERIAL
     pair<ZoneJournalReader::Result, ZoneJournalReaderPtr> result =
-        this->client_->getJournalReader(this->zname_, 1234, 1235);
+        this->client_->getJournalReader(this->zname_, 1200, 1235);
     EXPECT_EQ(ZoneJournalReader::NO_SUCH_SERIAL, result.first);
     EXPECT_FALSE(result.second);
 }
 
 TYPED_TEST(DatabaseClientTest, journalReaderForNXZone) {
-    EXPECT_THROW(this->client_->getJournalReader(Name("nosuchzone"), 0, 1),
-                 DataSourceError);
+    pair<ZoneJournalReader::Result, ZoneJournalReaderPtr> result =
+        this->client_->getJournalReader(Name("nosuchzone"), 0, 1);
+    EXPECT_EQ(ZoneJournalReader::NO_SUCH_ZONE, result.first);
+    EXPECT_FALSE(result.second);
 }
 
 }