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

Side by Side Diff: sql/recovery_unittest.cc

Issue 2428383009: [sql] Verify that recover works for multiple page sizes. (Closed)
Patch Set: Created 4 years, 2 months 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 // Verify that sql::Recovery maintains the page size, and the virtual table
843 // works with page sizes other than SQLite's default. Also verify the case
844 // where the default page size has changed.
845 TEST_F(SQLRecoveryTest, PageSize) {
846 const char kCreateSql[] = "CREATE TABLE x (t TEXT)";
847 const char kInsertSql1[] = "INSERT INTO x VALUES ('This is a test')";
848 const char kInsertSql2[] = "INSERT INTO x VALUES ('That was a test')";
849 const char kSelectSql[] = "SELECT * FROM x ORDER BY t";
850
851 const std::string default_page_size =
852 ExecuteWithResult(&db(), "PRAGMA page_size");
853 ASSERT_TRUE(db().Execute(kCreateSql));
854 ASSERT_TRUE(db().Execute(kInsertSql1));
855 ASSERT_TRUE(db().Execute(kInsertSql2));
856 sql::Recovery::RecoverDatabase(&db(), db_path());
857 ASSERT_TRUE(Reopen());
858 EXPECT_EQ(default_page_size, ExecuteWithResult(&db(), "PRAGMA page_size"));
859 EXPECT_EQ("That was a test\nThis is a test",
860 ExecuteWithResults(&db(), kSelectSql, "|", "\n"));
861
862 // Sync uses 32k pages.
863 db().Close();
864 sql::Connection::Delete(db_path());
865 db().set_page_size(32768);
866 ASSERT_TRUE(Reopen());
867 ASSERT_TRUE(db().Execute(kCreateSql));
868 ASSERT_TRUE(db().Execute(kInsertSql1));
869 ASSERT_TRUE(db().Execute(kInsertSql2));
870 ASSERT_EQ("32768", ExecuteWithResult(&db(), "PRAGMA page_size"));
871 sql::Recovery::RecoverDatabase(&db(), db_path());
872 ASSERT_TRUE(Reopen());
873 EXPECT_EQ("32768", ExecuteWithResult(&db(), "PRAGMA page_size"));
874 EXPECT_EQ("That was a test\nThis is a test",
875 ExecuteWithResults(&db(), kSelectSql, "|", "\n"));
876
877 // 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
878 db().Close();
879 sql::Connection::Delete(db_path());
880 db().set_page_size(4096);
881 ASSERT_TRUE(Reopen());
882 ASSERT_TRUE(db().Execute(kCreateSql));
883 ASSERT_TRUE(db().Execute(kInsertSql1));
884 ASSERT_TRUE(db().Execute(kInsertSql2));
885 ASSERT_EQ("4096", ExecuteWithResult(&db(), "PRAGMA page_size"));
886 sql::Recovery::RecoverDatabase(&db(), db_path());
887 ASSERT_TRUE(Reopen());
888 EXPECT_EQ("4096", ExecuteWithResult(&db(), "PRAGMA page_size"));
889 EXPECT_EQ("That was a test\nThis is a test",
890 ExecuteWithResults(&db(), kSelectSql, "|", "\n"));
891
892 // The default page size before 3.12.0.
893 db().Close();
894 sql::Connection::Delete(db_path());
895 db().set_page_size(1024);
896 ASSERT_TRUE(Reopen());
897 ASSERT_TRUE(db().Execute(kCreateSql));
898 ASSERT_TRUE(db().Execute(kInsertSql1));
899 ASSERT_TRUE(db().Execute(kInsertSql2));
900 ASSERT_EQ("1024", ExecuteWithResult(&db(), "PRAGMA page_size"));
901 sql::Recovery::RecoverDatabase(&db(), db_path());
902 ASSERT_TRUE(Reopen());
903 EXPECT_EQ("1024", ExecuteWithResult(&db(), "PRAGMA page_size"));
904 EXPECT_EQ("That was a test\nThis is a test",
905 ExecuteWithResults(&db(), kSelectSql, "|", "\n"));
906
907 // Databases with no page size specified should recover with the new default
908 // page size.
909 db().Close();
910 sql::Connection::Delete(db_path());
911 db().set_page_size(2048); // Not the old or new default.
912 ASSERT_TRUE(Reopen());
913 ASSERT_TRUE(db().Execute(kCreateSql));
914 ASSERT_TRUE(db().Execute(kInsertSql1));
915 ASSERT_TRUE(db().Execute(kInsertSql2));
916 ASSERT_EQ("2048", ExecuteWithResult(&db(), "PRAGMA page_size"));
917 db().set_page_size(0);
918 sql::Recovery::RecoverDatabase(&db(), db_path());
919 ASSERT_TRUE(Reopen());
920 EXPECT_EQ(default_page_size, ExecuteWithResult(&db(), "PRAGMA page_size"));
921 EXPECT_EQ("That was a test\nThis is a test",
922 ExecuteWithResults(&db(), kSelectSql, "|", "\n"));
923 }
924
842 } // namespace 925 } // 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