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

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 1715833002: Reland: Refactor and shorten in-memory cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in comment Created 4 years, 10 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) 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/test/mock_entropy_provider.h" 14 #include "base/test/mock_entropy_provider.h"
14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 15 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "base/threading/platform_thread.h" 17 #include "base/threading/platform_thread.h"
17 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
18 #include "net/base/cache_type.h" 19 #include "net/base/cache_type.h"
19 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 void BackendTrimInvalidEntry12(); 130 void BackendTrimInvalidEntry12();
130 void BackendDoomAll(); 131 void BackendDoomAll();
131 void BackendDoomAll2(); 132 void BackendDoomAll2();
132 void BackendInvalidRankings(); 133 void BackendInvalidRankings();
133 void BackendInvalidRankings2(); 134 void BackendInvalidRankings2();
134 void BackendDisable(); 135 void BackendDisable();
135 void BackendDisable2(); 136 void BackendDisable2();
136 void BackendDisable3(); 137 void BackendDisable3();
137 void BackendDisable4(); 138 void BackendDisable4();
138 void BackendDisabledAPI(); 139 void BackendDisabledAPI();
140
141 void BackendEviction();
139 }; 142 };
140 143
141 int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) { 144 int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) {
142 if (!use_current_thread_) { 145 if (!use_current_thread_) {
143 ADD_FAILURE(); 146 ADD_FAILURE();
144 return net::ERR_FAILED; 147 return net::ERR_FAILED;
145 } 148 }
146 149
147 disk_cache::Entry* entry; 150 disk_cache::Entry* entry;
148 int rv = cache_->CreateEntry("some key", &entry, cb->callback()); 151 int rv = cache_->CreateEntry("some key", &entry, cb->callback());
(...skipping 2745 matching lines...) Expand 10 before | Expand all | Expand 10 after
2894 } 2897 }
2895 2898
2896 TEST_F(DiskCacheBackendTest, NewEvictionDisabledAPI) { 2899 TEST_F(DiskCacheBackendTest, NewEvictionDisabledAPI) {
2897 ASSERT_TRUE(CopyTestCache("bad_rankings2")); 2900 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
2898 DisableFirstCleanup(); 2901 DisableFirstCleanup();
2899 SetNewEviction(); 2902 SetNewEviction();
2900 InitCache(); 2903 InitCache();
2901 BackendDisabledAPI(); 2904 BackendDisabledAPI();
2902 } 2905 }
2903 2906
2907 // Test that some eviction of some kind happens.
2908 void DiskCacheBackendTest::BackendEviction() {
2909 const int kMaxSize = 200 * 1024;
2910 const int kMaxEntryCount = 20;
2911 const int kWriteSize = kMaxSize / kMaxEntryCount;
2912
2913 const int kWriteEntryCount = kMaxEntryCount * 2;
2914
2915 static_assert(kWriteEntryCount * kWriteSize > kMaxSize,
2916 "must write more than MaxSize");
2917
2918 SetMaxSize(kMaxSize);
2919 InitSparseCache(nullptr, nullptr);
2920
2921 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kWriteSize));
2922 CacheTestFillBuffer(buffer->data(), kWriteSize, false);
2923
2924 std::string key_prefix("prefix");
2925 for (int i = 0; i < kWriteEntryCount; ++i) {
2926 AddDelay();
2927 disk_cache::Entry* entry = NULL;
2928 ASSERT_EQ(net::OK, CreateEntry(key_prefix + base::IntToString(i), &entry));
2929 disk_cache::ScopedEntryPtr entry_closer(entry);
2930 EXPECT_EQ(kWriteSize,
2931 WriteData(entry, 1, 0, buffer.get(), kWriteSize, false));
2932 }
2933
2934 int size = CalculateSizeOfAllEntries();
2935 EXPECT_GT(kMaxSize, size);
2936 }
2937
2938 TEST_F(DiskCacheBackendTest, BackendEviction) {
2939 BackendEviction();
2940 }
2941
2942 TEST_F(DiskCacheBackendTest, MemoryOnlyBackendEviction) {
2943 SetMemoryOnlyMode();
2944 BackendEviction();
2945 }
2946
2947 // TODO(gavinp): Enable BackendEviction test for simple cache after performance
2948 // problems are addressed. See crbug.com/588184 for more information.
2949
2904 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) { 2950 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) {
2905 MessageLoopHelper helper; 2951 MessageLoopHelper helper;
2906 2952
2907 ASSERT_TRUE(CleanupCacheDir()); 2953 ASSERT_TRUE(CleanupCacheDir());
2908 scoped_ptr<disk_cache::BackendImpl> cache; 2954 scoped_ptr<disk_cache::BackendImpl> cache;
2909 cache.reset(new disk_cache::BackendImpl( 2955 cache.reset(new disk_cache::BackendImpl(
2910 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL)); 2956 cache_path_, base::ThreadTaskRunnerHandle::Get(), NULL));
2911 ASSERT_TRUE(NULL != cache.get()); 2957 ASSERT_TRUE(NULL != cache.get());
2912 cache->SetUnitTestMode(); 2958 cache->SetUnitTestMode();
2913 ASSERT_EQ(net::OK, cache->SyncInit()); 2959 ASSERT_EQ(net::OK, cache->SyncInit());
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
3657 // after closing. 3703 // after closing.
3658 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940 3704 // NOTE: IF THIS TEST IS FLAKY THEN IT IS FAILING. See https://crbug.com/416940
3659 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) { 3705 TEST_F(DiskCacheBackendTest, SimpleCacheDeleteQuickly) {
3660 SetSimpleCacheMode(); 3706 SetSimpleCacheMode();
3661 for (int i = 0; i < 100; ++i) { 3707 for (int i = 0; i < 100; ++i) {
3662 InitCache(); 3708 InitCache();
3663 cache_.reset(); 3709 cache_.reset();
3664 EXPECT_TRUE(CleanupCacheDir()); 3710 EXPECT_TRUE(CleanupCacheDir());
3665 } 3711 }
3666 } 3712 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/entry_unittest.cc » ('j') | net/disk_cache/memory/mem_entry_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698