OLD | NEW |
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/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_file.h" | 10 #include "base/files/scoped_file.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 ScopedMockTimeSource& owner_; | 67 ScopedMockTimeSource& owner_; |
68 DISALLOW_COPY_AND_ASSIGN(MockTimeSource); | 68 DISALLOW_COPY_AND_ASSIGN(MockTimeSource); |
69 }; | 69 }; |
70 | 70 |
71 Connection& db_; | 71 Connection& db_; |
72 | 72 |
73 // Saves original source from |db_|. | 73 // Saves original source from |db_|. |
74 scoped_ptr<TimeSource> save_; | 74 std::unique_ptr<TimeSource> save_; |
75 | 75 |
76 // Current time returned by mock. | 76 // Current time returned by mock. |
77 base::TimeTicks current_time_; | 77 base::TimeTicks current_time_; |
78 | 78 |
79 // How far to jump on each Now() call. | 79 // How far to jump on each Now() call. |
80 base::TimeDelta delta_; | 80 base::TimeDelta delta_; |
81 | 81 |
82 DISALLOW_COPY_AND_ASSIGN(ScopedMockTimeSource); | 82 DISALLOW_COPY_AND_ASSIGN(ScopedMockTimeSource); |
83 }; | 83 }; |
84 | 84 |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 EXPECT_TRUE(db().Execute(kCreateSql)); | 1201 EXPECT_TRUE(db().Execute(kCreateSql)); |
1202 | 1202 |
1203 // Function to inject pauses into statements. | 1203 // Function to inject pauses into statements. |
1204 sql::test::ScopedScalarFunction scoper( | 1204 sql::test::ScopedScalarFunction scoper( |
1205 db(), "milliadjust", 1, base::Bind(&sqlite_adjust_millis, &time_mock)); | 1205 db(), "milliadjust", 1, base::Bind(&sqlite_adjust_millis, &time_mock)); |
1206 | 1206 |
1207 base::HistogramTester tester; | 1207 base::HistogramTester tester; |
1208 | 1208 |
1209 EXPECT_TRUE(db().Execute("SELECT milliadjust(10)")); | 1209 EXPECT_TRUE(db().Execute("SELECT milliadjust(10)")); |
1210 | 1210 |
1211 scoped_ptr<base::HistogramSamples> samples( | 1211 std::unique_ptr<base::HistogramSamples> samples( |
1212 tester.GetHistogramSamplesSinceCreation(kQueryTime)); | 1212 tester.GetHistogramSamplesSinceCreation(kQueryTime)); |
1213 ASSERT_TRUE(samples); | 1213 ASSERT_TRUE(samples); |
1214 // 10 for the adjust, 1 for the measurement. | 1214 // 10 for the adjust, 1 for the measurement. |
1215 EXPECT_EQ(11, samples->sum()); | 1215 EXPECT_EQ(11, samples->sum()); |
1216 | 1216 |
1217 samples = tester.GetHistogramSamplesSinceCreation(kUpdateTime); | 1217 samples = tester.GetHistogramSamplesSinceCreation(kUpdateTime); |
1218 EXPECT_EQ(0, samples->sum()); | 1218 EXPECT_EQ(0, samples->sum()); |
1219 | 1219 |
1220 samples = tester.GetHistogramSamplesSinceCreation(kCommitTime); | 1220 samples = tester.GetHistogramSamplesSinceCreation(kCommitTime); |
1221 EXPECT_EQ(0, samples->sum()); | 1221 EXPECT_EQ(0, samples->sum()); |
(...skipping 17 matching lines...) Expand all Loading... |
1239 EXPECT_TRUE(db().Execute(kCreateSql)); | 1239 EXPECT_TRUE(db().Execute(kCreateSql)); |
1240 | 1240 |
1241 // Function to inject pauses into statements. | 1241 // Function to inject pauses into statements. |
1242 sql::test::ScopedScalarFunction scoper( | 1242 sql::test::ScopedScalarFunction scoper( |
1243 db(), "milliadjust", 1, base::Bind(&sqlite_adjust_millis, &time_mock)); | 1243 db(), "milliadjust", 1, base::Bind(&sqlite_adjust_millis, &time_mock)); |
1244 | 1244 |
1245 base::HistogramTester tester; | 1245 base::HistogramTester tester; |
1246 | 1246 |
1247 EXPECT_TRUE(db().Execute("INSERT INTO foo VALUES (10, milliadjust(10))")); | 1247 EXPECT_TRUE(db().Execute("INSERT INTO foo VALUES (10, milliadjust(10))")); |
1248 | 1248 |
1249 scoped_ptr<base::HistogramSamples> samples( | 1249 std::unique_ptr<base::HistogramSamples> samples( |
1250 tester.GetHistogramSamplesSinceCreation(kQueryTime)); | 1250 tester.GetHistogramSamplesSinceCreation(kQueryTime)); |
1251 ASSERT_TRUE(samples); | 1251 ASSERT_TRUE(samples); |
1252 // 10 for the adjust, 1 for the measurement. | 1252 // 10 for the adjust, 1 for the measurement. |
1253 EXPECT_EQ(11, samples->sum()); | 1253 EXPECT_EQ(11, samples->sum()); |
1254 | 1254 |
1255 samples = tester.GetHistogramSamplesSinceCreation(kUpdateTime); | 1255 samples = tester.GetHistogramSamplesSinceCreation(kUpdateTime); |
1256 ASSERT_TRUE(samples); | 1256 ASSERT_TRUE(samples); |
1257 // 10 for the adjust, 1 for the measurement. | 1257 // 10 for the adjust, 1 for the measurement. |
1258 EXPECT_EQ(11, samples->sum()); | 1258 EXPECT_EQ(11, samples->sum()); |
1259 | 1259 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 sql::test::ScopedCommitHook scoped_hook( | 1291 sql::test::ScopedCommitHook scoped_hook( |
1292 db(), base::Bind(adjust_commit_hook, &time_mock, 100)); | 1292 db(), base::Bind(adjust_commit_hook, &time_mock, 100)); |
1293 ASSERT_TRUE(db().BeginTransaction()); | 1293 ASSERT_TRUE(db().BeginTransaction()); |
1294 EXPECT_TRUE(db().Execute( | 1294 EXPECT_TRUE(db().Execute( |
1295 "INSERT INTO foo VALUES (11, milliadjust(10))")); | 1295 "INSERT INTO foo VALUES (11, milliadjust(10))")); |
1296 EXPECT_TRUE(db().Execute( | 1296 EXPECT_TRUE(db().Execute( |
1297 "UPDATE foo SET value = milliadjust(10) WHERE id = 11")); | 1297 "UPDATE foo SET value = milliadjust(10) WHERE id = 11")); |
1298 EXPECT_TRUE(db().CommitTransaction()); | 1298 EXPECT_TRUE(db().CommitTransaction()); |
1299 } | 1299 } |
1300 | 1300 |
1301 scoped_ptr<base::HistogramSamples> samples( | 1301 std::unique_ptr<base::HistogramSamples> samples( |
1302 tester.GetHistogramSamplesSinceCreation(kQueryTime)); | 1302 tester.GetHistogramSamplesSinceCreation(kQueryTime)); |
1303 ASSERT_TRUE(samples); | 1303 ASSERT_TRUE(samples); |
1304 // 10 for insert adjust, 10 for update adjust, 100 for commit adjust, 1 for | 1304 // 10 for insert adjust, 10 for update adjust, 100 for commit adjust, 1 for |
1305 // measuring each of BEGIN, INSERT, UPDATE, and COMMIT. | 1305 // measuring each of BEGIN, INSERT, UPDATE, and COMMIT. |
1306 EXPECT_EQ(124, samples->sum()); | 1306 EXPECT_EQ(124, samples->sum()); |
1307 | 1307 |
1308 samples = tester.GetHistogramSamplesSinceCreation(kUpdateTime); | 1308 samples = tester.GetHistogramSamplesSinceCreation(kUpdateTime); |
1309 ASSERT_TRUE(samples); | 1309 ASSERT_TRUE(samples); |
1310 // 10 for insert adjust, 10 for update adjust, 100 for commit adjust, 1 for | 1310 // 10 for insert adjust, 10 for update adjust, 100 for commit adjust, 1 for |
1311 // measuring each of INSERT, UPDATE, and COMMIT. | 1311 // measuring each of INSERT, UPDATE, and COMMIT. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 // With no key, map everything and create the key. | 1482 // With no key, map everything and create the key. |
1483 // TODO(shess): This really should be "maps everything after validating it", | 1483 // TODO(shess): This really should be "maps everything after validating it", |
1484 // but that is more complicated to structure. | 1484 // but that is more complicated to structure. |
1485 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); | 1485 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
1486 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); | 1486 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); |
1487 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); | 1487 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); |
1488 } | 1488 } |
1489 #endif | 1489 #endif |
1490 | 1490 |
1491 } // namespace sql | 1491 } // namespace sql |
OLD | NEW |