Chromium Code Reviews| Index: sql/recovery_unittest.cc |
| diff --git a/sql/recovery_unittest.cc b/sql/recovery_unittest.cc |
| index 02ede5b0463c24f4fae18f9ebfe7992bca1c26c9..4aefe8130d71e030bc3464e6fdf862e105d58488 100644 |
| --- a/sql/recovery_unittest.cc |
| +++ b/sql/recovery_unittest.cc |
| @@ -839,4 +839,87 @@ TEST_F(SQLRecoveryTest, AttachFailure) { |
| tester.ExpectBucketCount(kErrorHistogramName, SQLITE_NOTADB, 1); |
| } |
| +// Verify that sql::Recovery maintains the page size, and the virtual table |
| +// works with page sizes other than SQLite's default. Also verify the case |
| +// where the default page size has changed. |
| +TEST_F(SQLRecoveryTest, PageSize) { |
| + const char kCreateSql[] = "CREATE TABLE x (t TEXT)"; |
| + const char kInsertSql1[] = "INSERT INTO x VALUES ('This is a test')"; |
| + const char kInsertSql2[] = "INSERT INTO x VALUES ('That was a test')"; |
| + const char kSelectSql[] = "SELECT * FROM x ORDER BY t"; |
| + |
| + const std::string default_page_size = |
| + ExecuteWithResult(&db(), "PRAGMA page_size"); |
| + ASSERT_TRUE(db().Execute(kCreateSql)); |
| + ASSERT_TRUE(db().Execute(kInsertSql1)); |
| + ASSERT_TRUE(db().Execute(kInsertSql2)); |
| + sql::Recovery::RecoverDatabase(&db(), db_path()); |
| + ASSERT_TRUE(Reopen()); |
| + EXPECT_EQ(default_page_size, ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + EXPECT_EQ("That was a test\nThis is a test", |
| + ExecuteWithResults(&db(), kSelectSql, "|", "\n")); |
| + |
| + // Sync uses 32k pages. |
| + db().Close(); |
| + sql::Connection::Delete(db_path()); |
| + db().set_page_size(32768); |
| + ASSERT_TRUE(Reopen()); |
| + ASSERT_TRUE(db().Execute(kCreateSql)); |
| + ASSERT_TRUE(db().Execute(kInsertSql1)); |
| + ASSERT_TRUE(db().Execute(kInsertSql2)); |
| + ASSERT_EQ("32768", ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + sql::Recovery::RecoverDatabase(&db(), db_path()); |
| + ASSERT_TRUE(Reopen()); |
| + EXPECT_EQ("32768", ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + EXPECT_EQ("That was a test\nThis is a test", |
| + ExecuteWithResults(&db(), kSelectSql, "|", "\n")); |
| + |
| + // Many clients use 4k pages. This is the SQLite default after 3.12.0. |
|
michaeln
2016/10/25 00:12:26
there's some repetition, maybe have a helper
voi
Scott Hess - ex-Googler
2016/10/26 23:37:38
Since I like having it be obvious which test case
|
| + db().Close(); |
| + sql::Connection::Delete(db_path()); |
| + db().set_page_size(4096); |
| + ASSERT_TRUE(Reopen()); |
| + ASSERT_TRUE(db().Execute(kCreateSql)); |
| + ASSERT_TRUE(db().Execute(kInsertSql1)); |
| + ASSERT_TRUE(db().Execute(kInsertSql2)); |
| + ASSERT_EQ("4096", ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + sql::Recovery::RecoverDatabase(&db(), db_path()); |
| + ASSERT_TRUE(Reopen()); |
| + EXPECT_EQ("4096", ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + EXPECT_EQ("That was a test\nThis is a test", |
| + ExecuteWithResults(&db(), kSelectSql, "|", "\n")); |
| + |
| + // The default page size before 3.12.0. |
| + db().Close(); |
| + sql::Connection::Delete(db_path()); |
| + db().set_page_size(1024); |
| + ASSERT_TRUE(Reopen()); |
| + ASSERT_TRUE(db().Execute(kCreateSql)); |
| + ASSERT_TRUE(db().Execute(kInsertSql1)); |
| + ASSERT_TRUE(db().Execute(kInsertSql2)); |
| + ASSERT_EQ("1024", ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + sql::Recovery::RecoverDatabase(&db(), db_path()); |
| + ASSERT_TRUE(Reopen()); |
| + EXPECT_EQ("1024", ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + EXPECT_EQ("That was a test\nThis is a test", |
| + ExecuteWithResults(&db(), kSelectSql, "|", "\n")); |
| + |
| + // Databases with no page size specified should recover with the new default |
| + // page size. |
| + db().Close(); |
| + sql::Connection::Delete(db_path()); |
| + db().set_page_size(2048); // Not the old or new default. |
| + ASSERT_TRUE(Reopen()); |
| + ASSERT_TRUE(db().Execute(kCreateSql)); |
| + ASSERT_TRUE(db().Execute(kInsertSql1)); |
| + ASSERT_TRUE(db().Execute(kInsertSql2)); |
| + ASSERT_EQ("2048", ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + db().set_page_size(0); |
| + sql::Recovery::RecoverDatabase(&db(), db_path()); |
| + ASSERT_TRUE(Reopen()); |
| + EXPECT_EQ(default_page_size, ExecuteWithResult(&db(), "PRAGMA page_size")); |
| + EXPECT_EQ("That was a test\nThis is a test", |
| + ExecuteWithResults(&db(), kSelectSql, "|", "\n")); |
| +} |
| + |
| } // namespace |