BIND 10 trac1330, updated. 480da1fe075da66aa8a144d37c23bac2fcfa1e2c [1330] Add failing test to extract first RR from difference set

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Nov 4 18:43:43 UTC 2011


The branch, trac1330 has been updated
       via  480da1fe075da66aa8a144d37c23bac2fcfa1e2c (commit)
       via  81b1ba0e9cf67bc5e8ee6040b28436d4c64b72cc (commit)
      from  fc17063223655ab14b4db33bd63dd33fdc5ed5ac (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 480da1fe075da66aa8a144d37c23bac2fcfa1e2c
Author: Stephen Morris <stephen at isc.org>
Date:   Fri Nov 4 18:43:01 2011 +0000

    [1330] Add failing test to extract first RR from difference set

commit 81b1ba0e9cf67bc5e8ee6040b28436d4c64b72cc
Author: Stephen Morris <stephen at isc.org>
Date:   Fri Nov 4 18:31:02 2011 +0000

    [1330] Sorted out clearing up after exception is thrown

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/database.h                         |    3 +-
 src/lib/datasrc/sqlite3_accessor.cc                |   29 ++++++++++-------
 src/lib/datasrc/sqlite3_accessor.h                 |    2 +-
 src/lib/datasrc/tests/database_unittest.cc         |    2 +-
 src/lib/datasrc/tests/sqlite3_accessor_unittest.cc |   34 ++++++++++++++++++-
 src/lib/datasrc/tests/testdata/diffs.sqlite3       |  Bin 16384 -> 16384 bytes
 src/lib/datasrc/tests/testdata/diffs_table.sql     |   20 ++++++------
 7 files changed, 62 insertions(+), 28 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/database.h b/src/lib/datasrc/database.h
index 05331db..f2bb4e7 100644
--- a/src/lib/datasrc/database.h
+++ b/src/lib/datasrc/database.h
@@ -319,8 +319,7 @@ public:
      *
      * \return Newly created iterator context. Must not be NULL.
      */
-    virtual IteratorContextPtr getDiffs(int id, uint32_t start, uint32_t end)
-                                        const = 0;
+    virtual IteratorContextPtr getDiffs(int id, int start, int end) const = 0;
 
     /// Start a transaction for updating a zone.
     ///
diff --git a/src/lib/datasrc/sqlite3_accessor.cc b/src/lib/datasrc/sqlite3_accessor.cc
index f034ba7..ccd9677 100644
--- a/src/lib/datasrc/sqlite3_accessor.cc
+++ b/src/lib/datasrc/sqlite3_accessor.cc
@@ -98,7 +98,7 @@ const char* const text_statements[NUM_STATEMENTS] = {
     "SELECT id FROM diffs "     // LOW_DIFF_ID
         "WHERE zone_id=?1 AND version=?2 and OPERATION=0 "
         "ORDER BY id ASC LIMIT 1",
-    "SELECT id FROM diffs "     // LOW_DIFF_ID
+    "SELECT id FROM diffs "     // HIGH_DIFF_ID
         "WHERE zone_id=?1 AND version=?2 and OPERATION=1 "
         "ORDER BY id DESC LIMIT 1",
     "SELECT name, rrtype, ttl, rdata FROM diffs "   // DIFFS
@@ -605,9 +605,14 @@ public:
                 int id, int start, int end) :
         accessor_(accessor)
     {
-        int low_id = findIndex(LOW_DIFF_ID, id, start);
-        int high_id = findIndex(HIGH_DIFF_ID, id, end);
-        std::cout << "Low index is " << low_id << ", high index is " << high_id << "\n";
+        try {
+            int low_id = findIndex(LOW_DIFF_ID, id, start);
+            int high_id = findIndex(HIGH_DIFF_ID, id, end);
+            std::cout << "Low index is " << low_id << ", high index is " << high_id << "\n";
+        } catch (...) {
+            accessor_->dbparameters_->finalizeStatements();
+            throw;
+        }
     }
 
     virtual ~DiffContext() {}
@@ -686,9 +691,9 @@ private:
             int rc = sqlite3_step(stmt);
             if (rc == SQLITE_DONE) {
 
-                // That was the only data, OK to return. Tidy up as we go,
-                // ignoring any error return.
-                rc = sqlite3_reset(stmt);
+                // All OK, exit with the value.
+                return (result);
+
             } else if (rc == SQLITE_ROW) {
                 isc_throw(DataSourceError, "request to return one value from "
                           "diffs table for serial " << serial << " (zone ID " <<
@@ -701,11 +706,11 @@ private:
                       " for zone ID " << zone_id);
         }
 
-        if (rc != SQLITE_OK) {
-            isc_throw(DataSourceError, "could not get data from diffs table: " <<
-                      sqlite3_errmsg(accessor_->dbparameters_->db_));
-        }
+        // We get here on an error.
+        isc_throw(DataSourceError, "could not get data from diffs table: " <<
+                  sqlite3_errmsg(accessor_->dbparameters_->db_));
 
+        // Keep the compiler happy with a return value.
         return (result);
     }
 
