OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/thread.h" |
12 #include "base/test/test_file_util.h" | 13 #include "base/test/test_file_util.h" |
13 #include "base/timer.h" | 14 #include "base/timer.h" |
14 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/base/test_completion_callback.h" |
16 #include "net/disk_cache/block_files.h" | 18 #include "net/disk_cache/block_files.h" |
17 #include "net/disk_cache/disk_cache.h" | 19 #include "net/disk_cache/disk_cache.h" |
18 #include "net/disk_cache/disk_cache_test_util.h" | 20 #include "net/disk_cache/disk_cache_test_util.h" |
19 #include "net/disk_cache/hash.h" | 21 #include "net/disk_cache/hash.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
22 | 24 |
23 using base::Time; | 25 using base::Time; |
24 | 26 |
25 extern volatile int g_cache_tests_received; | 27 extern volatile int g_cache_tests_received; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 for (int i = 0; i < 300000; i++) { | 149 for (int i = 0; i < 300000; i++) { |
148 std::string key = GenerateKey(true); | 150 std::string key = GenerateKey(true); |
149 disk_cache::Hash(key); | 151 disk_cache::Hash(key); |
150 } | 152 } |
151 timer.Done(); | 153 timer.Done(); |
152 } | 154 } |
153 | 155 |
154 TEST_F(DiskCacheTest, CacheBackendPerformance) { | 156 TEST_F(DiskCacheTest, CacheBackendPerformance) { |
155 MessageLoopForIO message_loop; | 157 MessageLoopForIO message_loop; |
156 | 158 |
| 159 base::Thread cache_thread("CacheThread"); |
| 160 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 161 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 162 |
157 ScopedTestCache test_cache; | 163 ScopedTestCache test_cache; |
158 disk_cache::Backend* cache = | 164 TestCompletionCallback cb; |
159 disk_cache::CreateCacheBackend(test_cache.path(), false, 0, | 165 disk_cache::Backend* cache; |
160 net::DISK_CACHE); | 166 int rv = disk_cache::CreateCacheBackend( |
161 ASSERT_TRUE(NULL != cache); | 167 net::DISK_CACHE, test_cache.path(), 0, false, |
| 168 cache_thread.message_loop_proxy(), &cache, &cb); |
| 169 |
| 170 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
162 | 171 |
163 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 172 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
164 srand(seed); | 173 srand(seed); |
165 | 174 |
166 TestEntries entries; | 175 TestEntries entries; |
167 int num_entries = 1000; | 176 int num_entries = 1000; |
168 | 177 |
169 int ret = TimeWrite(num_entries, cache, &entries); | 178 int ret = TimeWrite(num_entries, cache, &entries); |
170 EXPECT_EQ(ret, g_cache_tests_received); | 179 EXPECT_EQ(ret, g_cache_tests_received); |
171 | 180 |
172 MessageLoop::current()->RunAllPending(); | 181 MessageLoop::current()->RunAllPending(); |
173 delete cache; | 182 delete cache; |
174 | 183 |
175 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 184 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
176 test_cache.path().AppendASCII("index"))); | 185 test_cache.path().AppendASCII("index"))); |
177 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 186 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
178 test_cache.path().AppendASCII("data_0"))); | 187 test_cache.path().AppendASCII("data_0"))); |
179 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 188 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
180 test_cache.path().AppendASCII("data_1"))); | 189 test_cache.path().AppendASCII("data_1"))); |
181 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 190 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
182 test_cache.path().AppendASCII("data_2"))); | 191 test_cache.path().AppendASCII("data_2"))); |
183 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 192 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
184 test_cache.path().AppendASCII("data_3"))); | 193 test_cache.path().AppendASCII("data_3"))); |
185 | 194 |
186 cache = disk_cache::CreateCacheBackend(test_cache.path(), false, 0, | 195 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), 0, |
187 net::DISK_CACHE); | 196 false, cache_thread.message_loop_proxy(), |
188 ASSERT_TRUE(NULL != cache); | 197 &cache, &cb); |
| 198 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
189 | 199 |
190 ret = TimeRead(num_entries, cache, entries, true); | 200 ret = TimeRead(num_entries, cache, entries, true); |
191 EXPECT_EQ(ret, g_cache_tests_received); | 201 EXPECT_EQ(ret, g_cache_tests_received); |
192 | 202 |
193 ret = TimeRead(num_entries, cache, entries, false); | 203 ret = TimeRead(num_entries, cache, entries, false); |
194 EXPECT_EQ(ret, g_cache_tests_received); | 204 EXPECT_EQ(ret, g_cache_tests_received); |
195 | 205 |
196 MessageLoop::current()->RunAllPending(); | 206 MessageLoop::current()->RunAllPending(); |
197 delete cache; | 207 delete cache; |
198 } | 208 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 | 244 |
235 files.DeleteBlock(address[entry], false); | 245 files.DeleteBlock(address[entry], false); |
236 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), | 246 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), |
237 &address[entry])); | 247 &address[entry])); |
238 } | 248 } |
239 | 249 |
240 timer2.Done(); | 250 timer2.Done(); |
241 MessageLoop::current()->RunAllPending(); | 251 MessageLoop::current()->RunAllPending(); |
242 delete[] address; | 252 delete[] address; |
243 } | 253 } |
OLD | NEW |