BIND 10 trac326, updated. 1820f211d285fcd92e4b18351b9f0fd7e47c3b34 [326] additional test and some docs
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Aug 22 15:12:30 UTC 2011
The branch, trac326 has been updated
via 1820f211d285fcd92e4b18351b9f0fd7e47c3b34 (commit)
from 38d1a8aa943424e1a0de0503ee8aa961a95d0e14 (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 1820f211d285fcd92e4b18351b9f0fd7e47c3b34
Author: Jelte Jansen <jelte at isc.org>
Date: Mon Aug 22 17:12:17 2011 +0200
[326] additional test and some docs
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/sqlite3_accessor.cc | 6 ++-
src/lib/datasrc/tests/sqlite3_accessor_unittest.cc | 64 ++++++++++++++++----
2 files changed, 57 insertions(+), 13 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/sqlite3_accessor.cc b/src/lib/datasrc/sqlite3_accessor.cc
index 229a736..cdb4026 100644
--- a/src/lib/datasrc/sqlite3_accessor.cc
+++ b/src/lib/datasrc/sqlite3_accessor.cc
@@ -201,6 +201,7 @@ void do_sleep() {
// returns the schema version if the schema version table exists
// returns -1 if it does not
+// raises an SQLite3Error if there is a problem querying the db
int check_schema_version(sqlite3* db) {
sqlite3_stmt* prepared = NULL;
// At this point in time, the database might be exclusively locked, in
@@ -229,7 +230,9 @@ int check_schema_version(sqlite3* db) {
return (version);
}
-// return db version
+// Obtains an exclusive lock, checks the database again, and creates
+// the tables if they do not exist yet.
+// Returns the schema version
int create_database(sqlite3* db) {
// try to get an exclusive lock. Once that is obtained, do the version
// check *again*, just in case this process was racing another
@@ -241,6 +244,7 @@ int create_database(sqlite3* db) {
rc = sqlite3_exec(db, "BEGIN EXCLUSIVE TRANSACTION", NULL, NULL,
NULL);
if (rc == SQLITE_OK) {
+ // Lock acquired, move on
break;
} else if (rc != SQLITE_BUSY || i == 50) {
isc_throw(SQLite3Error, "Unable to acquire exclusive lock "
diff --git a/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc b/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc
index 92b8558..e241251 100644
--- a/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc
+++ b/src/lib/datasrc/tests/sqlite3_accessor_unittest.cc
@@ -301,13 +301,35 @@ TEST_F(SQLite3Access, getRecords) {
// and when done
class SQLite3Create : public ::testing::Test {
public:
- SQLite3Create() {
+ SQLite3Create() : db_(NULL) {
remove(SQLITE_NEW_DBFILE);
}
+ int open(const char* dbfile) {
+ return sqlite3_open(dbfile, &db_);
+ }
+
~SQLite3Create() {
+ if (db_ != NULL) {
+ sqlite3_close(db_);
+ }
remove(SQLITE_NEW_DBFILE);
}
+
+ void start_exclusive_transaction() {
+ sqlite3_exec(db_, "BEGIN EXCLUSIVE TRANSACTION", NULL, NULL, NULL);
+ }
+
+ void start_immediate_transaction() {
+ sqlite3_exec(db_, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL);
+ }
+
+ void rollback_transaction() {
+ sqlite3_exec(db_, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
+ }
+
+private:
+ sqlite3* db_;
};
bool exists(const char* filename) {
@@ -325,35 +347,53 @@ TEST_F(SQLite3Create, creationtest) {
TEST_F(SQLite3Create, emptytest) {
ASSERT_FALSE(exists(SQLITE_NEW_DBFILE));
- // open one manualle
- sqlite3* db;
- ASSERT_EQ(SQLITE_OK, sqlite3_open(SQLITE_NEW_DBFILE, &db));
+ ASSERT_EQ(SQLITE_OK, open(SQLITE_NEW_DBFILE));
// empty, but not locked, so creating it now should work
SQLite3Database db2(SQLITE_NEW_DBFILE, RRClass::IN());
+}
- sqlite3_close(db);
+TEST_F(SQLite3Create, lockedtest) {
+ ASSERT_FALSE(exists(SQLITE_NEW_DBFILE));
- // should work now that we closed it
+ ASSERT_EQ(SQLITE_OK, open(SQLITE_NEW_DBFILE));
+
+ start_exclusive_transaction();
+
+ // should not be able to open it
+ EXPECT_THROW(SQLite3Database db2(SQLITE_NEW_DBFILE, RRClass::IN()),
+ SQLite3Error);
+
+ rollback_transaction();
+
+ // should work now that we rolled back
SQLite3Database db3(SQLITE_NEW_DBFILE, RRClass::IN());
}
-TEST_F(SQLite3Create, lockedtest) {
+TEST_F(SQLite3Create, writelockedtest) {
ASSERT_FALSE(exists(SQLITE_NEW_DBFILE));
// open one manually
- sqlite3* db;
- ASSERT_EQ(SQLITE_OK, sqlite3_open(SQLITE_NEW_DBFILE, &db));
- sqlite3_exec(db, "BEGIN EXCLUSIVE TRANSACTION", NULL, NULL, NULL);
+ ASSERT_EQ(SQLITE_OK, open(SQLITE_NEW_DBFILE));
+ start_immediate_transaction();
- // should not be able to open it
+ // should be able to open it, but not create the new tables
EXPECT_THROW(SQLite3Database db2(SQLITE_NEW_DBFILE, RRClass::IN()),
SQLite3Error);
- sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
+ rollback_transaction();
// should work now that we closed it
SQLite3Database db3(SQLITE_NEW_DBFILE, RRClass::IN());
+
+ // and now that the database has been initialized, the exact same sequence
+ // should not fail
+ start_immediate_transaction();
+
+ // should be able to open it, but not create the new tables
+ SQLite3Database db2(SQLITE_NEW_DBFILE, RRClass::IN());
+
+ rollback_transaction();
}
} // end anonymous namespace
More information about the bind10-changes
mailing list