@@ -716,7 +721,7 @@ private:
 // ... and return the iterator
 
 DatabaseAccessor::IteratorContextPtr
-SQLite3Accessor::getDiffs(int id, uint32_t start, uint32_t end) const {
+SQLite3Accessor::getDiffs(int id, int start, int end) const {
     return (IteratorContextPtr(new DiffContext(shared_from_this(), id, start,
                                end)));
 }
diff --git a/src/lib/datasrc/sqlite3_accessor.h b/src/lib/datasrc/sqlite3_accessor.h
index 735f6aa..7e51588 100644
--- a/src/lib/datasrc/sqlite3_accessor.h
+++ b/src/lib/datasrc/sqlite3_accessor.h
@@ -157,7 +157,7 @@ public:
      *
      * \return Iterator containing difference records.
      */
-    virtual IteratorContextPtr getDiffs(int id, uint32_t start, uint32_t end) const;
+    virtual IteratorContextPtr getDiffs(int id, int start, int end) const;
                                         
 
 
diff --git a/src/lib/datasrc/tests/database_unittest.cc b/src/lib/datasrc/tests/database_unittest.cc
index 83d4e81..206c762 100644
--- a/src/lib/datasrc/tests/database_unittest.cc
+++ b/src/lib/datasrc/tests/database_unittest.cc
@@ -252,7 +252,7 @@ public:
                   "This database datasource can't be iterated");
     }
 
