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

Side by Side Diff: third_party/leveldatabase/env_chromium_unittest.cc

Issue 2243363002: IndexedDB: Limit the size of a leveldb write buffer to minimize disk space. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/files/file.h" 5 #include "base/files/file.h"
6 #include "base/files/file_enumerator.h" 6 #include "base/files/file_enumerator.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/test/test_suite.h" 11 #include "base/test/test_suite.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/leveldatabase/env_chromium.h" 13 #include "third_party/leveldatabase/env_chromium.h"
14 #include "third_party/leveldatabase/src/include/leveldb/db.h" 14 #include "third_party/leveldatabase/src/include/leveldb/db.h"
15 15
16 #define FPL FILE_PATH_LITERAL 16 #define FPL FILE_PATH_LITERAL
17 17
18 using leveldb::DB; 18 using leveldb::DB;
19 using leveldb::Env; 19 using leveldb::Env;
20 using leveldb::Options; 20 using leveldb::Options;
21 using leveldb::ReadOptions; 21 using leveldb::ReadOptions;
22 using leveldb::Slice; 22 using leveldb::Slice;
23 using leveldb::Status; 23 using leveldb::Status;
24 using leveldb::WritableFile; 24 using leveldb::WritableFile;
25 using leveldb::WriteOptions; 25 using leveldb::WriteOptions;
26 using leveldb_env::ChromiumEnv; 26 using leveldb_env::ChromiumEnv;
27 using leveldb_env::MethodID; 27 using leveldb_env::MethodID;
28 28
29 namespace leveldb_env {
30 extern size_t WriteBufferSize(int64_t disk_space);
michaeln 2016/08/16 00:28:05 Is including env_chromium.h not enough, the functi
cmumford 2016/08/16 00:54:26 I overloaded WriteBuferSize and this is the versio
michaeln 2016/08/16 19:41:23 or maybe expose both functions in the .h file inst
31 }
32
29 TEST(ErrorEncoding, OnlyAMethod) { 33 TEST(ErrorEncoding, OnlyAMethod) {
30 const MethodID in_method = leveldb_env::kSequentialFileRead; 34 const MethodID in_method = leveldb_env::kSequentialFileRead;
31 const Status s = MakeIOError("Somefile.txt", "message", in_method); 35 const Status s = MakeIOError("Somefile.txt", "message", in_method);
32 MethodID method; 36 MethodID method;
33 base::File::Error error = base::File::FILE_ERROR_MAX; 37 base::File::Error error = base::File::FILE_ERROR_MAX;
34 EXPECT_EQ(leveldb_env::METHOD_ONLY, ParseMethodAndError(s, &method, &error)); 38 EXPECT_EQ(leveldb_env::METHOD_ONLY, ParseMethodAndError(s, &method, &error));
35 EXPECT_EQ(in_method, method); 39 EXPECT_EQ(in_method, method);
36 EXPECT_EQ(base::File::FILE_ERROR_MAX, error); 40 EXPECT_EQ(base::File::FILE_ERROR_MAX, error);
37 } 41 }
38 42
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); 166 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result);
163 EXPECT_TRUE(status.ok()); 167 EXPECT_TRUE(status.ok());
164 EXPECT_EQ(1U, result.size()); 168 EXPECT_EQ(1U, result.size());
165 169
166 // And a second time should also return one result 170 // And a second time should also return one result
167 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); 171 status = env->GetChildren(dir.AsUTF8Unsafe(), &result);
168 EXPECT_TRUE(status.ok()); 172 EXPECT_TRUE(status.ok());
169 EXPECT_EQ(1U, result.size()); 173 EXPECT_EQ(1U, result.size());
170 } 174 }
171 175
176 TEST(ChromiumEnv, TestWriteBufferSize) {
177 // If can't get disk size, use leveldb defaults.
178 const int64_t MB = 1024 * 1024;
179 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(-1));
180
181 // A very small disk (check lower clamp value).
182 EXPECT_EQ(size_t(1 * MB), leveldb_env::WriteBufferSize(1 * MB));
183
184 // Some value on the linear equation between min and max.
185 EXPECT_EQ(size_t(2.5 * MB), leveldb_env::WriteBufferSize(25 * MB));
186
187 // The disk size equating to the max buffer size
188 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(40 * MB));
189
190 // Make sure sizes larger than 40MB are clamped to max buffer size.
191 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(80 * MB));
192
193 // Check for very large disk size (catch overflow).
194 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(100 * MB * MB));
195 }
196
172 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } 197 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698