Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: sql/recovery_unittest.cc

Issue 2428383009: [sql] Verify that recover works for multiple page sizes. (Closed)
Patch Set: Switch to EXPECT_NO_FATAL_FAILURE() for context. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sql/recovery.h" 5 #include "sql/recovery.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 ASSERT_FALSE(recovery.get()); 832 ASSERT_FALSE(recovery.get());
833 833
834 ASSERT_TRUE(expecter.SawExpectedErrors()); 834 ASSERT_TRUE(expecter.SawExpectedErrors());
835 } 835 }
836 836
837 // Verify that the failure was in the right place with the expected code. 837 // Verify that the failure was in the right place with the expected code.
838 tester.ExpectBucketCount(kEventHistogramName, kEventEnum, 1); 838 tester.ExpectBucketCount(kEventHistogramName, kEventEnum, 1);
839 tester.ExpectBucketCount(kErrorHistogramName, SQLITE_NOTADB, 1); 839 tester.ExpectBucketCount(kErrorHistogramName, SQLITE_NOTADB, 1);
840 } 840 }
841 841
842 // Helper for SQLRecoveryTest.PageSize. Creates a fresh db based on db_prefix,
843 // with the given initial page size, and verifies it against the expected size.
844 // Then changes to the final page size and recovers, verifying that the
845 // recovered database ends up with the expected final page size.
846 void TestPageSize(const base::FilePath& db_prefix,
847 int initial_page_size,
848 const std::string& expected_initial_page_size,
849 int final_page_size,
850 const std::string& expected_final_page_size) {
851 const char kCreateSql[] = "CREATE TABLE x (t TEXT)";
852 const char kInsertSql1[] = "INSERT INTO x VALUES ('This is a test')";
853 const char kInsertSql2[] = "INSERT INTO x VALUES ('That was a test')";
854 const char kSelectSql[] = "SELECT * FROM x ORDER BY t";
855
856 const base::FilePath db_path = db_prefix.InsertBeforeExtensionASCII(
857 base::IntToString(initial_page_size));
858 sql::Connection::Delete(db_path);
859 sql::Connection db;
860 db.set_page_size(initial_page_size);
861 ASSERT_TRUE(db.Open(db_path));
862 ASSERT_TRUE(db.Execute(kCreateSql));
863 ASSERT_TRUE(db.Execute(kInsertSql1));
864 ASSERT_TRUE(db.Execute(kInsertSql2));
865 ASSERT_EQ(expected_initial_page_size,
866 ExecuteWithResult(&db, "PRAGMA page_size"));
867
868 // Recovery will use the page size set in the connection object, which may not
869 // match the file's page size.
870 db.set_page_size(final_page_size);
871 sql::Recovery::RecoverDatabase(&db, db_path);
872
873 // Recovery poisoned the handle, must re-open.
874 db.Close();
875
876 // Make sure the page size is read from the file.
877 db.set_page_size(0);
878 ASSERT_TRUE(db.Open(db_path));
879 ASSERT_EQ(expected_final_page_size,
880 ExecuteWithResult(&db, "PRAGMA page_size"));
881 EXPECT_EQ("That was a test\nThis is a test",
882 ExecuteWithResults(&db, kSelectSql, "|", "\n"));
883 }
884
885 // Verify that sql::Recovery maintains the page size, and the virtual table
886 // works with page sizes other than SQLite's default. Also verify the case
887 // where the default page size has changed.
888 TEST_F(SQLRecoveryTest, PageSize) {
889 const std::string default_page_size =
890 ExecuteWithResult(&db(), "PRAGMA page_size");
891
892 // The database should have the default page size after recovery.
893 EXPECT_NO_FATAL_FAILURE(
894 TestPageSize(db_path(), 0, default_page_size, 0, default_page_size));
895
896 // Sync user 32k pages.
897 EXPECT_NO_FATAL_FAILURE(
898 TestPageSize(db_path(), 32768, "32768", 32768, "32768"));
899
900 // Many clients use 4k pages. This is the SQLite default after 3.12.0.
901 EXPECT_NO_FATAL_FAILURE(TestPageSize(db_path(), 4096, "4096", 4096, "4096"));
902
903 // 1k is the default page size before 3.12.0.
904 EXPECT_NO_FATAL_FAILURE(TestPageSize(db_path(), 1024, "1024", 1024, "1024"));
905
906 // Databases with no page size specified should recover with the new default
907 // page size. 2k has never been the default page size.
908 ASSERT_NE("2048", default_page_size);
909 EXPECT_NO_FATAL_FAILURE(
910 TestPageSize(db_path(), 2048, "2048", 0, default_page_size));
911 }
912
842 } // namespace 913 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698