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

Side by Side Diff: sql/connection_unittest.cc

Issue 2728543008: [sql] Experiment to enable smart-vacuum on Android.
Patch Set: Just read page size. Created 3 years, 8 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 | « sql/connection.cc ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/feature_list.h"
9 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
10 #include "base/files/scoped_file.h" 11 #include "base/files/scoped_file.h"
11 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/test/histogram_tester.h" 16 #include "base/test/histogram_tester.h"
17 #include "base/test/scoped_feature_list.h"
16 #include "base/trace_event/process_memory_dump.h" 18 #include "base/trace_event/process_memory_dump.h"
17 #include "sql/connection.h" 19 #include "sql/connection.h"
18 #include "sql/connection_memory_dump_provider.h" 20 #include "sql/connection_memory_dump_provider.h"
19 #include "sql/correct_sql_test_base.h" 21 #include "sql/correct_sql_test_base.h"
20 #include "sql/meta_table.h" 22 #include "sql/meta_table.h"
21 #include "sql/statement.h" 23 #include "sql/statement.h"
22 #include "sql/test/error_callback_support.h" 24 #include "sql/test/error_callback_support.h"
23 #include "sql/test/scoped_error_expecter.h" 25 #include "sql/test/scoped_error_expecter.h"
24 #include "sql/test/test_helpers.h" 26 #include "sql/test/test_helpers.h"
25 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 #if !defined(OS_ANDROID) && !defined(OS_IOS) 1627 #if !defined(OS_ANDROID) && !defined(OS_IOS)
1626 if (DLOG_IS_ON(FATAL)) { 1628 if (DLOG_IS_ON(FATAL)) {
1627 db().set_error_callback(base::Bind(&IgnoreErrorCallback)); 1629 db().set_error_callback(base::Bind(&IgnoreErrorCallback));
1628 ASSERT_DEATH({ 1630 ASSERT_DEATH({
1629 db().GetUniqueStatement("SELECT x"); 1631 db().GetUniqueStatement("SELECT x");
1630 }, "SQL compile error no such column: x"); 1632 }, "SQL compile error no such column: x");
1631 } 1633 }
1632 #endif 1634 #endif
1633 } 1635 }
1634 1636
1637 #if !defined(USE_SYSTEM_SQLITE)
1638 // Test that smart-autovacuum is enabled appropriately.
1639 // http://crbug.com/698010
1640 TEST_F(SQLConnectionTest, SmartAutoVacuumChunks) {
1641 // Explicitly turn on auto_vacuum so that this works the same on all
1642 // platforms, and set the page size low to make results obvious. These
1643 // settings require re-writing the database, which VACUUM does.
1644 ASSERT_TRUE(db().Execute("PRAGMA auto_vacuum = FULL"));
1645 ASSERT_TRUE(db().Execute("PRAGMA page_size = 1024"));
1646 ASSERT_TRUE(db().Execute("VACUUM"));
1647
1648 // With page_size=1024, the following will insert rows which take up an
1649 // overflow page, plus a small header in a b-tree node. An empty table takes
1650 // a single page, so for small row counts each insert will add one page.
1651 const char kCreateSql[] = "CREATE TABLE t (id INTEGER PRIMARY KEY, value)";
1652 const char kInsertSql[] = "INSERT INTO t (value) VALUES (randomblob(980))";
1653
1654 // This database will be 34 overflow pages plus the table's root page plus the
1655 // SQLite header page plus the freelist page.
1656 ASSERT_TRUE(db().Execute(kCreateSql));
1657 {
1658 sql::Statement s(db().GetUniqueStatement(kInsertSql));
1659 for (int i = 0; i < 34; ++i) {
1660 s.Reset(true);
1661 ASSERT_TRUE(s.Run());
1662 }
1663 }
1664 ASSERT_EQ("37", sql::test::ExecuteWithResult(&db(), "PRAGMA page_count"));
1665
1666 // Matches connection.cc.
1667 // TODO(shess): Should this be shared?
1668 const base::Feature kFeature{"SqliteSmartAutoVacuum",
1669 base::FEATURE_DISABLED_BY_DEFAULT};
1670
1671 const char kPragma[] = "PRAGMA auto_vacuum_slack_pages";
1672
1673 // Give Open() a chance to set the pragma with the feature disabled.
1674 {
1675 base::test::ScopedFeatureList fl;
1676 fl.InitAndDisableFeature(kFeature);
1677 db().Close();
1678 db().set_page_size(1024);
1679 ASSERT_TRUE(db().Open(db_path()));
1680
1681 ASSERT_EQ("0", sql::test::ExecuteWithResult(&db(), kPragma));
1682 }
1683
1684 // Give Open() a chance to set the pragma with the feature enabled.
1685 {
1686 base::test::ScopedFeatureList fl;
1687 fl.InitAndEnableFeature(kFeature);
1688 db().Close();
1689 db().set_page_size(1024);
1690 ASSERT_TRUE(db().Open(db_path()));
1691
1692 ASSERT_EQ("4", sql::test::ExecuteWithResult(&db(), kPragma));
1693 }
1694 }
1695 #endif // !defined(USE_SYSTEM_SQLITE)
1696
1635 } // namespace sql 1697 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698