From: JINMEI Tatuya Date: Tue, 3 Apr 2012 06:41:55 +0000 (-0700) Subject: [1746] removed SQLite3Accessor::getRecordDiff, and adjusted the test as such. X-Git-Tag: trac2351_base~226^2~116^2~61^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=69e76e0edb5a28773bd8e29d82902c4dbbb412ad;p=thirdparty%2Fkea.git [1746] removed SQLite3Accessor::getRecordDiff, and adjusted the test as such. it was intended to be a short term hack until we implement getDiffs(), but apparently we forgot to complete the cleanup task. So this is just an originally planned cleanup. note that there was a bug in the test code. The change to diff_add_a_data is not to hide a problem in the tested code, but it's a fix to the test's bug. --- diff --git a/src/lib/datasrc/sqlite3_accessor.cc b/src/lib/datasrc/sqlite3_accessor.cc index 308df607a3..848d781e6c 100644 --- a/src/lib/datasrc/sqlite3_accessor.cc +++ b/src/lib/datasrc/sqlite3_accessor.cc @@ -858,7 +858,7 @@ private: // No data returned but the SQL query succeeded. Only possibility // is that there is no entry in the differences table for the given // zone and version. - isc_throw(NoSuchSerial, "No entry in differences table for " << + isc_throw(NoSuchSerial, "No entry in differences table for" << " zone ID " << zone_id << ", serial number " << serial); } @@ -1085,26 +1085,6 @@ SQLite3Accessor::addRecordDiff(int zone_id, uint32_t serial, executer.exec(); } -vector > -SQLite3Accessor::getRecordDiff(int zone_id) { - sqlite3_stmt* const stmt = dbparameters_->getStatement(GET_RECORD_DIFF); - sqlite3_bind_int(stmt, 1, zone_id); - - vector > result; - while (sqlite3_step(stmt) == SQLITE_ROW) { - vector row_result; - for (int i = 0; i < 6; ++i) { - row_result.push_back(convertToPlainChar(sqlite3_column_text(stmt, - i), - dbparameters_->db_)); - } - result.push_back(row_result); - } - sqlite3_reset(stmt); - - return (result); -} - std::string SQLite3Accessor::findPreviousName(int zone_id, const std::string& rname) const diff --git a/src/lib/datasrc/sqlite3_accessor.h b/src/lib/datasrc/sqlite3_accessor.h index efaec0e858..382383c4d3 100644 --- a/src/lib/datasrc/sqlite3_accessor.h +++ b/src/lib/datasrc/sqlite3_accessor.h @@ -218,16 +218,6 @@ public: int zone_id, uint32_t serial, DiffOperation operation, const std::string (¶ms)[DIFF_PARAM_COUNT]); - // A short term method for tests until we implement more complete - // API to retrieve diffs (#1330). It returns all records of the diffs - // table whose zone_id column is identical to the given value. - // Since this is a short term workaround, it ignores some corner cases - // (such as an SQLite3 execution failure) and is not very efficient, - // in favor of brevity. Once #1330 is completed, this method must be - // removed, and the tests using this method must be rewritten using the - // official API. - std::vector > getRecordDiff(int zone_id); - /// The SQLite3 implementation of this method returns a string starting /// with a fixed prefix of "sqlite3_" followed by the DB file name /// removing any path name. For example, for the DB file diff --git a/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc b/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc index cd760b6146..9c0c9e4a74 100644 --- a/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc +++ b/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc @@ -1050,7 +1050,7 @@ const char* const diff_end_data[] = { "1300", DIFF_ADD_TEXT }; const char* const diff_add_a_data[] = { - "dns01.example.com.", "A", "3600", "192.0.2.10", "1234", DIFF_ADD_TEXT + "dns01.example.com.", "A", "3600", "192.0.2.10", "1300", DIFF_ADD_TEXT }; // The following two are helper functions to convert textual test data @@ -1071,8 +1071,19 @@ getOperation(const char* const diff_data[]) { // diffs. void checkDiffs(const vector& expected, - const vector >& actual) + DatabaseAccessor::IteratorContextPtr rr_iterator) { + vector > actual; + string columns_holder[DatabaseAccessor::COLUMN_COUNT]; + while (rr_iterator->getNext(columns_holder)) { + // Reorder the 'actual' vector to be compatible with the expected one. + vector columns; + columns.push_back(columns_holder[DatabaseAccessor::NAME_COLUMN]); + columns.push_back(columns_holder[DatabaseAccessor::TYPE_COLUMN]); + columns.push_back(columns_holder[DatabaseAccessor::TTL_COLUMN]); + columns.push_back(columns_holder[DatabaseAccessor::RDATA_COLUMN]); + actual.push_back(columns); + } EXPECT_EQ(expected.size(), actual.size()); const size_t n_diffs = std::min(expected.size(), actual.size()); for (size_t i = 0; i < n_diffs; ++i) { @@ -1098,16 +1109,18 @@ TEST_F(SQLite3Update, addRecordDiff) { getOperation(diff_end_data), diff_params); // Until the diffs are committed, they are not visible to other accessors. - EXPECT_TRUE(another_accessor->getRecordDiff(zone_id).empty()); + EXPECT_THROW(another_accessor->getDiffs(zone_id, 1234, 1300), + NoSuchSerial); accessor->commit(); expected_stored.clear(); expected_stored.push_back(diff_begin_data); expected_stored.push_back(diff_end_data); - checkDiffs(expected_stored, accessor->getRecordDiff(zone_id)); + checkDiffs(expected_stored, accessor->getDiffs(zone_id, 1234, 1300)); // Now it should be visible to others, too. - checkDiffs(expected_stored, another_accessor->getRecordDiff(zone_id)); + checkDiffs(expected_stored, another_accessor->getDiffs(zone_id, 1234, + 1300)); } TEST_F(SQLite3Update, addRecordOfLargeSerial) { @@ -1139,7 +1152,7 @@ TEST_F(SQLite3Update, addRecordOfLargeSerial) { expected_stored.clear(); expected_stored.push_back(begin_data); expected_stored.push_back(diff_end_data); - checkDiffs(expected_stored, accessor->getRecordDiff(zone_id)); + checkDiffs(expected_stored, accessor->getDiffs(zone_id, 4294967295, 1300)); } TEST_F(SQLite3Update, addDiffWithoutUpdate) { @@ -1184,7 +1197,7 @@ TEST_F(SQLite3Update, addDiffRollback) { getOperation(diff_begin_data), diff_params); accessor->rollback(); - EXPECT_TRUE(accessor->getRecordDiff(zone_id).empty()); + EXPECT_THROW(accessor->getDiffs(zone_id, 1234, 1234), NoSuchSerial); } TEST_F(SQLite3Update, addDiffInBadOrder) { @@ -1196,19 +1209,23 @@ TEST_F(SQLite3Update, addDiffInBadOrder) { copy(diff_end_data, diff_end_data + DatabaseAccessor::DIFF_PARAM_COUNT, diff_params); accessor->addRecordDiff(zone_id, getVersion(diff_end_data), - getOperation(diff_end_data), diff_params); + static_cast( + lexical_cast(DIFF_DELETE_TEXT)), + diff_params); copy(diff_begin_data, diff_begin_data + DatabaseAccessor::DIFF_PARAM_COUNT, diff_params); accessor->addRecordDiff(zone_id, getVersion(diff_begin_data), - getOperation(diff_begin_data), diff_params); + static_cast( + lexical_cast(DIFF_ADD_TEXT)), + diff_params); accessor->commit(); expected_stored.clear(); expected_stored.push_back(diff_end_data); expected_stored.push_back(diff_begin_data); - checkDiffs(expected_stored, accessor->getRecordDiff(zone_id)); + checkDiffs(expected_stored, accessor->getDiffs(zone_id, 1300, 1234)); } TEST_F(SQLite3Update, addDiffWithUpdate) { @@ -1278,7 +1295,7 @@ TEST_F(SQLite3Update, addDiffWithUpdate) { expected_stored.push_back(diff_end_data); expected_stored.push_back(diff_add_a_data); - checkDiffs(expected_stored, accessor->getRecordDiff(zone_id)); + checkDiffs(expected_stored, accessor->getDiffs(zone_id, 1234, 1300)); } TEST_F(SQLite3Update, addDiffWithNoTable) {