-    virtual IteratorContextPtr getDiffs(int, uint32_t, uint32_t) const {
+    virtual IteratorContextPtr getDiffs(int, int, int) const {
         isc_throw(isc::NotImplemented,
                   "This database datasource can't be iterated");
     }
diff --git a/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc b/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc
index 9991444..732f56f 100644
--- a/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc
+++ b/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc
@@ -220,9 +220,39 @@ TEST_F(SQLite3AccessorTest, diffIteratorNoVersion) {
     const std::pair<bool, int> zone_info(accessor->getZone("example.org."));
     ASSERT_TRUE(zone_info.first);
 
-    // Get the iterator context.  Difference of version 1 does not exist.
-    EXPECT_THROW(accessor->getDiffs(zone_info.second, 1U, 1234U),
+    // Get the iterator context.  Difference of version 1 does not exist, so
+    // this should throw an exception.
+    EXPECT_THROW(accessor->getDiffs(zone_info.second, 1, 1234),
+                 isc::datasrc::NoSuchSerial);
+
+    // Check that an invalid high version number also throws an exception.
+    EXPECT_THROW(accessor->getDiffs(zone_info.second, 1231, 2234),
                  NoSuchSerial);
+
+}
+
+// Try to iterate through a valid set of differences
+TEST_F(SQLite3AccessorTest, validSequence) {
+
+    // Our test zone is conveniently small, but not empty
+    initAccessor(SQLITE_DBFILE_DIFFS, "IN");
+
+    const std::pair<bool, int> zone_info(accessor->getZone("example.org."));
+    ASSERT_TRUE(zone_info.first);
+    // Get the iterator context
+    DatabaseAccessor::IteratorContextPtr
+        context(accessor->getDiffs(zone_info.second, 1230, 1232));
+    ASSERT_NE(DatabaseAccessor::IteratorContextPtr(), context);
+
+    std::string data[DatabaseAccessor::COLUMN_COUNT];
+
+    // Check the records
+    EXPECT_TRUE(context->getNext(data));
+    EXPECT_EQ("SOA", data[DatabaseAccessor::TYPE_COLUMN]);
+    EXPECT_EQ("3600", data[DatabaseAccessor::TTL_COLUMN]);
+    EXPECT_EQ("ns1.example.org. admin.example.org. 1230, 3600 1800 2419200 7200",
+        data[DatabaseAccessor::RDATA_COLUMN]);
+    EXPECT_EQ("example.org.", data[DatabaseAccessor::NAME_COLUMN]);
 }
 
 TEST(SQLite3Open, getDBNameExample2) {
diff --git a/src/lib/datasrc/tests/testdata/diffs.sqlite3 b/src/lib/datasrc/tests/testdata/diffs.sqlite3
index c5a1476..2095d4c 100644
Binary files a/src/lib/datasrc/tests/testdata/diffs.sqlite3 and b/src/lib/datasrc/tests/testdata/diffs.sqlite3 differ
diff --git a/src/lib/datasrc/tests/testdata/diffs_table.sql b/src/lib/datasrc/tests/testdata/diffs_table.sql
index b5467a7..39c913a 100644
--- a/src/lib/datasrc/tests/testdata/diffs_table.sql
+++ b/src/lib/datasrc/tests/testdata/diffs_table.sql
@@ -45,14 +45,14 @@ CREATE TABLE diffs (id INTEGER PRIMARY KEY AUTOINCREMENT,
 -- Update one record in the zone.
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 4294967280,  0, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 4294967280 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 4294967280 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 4294967280, 0, "www.example.org.", "A", 3600, "192.0.2.31");
 
 -- Records added in version 1230 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1230, 1, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 1230 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1230 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1230, 1, "www.example.org.", "A", 3600, "192.0.2.21");
 
@@ -60,37 +60,37 @@ INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
 -- Records removed from version 1230 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1230, 0, "example.org.", "SOA", 1800,
-           "ns1.example.org. admin.example.org. 1230 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1230 3600 1800 2419200 7200");
 
 -- Records added in version 1231 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1231, 1, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 1231 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1231 3600 1800 2419200 7200");
 
 
 -- Change 1231 to 1232: Remove one record, don't add anything.
 -- Records removed from version 1231 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1231, 0, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 1231 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1231 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1231, 0, "unused.example.org.", "A", 3600, "192.0.2.102");
 
 -- Records added in version 1232 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1232, 1, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 1232 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1232 3600 1800 2419200 7200");
 
 -- Change 1232 to 1233: Add two, don't remove anything.
 -- Records removed from version 1232 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1232, 0, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 1232 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1232 3600 1800 2419200 7200");
 
 -- Records added in version 1233 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1233, 1, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 1233 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1233 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1233, 1, "sub.example.org.", "NS", 3600, "ns.sub.example.org.");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
@@ -101,7 +101,7 @@ INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
 -- Records removed from version 1233 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1233, 0, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 1233 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1233 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1233, 0, "www.example.org.", "A", 3600, "192.0.2.21");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
@@ -110,7 +110,7 @@ INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
 -- Records added in version 1234 of the zone
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1234, 1, "example.org.", "SOA", 3600,
-           "ns1.example.org. admin.example.org. 1234 3600 1800 2419200, 7200");
+           "ns1.example.org. admin.example.org. 1234 3600 1800 2419200 7200");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)
     VALUES(1, 1234, 1, "www.example.org.", "A", 3600, "192.0.2.1");
 INSERT INTO diffs(zone_id, version, operation, name, rrtype, ttl, rdata)




More information about the bind10-changes mailing list