|
@@ -49,73 +49,73 @@ std::string SQLITE_DBFILE_NOTEXIST = TEST_DATA_DIR "/nodir/notexist";
|
|
|
|
|
|
// Opening works (the content is tested in different tests)
|
|
|
TEST(SQLite3Open, common) {
|
|
|
- EXPECT_NO_THROW(SQLite3Database db(SQLITE_DBFILE_EXAMPLE,
|
|
|
- RRClass::IN()));
|
|
|
+ EXPECT_NO_THROW(SQLite3Accessor accessor(SQLITE_DBFILE_EXAMPLE,
|
|
|
+ RRClass::IN()));
|
|
|
}
|
|
|
|
|
|
// The file can't be opened
|
|
|
TEST(SQLite3Open, notExist) {
|
|
|
- EXPECT_THROW(SQLite3Database db(SQLITE_DBFILE_NOTEXIST,
|
|
|
- RRClass::IN()), SQLite3Error);
|
|
|
+ EXPECT_THROW(SQLite3Accessor accessor(SQLITE_DBFILE_NOTEXIST,
|
|
|
+ RRClass::IN()), SQLite3Error);
|
|
|
}
|
|
|
|
|
|
// It rejects broken DB
|
|
|
TEST(SQLite3Open, brokenDB) {
|
|
|
- EXPECT_THROW(SQLite3Database db(SQLITE_DBFILE_BROKENDB,
|
|
|
- RRClass::IN()), SQLite3Error);
|
|
|
+ EXPECT_THROW(SQLite3Accessor accessor(SQLITE_DBFILE_BROKENDB,
|
|
|
+ RRClass::IN()), SQLite3Error);
|
|
|
}
|
|
|
|
|
|
// Test we can create the schema on the fly
|
|
|
TEST(SQLite3Open, memoryDB) {
|
|
|
- EXPECT_NO_THROW(SQLite3Database db(SQLITE_DBFILE_MEMORY,
|
|
|
- RRClass::IN()));
|
|
|
+ EXPECT_NO_THROW(SQLite3Accessor accessor(SQLITE_DBFILE_MEMORY,
|
|
|
+ RRClass::IN()));
|
|
|
}
|
|
|
|
|
|
// Test fixture for querying the db
|
|
|
-class SQLite3Access : public ::testing::Test {
|
|
|
+class SQLite3AccessorTest : public ::testing::Test {
|
|
|
public:
|
|
|
- SQLite3Access() {
|
|
|
+ SQLite3AccessorTest() {
|
|
|
initAccessor(SQLITE_DBFILE_EXAMPLE, RRClass::IN());
|
|
|
}
|
|
|
// So it can be re-created with different data
|
|
|
void initAccessor(const std::string& filename, const RRClass& rrclass) {
|
|
|
- db.reset(new SQLite3Database(filename, rrclass));
|
|
|
+ accessor.reset(new SQLite3Accessor(filename, rrclass));
|
|
|
}
|
|
|
- // The tested dbection
|
|
|
- boost::scoped_ptr<SQLite3Database> db;
|
|
|
+ // The tested accessor
|
|
|
+ boost::scoped_ptr<SQLite3Accessor> accessor;
|
|
|
};
|
|
|
|
|
|
// This zone exists in the data, so it should be found
|
|
|
-TEST_F(SQLite3Access, getZone) {
|
|
|
- std::pair<bool, int> result(db->getZone(Name("example.com")));
|
|
|
+TEST_F(SQLite3AccessorTest, getZone) {
|
|
|
+ std::pair<bool, int> result(accessor->getZone(Name("example.com")));
|
|
|
EXPECT_TRUE(result.first);
|
|
|
EXPECT_EQ(1, result.second);
|
|
|
}
|
|
|
|
|
|
// But it should find only the zone, nothing below it
|
|
|
-TEST_F(SQLite3Access, subZone) {
|
|
|
- EXPECT_FALSE(db->getZone(Name("sub.example.com")).first);
|
|
|
+TEST_F(SQLite3AccessorTest, subZone) {
|
|
|
+ EXPECT_FALSE(accessor->getZone(Name("sub.example.com")).first);
|
|
|
}
|
|
|
|
|
|
// This zone is not there at all
|
|
|
-TEST_F(SQLite3Access, noZone) {
|
|
|
- EXPECT_FALSE(db->getZone(Name("example.org")).first);
|
|
|
+TEST_F(SQLite3AccessorTest, noZone) {
|
|
|
+ EXPECT_FALSE(accessor->getZone(Name("example.org")).first);
|
|
|
}
|
|
|
|
|
|
// This zone is there, but in different class
|
|
|
-TEST_F(SQLite3Access, noClass) {
|
|
|
+TEST_F(SQLite3AccessorTest, noClass) {
|
|
|
initAccessor(SQLITE_DBFILE_EXAMPLE, RRClass::CH());
|
|
|
- EXPECT_FALSE(db->getZone(Name("example.com")).first);
|
|
|
+ EXPECT_FALSE(accessor->getZone(Name("example.com")).first);
|
|
|
}
|
|
|
|
|
|
TEST(SQLite3Open, getDBNameExample2) {
|
|
|
- SQLite3Database db(SQLITE_DBFILE_EXAMPLE2, RRClass::IN());
|
|
|
- EXPECT_EQ(SQLITE_DBNAME_EXAMPLE2, db.getDBName());
|
|
|
+ SQLite3Accessor accessor(SQLITE_DBFILE_EXAMPLE2, RRClass::IN());
|
|
|
+ EXPECT_EQ(SQLITE_DBNAME_EXAMPLE2, accessor.getDBName());
|
|
|
}
|
|
|
|
|
|
TEST(SQLite3Open, getDBNameExampleROOT) {
|
|
|
- SQLite3Database db(SQLITE_DBFILE_EXAMPLE_ROOT, RRClass::IN());
|
|
|
- EXPECT_EQ(SQLITE_DBNAME_EXAMPLE_ROOT, db.getDBName());
|
|
|
+ SQLite3Accessor accessor(SQLITE_DBFILE_EXAMPLE_ROOT, RRClass::IN());
|
|
|
+ EXPECT_EQ(SQLITE_DBNAME_EXAMPLE_ROOT, accessor.getDBName());
|
|
|
}
|
|
|
|
|
|
// Simple function to cound the number of records for
|
|
@@ -133,8 +133,9 @@ checkRecordRow(const std::string columns[],
|
|
|
EXPECT_EQ(field3, columns[3]);
|
|
|
}
|
|
|
|
|
|
-TEST_F(SQLite3Access, getRecords) {
|
|
|
- const std::pair<bool, int> zone_info(db->getZone(Name("example.com")));
|
|
|
+TEST_F(SQLite3AccessorTest, getRecords) {
|
|
|
+ const std::pair<bool, int> zone_info(
|
|
|
+ accessor->getZone(Name("example.com")));
|
|
|
ASSERT_TRUE(zone_info.first);
|
|
|
|
|
|
const int zone_id = zone_info.second;
|
|
@@ -144,85 +145,85 @@ TEST_F(SQLite3Access, getRecords) {
|
|
|
std::string columns[column_count];
|
|
|
|
|
|
// without search, getNext() should return false
|
|
|
- EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
+ EXPECT_FALSE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "", "", "", "");
|
|
|
|
|
|
- db->searchForRecords(zone_id, "foo.bar.");
|
|
|
- EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
+ accessor->searchForRecords(zone_id, "foo.bar.");
|
|
|
+ EXPECT_FALSE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "", "", "", "");
|
|
|
|
|
|
- db->searchForRecords(zone_id, "");
|
|
|
- EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
+ accessor->searchForRecords(zone_id, "");
|
|
|
+ EXPECT_FALSE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "", "", "", "");
|
|
|
|
|
|
// Should error on a bad number of columns
|
|
|
- EXPECT_THROW(db->getNextRecord(columns, 3), DataSourceError);
|
|
|
- EXPECT_THROW(db->getNextRecord(columns, 5), DataSourceError);
|
|
|
+ EXPECT_THROW(accessor->getNextRecord(columns, 3), DataSourceError);
|
|
|
+ EXPECT_THROW(accessor->getNextRecord(columns, 5), DataSourceError);
|
|
|
|
|
|
// now try some real searches
|
|
|
- db->searchForRecords(zone_id, "foo.example.com.");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ accessor->searchForRecords(zone_id, "foo.example.com.");
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "CNAME", "3600", "",
|
|
|
"cnametest.example.org.");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "CNAME",
|
|
|
"CNAME 5 3 3600 20100322084538 20100220084538 33495 "
|
|
|
"example.com. FAKEFAKEFAKEFAKE");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "NSEC", "7200", "",
|
|
|
"mail.example.com. CNAME RRSIG NSEC");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "7200", "NSEC",
|
|
|
"NSEC 5 3 7200 20100322084538 20100220084538 33495 "
|
|
|
"example.com. FAKEFAKEFAKEFAKE");
|
|
|
- EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
+ EXPECT_FALSE(accessor->getNextRecord(columns, column_count));
|
|
|
// with no more records, the array should not have been modified
|
|
|
checkRecordRow(columns, "RRSIG", "7200", "NSEC",
|
|
|
"NSEC 5 3 7200 20100322084538 20100220084538 33495 "
|
|
|
"example.com. FAKEFAKEFAKEFAKE");
|
|
|
|
|
|
- db->searchForRecords(zone_id, "example.com.");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ accessor->searchForRecords(zone_id, "example.com.");
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "SOA", "3600", "",
|
|
|
"master.example.com. admin.example.com. "
|
|
|
"1234 3600 1800 2419200 7200");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "SOA",
|
|
|
"SOA 5 2 3600 20100322084538 20100220084538 "
|
|
|
"33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "NS", "1200", "", "dns01.example.com.");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "NS", "3600", "", "dns02.example.com.");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "NS", "1800", "", "dns03.example.com.");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "NS",
|
|
|
"NS 5 2 3600 20100322084538 20100220084538 "
|
|
|
"33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "MX", "3600", "", "10 mail.example.com.");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "MX", "3600", "",
|
|
|
"20 mail.subzone.example.com.");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "MX",
|
|
|
"MX 5 2 3600 20100322084538 20100220084538 "
|
|
|
"33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "NSEC", "7200", "",
|
|
|
"cname-ext.example.com. NS SOA MX RRSIG NSEC DNSKEY");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "7200", "NSEC",
|
|
|
"NSEC 5 2 7200 20100322084538 20100220084538 "
|
|
|
"33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "DNSKEY", "3600", "",
|
|
|
"256 3 5 AwEAAcOUBllYc1hf7ND9uDy+Yz1BF3sI0m4q NGV7W"
|
|
|
"cTD0WEiuV7IjXgHE36fCmS9QsUxSSOV o1I/FMxI2PJVqTYHkX"
|
|
|
"FBS7AzLGsQYMU7UjBZ SotBJ6Imt5pXMu+lEDNy8TOUzG3xm7g"
|
|
|
"0qcbW YF6qCEfvZoBtAqi5Rk7Mlrqs8agxYyMx");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "DNSKEY", "3600", "",
|
|
|
"257 3 5 AwEAAe5WFbxdCPq2jZrZhlMj7oJdff3W7syJ tbvzg"
|
|
|
"62tRx0gkoCDoBI9DPjlOQG0UAbj+xUV 4HQZJStJaZ+fHU5AwV"
|
|
@@ -232,15 +233,15 @@ TEST_F(SQLite3Access, getRecords) {
|
|
|
"fiHAxFHrkY3t3D5J R9Nsl/7fdRmSznwtcSDgLXBoFEYmw6p86"
|
|
|
"Acv RyoYNcL1SXjaKVLG5jyU3UR+LcGZT5t/0xGf oIK/aKwEN"
|
|
|
"rsjcKZZj660b1M=");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "DNSKEY",
|
|
|
"DNSKEY 5 2 3600 20100322084538 20100220084538 "
|
|
|
"4456 example.com. FAKEFAKEFAKEFAKE");
|
|
|
- ASSERT_TRUE(db->getNextRecord(columns, column_count));
|
|
|
+ ASSERT_TRUE(accessor->getNextRecord(columns, column_count));
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "DNSKEY",
|
|
|
"DNSKEY 5 2 3600 20100322084538 20100220084538 "
|
|
|
"33495 example.com. FAKEFAKEFAKEFAKE");
|
|
|
- EXPECT_FALSE(db->getNextRecord(columns, column_count));
|
|
|
+ EXPECT_FALSE(accessor->getNextRecord(columns, column_count));
|
|
|
// getnextrecord returning false should mean array is not altered
|
|
|
checkRecordRow(columns, "RRSIG", "3600", "DNSKEY",
|
|
|
"DNSKEY 5 2 3600 20100322084538 20100220084538 "
|
|
@@ -265,17 +266,17 @@ const char* const deleted_data[] = {
|
|
|
"foo.bar.example.com.", "A", "192.0.2.1"
|
|
|
};
|
|
|
|
|
|
-class SQLite3Update : public SQLite3Access {
|
|
|
+class SQLite3Update : public SQLite3AccessorTest {
|
|
|
protected:
|
|
|
SQLite3Update() {
|
|
|
ASSERT_EQ(0, system(INSTALL_PROG " " TEST_DATA_DIR
|
|
|
"/test.sqlite3 "
|
|
|
TEST_DATA_BUILDDIR "/test.sqlite3.copied"));
|
|
|
initAccessor(TEST_DATA_BUILDDIR "/test.sqlite3.copied", RRClass::IN());
|
|
|
- zone_id = db->getZone(Name("example.com")).second;
|
|
|
- another_db.reset(new SQLite3Database(
|
|
|
- TEST_DATA_BUILDDIR "/test.sqlite3.copied",
|
|
|
- RRClass::IN()));
|
|
|
+ zone_id = accessor->getZone(Name("example.com")).second;
|
|
|
+ another_accessor.reset(new SQLite3Accessor(
|
|
|
+ TEST_DATA_BUILDDIR "/test.sqlite3.copied",
|
|
|
+ RRClass::IN()));
|
|
|
expected_stored.push_back(common_expected_data);
|
|
|
}
|
|
|
|
|
@@ -287,17 +288,17 @@ protected:
|
|
|
vector<const char* const*> empty_stored; // indicate no corresponding data
|
|
|
|
|
|
// Another accessor, emulating one running on a different process/thread
|
|
|
- shared_ptr<SQLite3Database> another_db;
|
|
|
+ shared_ptr<SQLite3Accessor> another_accessor;
|
|
|
};
|
|
|
|
|
|
void
|
|
|
-checkRecords(SQLite3Database& db, int zone_id, const std::string& name,
|
|
|
+checkRecords(SQLite3Accessor& accessor, int zone_id, const std::string& name,
|
|
|
vector<const char* const*> expected_rows)
|
|
|
{
|
|
|
- db.searchForRecords(zone_id, name);
|
|
|
+ accessor.searchForRecords(zone_id, name);
|
|
|
std::string columns[DatabaseAccessor::COLUMN_COUNT];
|
|
|
vector<const char* const*>::const_iterator it = expected_rows.begin();
|
|
|
- while (db.getNextRecord(columns, DatabaseAccessor::COLUMN_COUNT)) {
|
|
|
+ while (accessor.getNextRecord(columns, DatabaseAccessor::COLUMN_COUNT)) {
|
|
|
ASSERT_TRUE(it != expected_rows.end());
|
|
|
checkRecordRow(columns, (*it)[3], (*it)[2], (*it)[4], (*it)[5]);
|
|
|
++it;
|
|
@@ -309,64 +310,64 @@ TEST_F(SQLite3Update, emptyUpdate) {
|
|
|
// If we do nothing between start and commit, the zone content
|
|
|
// should be intact.
|
|
|
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
- db->commitUpdateZone();
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ accessor->commitUpdateZone();
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, flushZone) {
|
|
|
// With 'replace' being true startUpdateZone() will flush the existing
|
|
|
// zone content.
|
|
|
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
- zone_id = db->startUpdateZone("example.com.", true).second;
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
- db->commitUpdateZone();
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", true).second;
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ accessor->commitUpdateZone();
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, readWhileUpdate) {
|
|
|
- zone_id = db->startUpdateZone("example.com.", true).second;
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", true).second;
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
|
|
|
// Until commit is done, the other accessor should see the old data
|
|
|
- another_db->searchForRecords(zone_id, "foo.bar.example.com.");
|
|
|
- checkRecords(*another_db, zone_id, "foo.bar.example.com.",
|
|
|
+ another_accessor->searchForRecords(zone_id, "foo.bar.example.com.");
|
|
|
+ checkRecords(*another_accessor, zone_id, "foo.bar.example.com.",
|
|
|
expected_stored);
|
|
|
|
|
|
// Once the changes are committed, the other accessor will see the new
|
|
|
// data.
|
|
|
- db->commitUpdateZone();
|
|
|
- another_db->searchForRecords(zone_id, "foo.bar.example.com.");
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ accessor->commitUpdateZone();
|
|
|
+ another_accessor->searchForRecords(zone_id, "foo.bar.example.com.");
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, rollback) {
|
|
|
- zone_id = db->startUpdateZone("example.com.", true).second;
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", true).second;
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
|
|
|
// Rollback will revert the change made by startUpdateZone(, true).
|
|
|
- db->rollbackUpdateZone();
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ accessor->rollbackUpdateZone();
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, commitConflict) {
|
|
|
// Start reading the DB by another accessor. We should stop at a single
|
|
|
// call to getNextRecord() to keep holding the lock.
|
|
|
- another_db->searchForRecords(zone_id, "foo.example.com.");
|
|
|
- EXPECT_TRUE(another_db->getNextRecord(get_columns,
|
|
|
+ another_accessor->searchForRecords(zone_id, "foo.example.com.");
|
|
|
+ EXPECT_TRUE(another_accessor->getNextRecord(get_columns,
|
|
|
DatabaseAccessor::COLUMN_COUNT));
|
|
|
|
|
|
// Due to getNextRecord() above, the other accessor holds a DB lock,
|
|
|
// which will prevent commit.
|
|
|
- zone_id = db->startUpdateZone("example.com.", true).second;
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
- EXPECT_THROW(db->commitUpdateZone(), DataSourceError);
|
|
|
- db->rollbackUpdateZone(); // rollback should still succeed
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", true).second;
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ EXPECT_THROW(accessor->commitUpdateZone(), DataSourceError);
|
|
|
+ accessor->rollbackUpdateZone(); // rollback should still succeed
|
|
|
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, updateConflict) {
|
|
@@ -374,54 +375,57 @@ TEST_F(SQLite3Update, updateConflict) {
|
|
|
// update attempt. Note that these two accessors modify disjoint sets
|
|
|
// of data; sqlite3 only has a coarse-grained lock so we cannot allow
|
|
|
// these updates to run concurrently.
|
|
|
- EXPECT_TRUE(another_db->startUpdateZone("sql1.example.com.", true).first);
|
|
|
- EXPECT_THROW(db->startUpdateZone("example.com.", true), DataSourceError);
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ EXPECT_TRUE(another_accessor->startUpdateZone("sql1.example.com.",
|
|
|
+ true).first);
|
|
|
+ EXPECT_THROW(accessor->startUpdateZone("example.com.", true),
|
|
|
+ DataSourceError);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, duplicateUpdate) {
|
|
|
- db->startUpdateZone("example.com.", false);
|
|
|
- EXPECT_THROW(db->startUpdateZone("example.com.", false), DataSourceError);
|
|
|
+ accessor->startUpdateZone("example.com.", false);
|
|
|
+ EXPECT_THROW(accessor->startUpdateZone("example.com.", false),
|
|
|
+ DataSourceError);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, commitWithoutTransaction) {
|
|
|
- EXPECT_THROW(db->commitUpdateZone(), DataSourceError);
|
|
|
+ EXPECT_THROW(accessor->commitUpdateZone(), DataSourceError);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, rollbackWithoutTransaction) {
|
|
|
- EXPECT_THROW(db->rollbackUpdateZone(), DataSourceError);
|
|
|
+ EXPECT_THROW(accessor->rollbackUpdateZone(), DataSourceError);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, addRecord) {
|
|
|
// Before update, there should be no record for this name
|
|
|
- checkRecords(*db, zone_id, "newdata.example.com.", empty_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "newdata.example.com.", empty_stored);
|
|
|
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
update_columns.assign(new_data,
|
|
|
new_data + DatabaseAccessor::ADD_COLUMN_COUNT);
|
|
|
- db->addRecordToZone(update_columns);
|
|
|
+ accessor->addRecordToZone(update_columns);
|
|
|
|
|
|
expected_stored.clear();
|
|
|
expected_stored.push_back(new_data);
|
|
|
- checkRecords(*db, zone_id, "newdata.example.com.", expected_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "newdata.example.com.", expected_stored);
|
|
|
|
|
|
// Commit the change, and confirm the new data is still there.
|
|
|
- db->commitUpdateZone();
|
|
|
- checkRecords(*db, zone_id, "newdata.example.com.", expected_stored);
|
|
|
+ accessor->commitUpdateZone();
|
|
|
+ checkRecords(*accessor, zone_id, "newdata.example.com.", expected_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, addThenRollback) {
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
update_columns.assign(new_data,
|
|
|
new_data + DatabaseAccessor::ADD_COLUMN_COUNT);
|
|
|
- db->addRecordToZone(update_columns);
|
|
|
+ accessor->addRecordToZone(update_columns);
|
|
|
|
|
|
expected_stored.clear();
|
|
|
expected_stored.push_back(new_data);
|
|
|
- checkRecords(*db, zone_id, "newdata.example.com.", expected_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "newdata.example.com.", expected_stored);
|
|
|
|
|
|
- db->rollbackUpdateZone();
|
|
|
- checkRecords(*db, zone_id, "newdata.example.com.", empty_stored);
|
|
|
+ accessor->rollbackUpdateZone();
|
|
|
+ checkRecords(*accessor, zone_id, "newdata.example.com.", empty_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, duplicateAdd) {
|
|
@@ -431,103 +435,105 @@ TEST_F(SQLite3Update, duplicateAdd) {
|
|
|
};
|
|
|
expected_stored.clear();
|
|
|
expected_stored.push_back(dup_data);
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
|
|
|
// Adding exactly the same data. As this backend is "dumb", another
|
|
|
// row of the same content will be inserted.
|
|
|
update_columns.assign(dup_data,
|
|
|
dup_data + DatabaseAccessor::ADD_COLUMN_COUNT);
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
- db->addRecordToZone(update_columns);
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
+ accessor->addRecordToZone(update_columns);
|
|
|
expected_stored.push_back(dup_data);
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, invalidAdd) {
|
|
|
// An attempt of add before an explicit start of transaction
|
|
|
- EXPECT_THROW(db->addRecordToZone(update_columns), DataSourceError);
|
|
|
+ EXPECT_THROW(accessor->addRecordToZone(update_columns), DataSourceError);
|
|
|
|
|
|
// Short column vector
|
|
|
update_columns.clear();
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
- EXPECT_THROW(db->addRecordToZone(update_columns), DataSourceError);
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
+ EXPECT_THROW(accessor->addRecordToZone(update_columns), DataSourceError);
|
|
|
|
|
|
// Too many columns
|
|
|
for (int i = 0; i < DatabaseAccessor::ADD_COLUMN_COUNT + 1; ++i) {
|
|
|
update_columns.push_back("");
|
|
|
}
|
|
|
- EXPECT_THROW(db->addRecordToZone(update_columns), DataSourceError);
|
|
|
+ EXPECT_THROW(accessor->addRecordToZone(update_columns), DataSourceError);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, deleteRecord) {
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
|
|
|
update_columns.assign(deleted_data, deleted_data +
|
|
|
DatabaseAccessor::DEL_PARAM_COUNT);
|
|
|
- db->deleteRecordInZone(update_columns);
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ accessor->deleteRecordInZone(update_columns);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
|
|
|
// Commit the change, and confirm the deleted data still isn't there.
|
|
|
- db->commitUpdateZone();
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ accessor->commitUpdateZone();
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, deleteThenRollback) {
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
|
|
|
update_columns.assign(deleted_data, deleted_data +
|
|
|
DatabaseAccessor::DEL_PARAM_COUNT);
|
|
|
- db->deleteRecordInZone(update_columns);
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
+ accessor->deleteRecordInZone(update_columns);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", empty_stored);
|
|
|
|
|
|
// Rollback the change, and confirm the data still exists.
|
|
|
- db->rollbackUpdateZone();
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ accessor->rollbackUpdateZone();
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, deleteNonexistent) {
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
update_columns.assign(deleted_data, deleted_data +
|
|
|
DatabaseAccessor::DEL_PARAM_COUNT);
|
|
|
|
|
|
// Replace the name with a non existent one, then try to delete it.
|
|
|
// nothing should happen.
|
|
|
update_columns[0] = "no-such-name.example.com.";
|
|
|
- checkRecords(*db, zone_id, "no-such-name.example.com.", empty_stored);
|
|
|
- db->deleteRecordInZone(update_columns);
|
|
|
- checkRecords(*db, zone_id, "no-such-name.example.com.", empty_stored);
|
|
|
+ checkRecords(*accessor, zone_id, "no-such-name.example.com.",
|
|
|
+ empty_stored);
|
|
|
+ accessor->deleteRecordInZone(update_columns);
|
|
|
+ checkRecords(*accessor, zone_id, "no-such-name.example.com.",
|
|
|
+ empty_stored);
|
|
|
|
|
|
// Name exists but the RR type is different. Delete attempt shouldn't
|
|
|
// delete only by name.
|
|
|
update_columns.assign(deleted_data, deleted_data +
|
|
|
DatabaseAccessor::DEL_PARAM_COUNT);
|
|
|
update_columns[1] = "AAAA";
|
|
|
- db->deleteRecordInZone(update_columns);
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ accessor->deleteRecordInZone(update_columns);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
|
|
|
// Similar to the previous case, but RDATA is different.
|
|
|
update_columns.assign(deleted_data, deleted_data +
|
|
|
DatabaseAccessor::DEL_PARAM_COUNT);
|
|
|
update_columns[2] = "192.0.2.2";
|
|
|
- db->deleteRecordInZone(update_columns);
|
|
|
- checkRecords(*db, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
+ accessor->deleteRecordInZone(update_columns);
|
|
|
+ checkRecords(*accessor, zone_id, "foo.bar.example.com.", expected_stored);
|
|
|
}
|
|
|
|
|
|
TEST_F(SQLite3Update, invalidDelete) {
|
|
|
// An attempt of delete before an explicit start of transaction
|
|
|
- EXPECT_THROW(db->deleteRecordInZone(update_columns), DataSourceError);
|
|
|
+ EXPECT_THROW(accessor->deleteRecordInZone(update_columns), DataSourceError);
|
|
|
|
|
|
// Short column vector
|
|
|
update_columns.clear();
|
|
|
- zone_id = db->startUpdateZone("example.com.", false).second;
|
|
|
- EXPECT_THROW(db->deleteRecordInZone(update_columns), DataSourceError);
|
|
|
+ zone_id = accessor->startUpdateZone("example.com.", false).second;
|
|
|
+ EXPECT_THROW(accessor->deleteRecordInZone(update_columns), DataSourceError);
|
|
|
|
|
|
// Too many parameters
|
|
|
for (int i = 0; i < DatabaseAccessor::DEL_PARAM_COUNT + 1; ++i) {
|
|
|
update_columns.push_back("");
|
|
|
}
|
|
|
- EXPECT_THROW(db->deleteRecordInZone(update_columns), DataSourceError);
|
|
|
+ EXPECT_THROW(accessor->deleteRecordInZone(update_columns), DataSourceError);
|
|
|
}
|
|
|
} // end anonymous namespace
|