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

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

Issue 2874833005: SimpleCache: read small files all at once. (Closed)
Patch Set: Tweak histogram description based on feedback Created 3 years, 3 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 | « no previous file | net/disk_cache/simple/simple_entry_impl.h » ('j') | 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 <utility> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/metrics/field_trial.h"
13 #include "base/metrics/field_trial_param_associator.h"
12 #include "base/run_loop.h" 14 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
15 #include "base/test/histogram_tester.h" 17 #include "base/test/histogram_tester.h"
18 #include "base/test/mock_entropy_provider.h"
19 #include "base/test/scoped_feature_list.h"
16 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
17 #include "net/base/completion_callback.h" 21 #include "net/base/completion_callback.h"
18 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
19 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
20 #include "net/base/test_completion_callback.h" 24 #include "net/base/test_completion_callback.h"
21 #include "net/disk_cache/blockfile/backend_impl.h" 25 #include "net/disk_cache/blockfile/backend_impl.h"
22 #include "net/disk_cache/blockfile/entry_impl.h" 26 #include "net/disk_cache/blockfile/entry_impl.h"
23 #include "net/disk_cache/cache_util.h" 27 #include "net/disk_cache/cache_util.h"
24 #include "net/disk_cache/disk_cache_test_base.h" 28 #include "net/disk_cache/disk_cache_test_base.h"
25 #include "net/disk_cache/disk_cache_test_util.h" 29 #include "net/disk_cache/disk_cache_test_util.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void DoomNormalEntry(); 72 void DoomNormalEntry();
69 void DoomEntryNextToOpenEntry(); 73 void DoomEntryNextToOpenEntry();
70 void DoomedEntry(int stream_index); 74 void DoomedEntry(int stream_index);
71 void BasicSparseIO(); 75 void BasicSparseIO();
72 void HugeSparseIO(); 76 void HugeSparseIO();
73 void GetAvailableRange(); 77 void GetAvailableRange();
74 void CouldBeSparse(); 78 void CouldBeSparse();
75 void UpdateSparseEntry(); 79 void UpdateSparseEntry();
76 void DoomSparseEntry(); 80 void DoomSparseEntry();
77 void PartialSparseEntry(); 81 void PartialSparseEntry();
78 bool SimpleCacheMakeBadChecksumEntry(const std::string& key, int* data_size); 82 bool SimpleCacheMakeBadChecksumEntry(const std::string& key, int data_size);
79 bool SimpleCacheThirdStreamFileExists(const char* key); 83 bool SimpleCacheThirdStreamFileExists(const char* key);
80 void SyncDoomEntry(const char* key); 84 void SyncDoomEntry(const char* key);
81 }; 85 };
82 86
83 // This part of the test runs on the background thread. 87 // This part of the test runs on the background thread.
84 void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) { 88 void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) {
85 const int kSize1 = 10; 89 const int kSize1 = 10;
86 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); 90 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1));
87 CacheTestFillBuffer(buffer1->data(), kSize1, false); 91 CacheTestFillBuffer(buffer1->data(), kSize1, false);
88 EXPECT_EQ( 92 EXPECT_EQ(
(...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after
2625 // it on a doomed entry, if it was previously lazily omitted. 2629 // it on a doomed entry, if it was previously lazily omitted.
2626 for (int i = 0; i < disk_cache::kSimpleEntryStreamCount - 1; ++i) { 2630 for (int i = 0; i < disk_cache::kSimpleEntryStreamCount - 1; ++i) {
2627 EXPECT_THAT(DoomAllEntries(), IsOk()); 2631 EXPECT_THAT(DoomAllEntries(), IsOk());
2628 DoomedEntry(i); 2632 DoomedEntry(i);
2629 } 2633 }
2630 } 2634 }
2631 2635
2632 // Creates an entry with corrupted last byte in stream 0. 2636 // Creates an entry with corrupted last byte in stream 0.
2633 // Requires SimpleCacheMode. 2637 // Requires SimpleCacheMode.
2634 bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key, 2638 bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key,
2635 int* data_size) { 2639 int data_size) {
2636 disk_cache::Entry* entry = NULL; 2640 disk_cache::Entry* entry = NULL;
2637 2641
2638 if (CreateEntry(key, &entry) != net::OK || !entry) { 2642 if (CreateEntry(key, &entry) != net::OK || !entry) {
2639 LOG(ERROR) << "Could not create entry"; 2643 LOG(ERROR) << "Could not create entry";
2640 return false; 2644 return false;
2641 } 2645 }
2642 2646
2643 const char data[] = "this is very good data"; 2647 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(data_size));
2644 const int kDataSize = arraysize(data); 2648 memset(buffer->data(), 'A', data_size);
2645 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kDataSize));
2646 base::strlcpy(buffer->data(), data, kDataSize);
2647 2649
2648 EXPECT_EQ(kDataSize, WriteData(entry, 1, 0, buffer.get(), kDataSize, false)); 2650 EXPECT_EQ(data_size, WriteData(entry, 1, 0, buffer.get(), data_size, false));
2649 entry->Close(); 2651 entry->Close();
2650 entry = NULL; 2652 entry = NULL;
2651 2653
2652 // Corrupt the last byte of the data. 2654 // Corrupt the last byte of the data.
2653 base::FilePath entry_file0_path = cache_path_.AppendASCII( 2655 base::FilePath entry_file0_path = cache_path_.AppendASCII(
2654 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); 2656 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
2655 base::File entry_file0(entry_file0_path, 2657 base::File entry_file0(entry_file0_path,
2656 base::File::FLAG_WRITE | base::File::FLAG_OPEN); 2658 base::File::FLAG_WRITE | base::File::FLAG_OPEN);
2657 if (!entry_file0.IsValid()) 2659 if (!entry_file0.IsValid())
2658 return false; 2660 return false;
2659 2661
2660 int64_t file_offset = 2662 int64_t file_offset =
2661 sizeof(disk_cache::SimpleFileHeader) + key.size() + kDataSize - 2; 2663 sizeof(disk_cache::SimpleFileHeader) + key.size() + data_size - 2;
2662 EXPECT_EQ(1, entry_file0.Write(file_offset, "X", 1)); 2664 EXPECT_EQ(1, entry_file0.Write(file_offset, "X", 1));
2663 *data_size = kDataSize;
2664 return true; 2665 return true;
2665 } 2666 }
2666 2667
2667 // Tests that the simple cache can detect entries that have bad data.
2668 TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksum) { 2668 TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksum) {
2669 base::HistogramTester histogram_tester; 2669 base::HistogramTester histogram_tester;
2670 SetSimpleCacheMode(); 2670 SetSimpleCacheMode();
2671 InitCache(); 2671 InitCache();
2672 2672
2673 const char key[] = "the first key"; 2673 const char key[] = "the first key";
2674 int size_unused; 2674 const int kLargeSize = 50000;
2675 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size_unused)); 2675 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, kLargeSize));
2676 2676
2677 disk_cache::Entry* entry = NULL; 2677 disk_cache::Entry* entry = NULL;
2678 2678
2679 // Open the entry. 2679 // Open the entry. Can't spot the checksum that quickly with it so
2680 // huge.
2680 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); 2681 ASSERT_THAT(OpenEntry(key, &entry), IsOk());
2681 ScopedEntryPtr entry_closer(entry); 2682 ScopedEntryPtr entry_closer(entry);
2682 2683
2683 const int kReadBufferSize = 200; 2684 EXPECT_GE(kLargeSize, entry->GetDataSize(1));
2684 EXPECT_GE(kReadBufferSize, entry->GetDataSize(1)); 2685 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kLargeSize));
2685 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kReadBufferSize));
2686 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH, 2686 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH,
2687 ReadData(entry, 1, 0, read_buffer.get(), kReadBufferSize)); 2687 ReadData(entry, 1, 0, read_buffer.get(), kLargeSize));
2688 histogram_tester.ExpectUniqueSample( 2688 histogram_tester.ExpectUniqueSample(
2689 "SimpleCache.Http.ReadResult", 2689 "SimpleCache.Http.ReadResult",
2690 disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1); 2690 disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1);
2691 } 2691 }
2692 2692
2693 // Tests that an entry that has had an IO error occur can still be Doomed(). 2693 // Tests that an entry that has had an IO error occur can still be Doomed().
2694 TEST_F(DiskCacheEntryTest, SimpleCacheErrorThenDoom) { 2694 TEST_F(DiskCacheEntryTest, SimpleCacheErrorThenDoom) {
2695 base::HistogramTester histogram_tester; 2695 base::HistogramTester histogram_tester;
2696 SetSimpleCacheMode(); 2696 SetSimpleCacheMode();
2697 InitCache(); 2697 InitCache();
2698 2698
2699 const char key[] = "the first key"; 2699 const char key[] = "the first key";
2700 int size_unused; 2700 const int kLargeSize = 50000;
2701 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size_unused)); 2701 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, kLargeSize));
2702 2702
2703 disk_cache::Entry* entry = NULL; 2703 disk_cache::Entry* entry = NULL;
2704 2704
2705 // Open the entry, forcing an IO error. 2705 // Open the entry, forcing an IO error.
2706 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); 2706 ASSERT_THAT(OpenEntry(key, &entry), IsOk());
2707 ScopedEntryPtr entry_closer(entry); 2707 ScopedEntryPtr entry_closer(entry);
2708 2708
2709 const int kReadBufferSize = 200; 2709 EXPECT_GE(kLargeSize, entry->GetDataSize(1));
2710 EXPECT_GE(kReadBufferSize, entry->GetDataSize(1)); 2710 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kLargeSize));
2711 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kReadBufferSize));
2712 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH, 2711 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH,
2713 ReadData(entry, 1, 0, read_buffer.get(), kReadBufferSize)); 2712 ReadData(entry, 1, 0, read_buffer.get(), kLargeSize));
2714 histogram_tester.ExpectUniqueSample( 2713 histogram_tester.ExpectUniqueSample(
2715 "SimpleCache.Http.ReadResult", 2714 "SimpleCache.Http.ReadResult",
2716 disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1); 2715 disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1);
2717 entry->Doom(); // Should not crash. 2716 entry->Doom(); // Should not crash.
2718 } 2717 }
2719 2718
2720 bool TruncatePath(const base::FilePath& file_path, int64_t length) { 2719 bool TruncatePath(const base::FilePath& file_path, int64_t length) {
2721 base::File file(file_path, base::File::FLAG_WRITE | base::File::FLAG_OPEN); 2720 base::File file(file_path, base::File::FLAG_WRITE | base::File::FLAG_OPEN);
2722 if (!file.IsValid()) 2721 if (!file.IsValid())
2723 return false; 2722 return false;
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
3439 3438
3440 // Tests that if a read and a following in-flight truncate are both in progress 3439 // Tests that if a read and a following in-flight truncate are both in progress
3441 // simultaniously that they both can occur successfully. See 3440 // simultaniously that they both can occur successfully. See
3442 // http://crbug.com/239223 3441 // http://crbug.com/239223
3443 TEST_F(DiskCacheEntryTest, SimpleCacheInFlightTruncate) { 3442 TEST_F(DiskCacheEntryTest, SimpleCacheInFlightTruncate) {
3444 SetSimpleCacheMode(); 3443 SetSimpleCacheMode();
3445 InitCache(); 3444 InitCache();
3446 3445
3447 const char key[] = "the first key"; 3446 const char key[] = "the first key";
3448 3447
3449 const int kBufferSize = 1024; 3448 // We use a very large entry size here to make sure this doesn't hit
3449 // the prefetch path for any concievable setting. Hitting prefetch would
3450 // make us serve the read below from memory entirely on I/O thread, missing
3451 // the point of the test which coverred two concurrent disk ops, with
3452 // portions of work happening on the workpool.
3453 const int kBufferSize = 50000;
3450 scoped_refptr<net::IOBuffer> write_buffer(new net::IOBuffer(kBufferSize)); 3454 scoped_refptr<net::IOBuffer> write_buffer(new net::IOBuffer(kBufferSize));
3451 CacheTestFillBuffer(write_buffer->data(), kBufferSize, false); 3455 CacheTestFillBuffer(write_buffer->data(), kBufferSize, false);
3452 3456
3453 disk_cache::Entry* entry = NULL; 3457 disk_cache::Entry* entry = NULL;
3454 ASSERT_THAT(CreateEntry(key, &entry), IsOk()); 3458 ASSERT_THAT(CreateEntry(key, &entry), IsOk());
3455 3459
3456 EXPECT_EQ(kBufferSize, 3460 EXPECT_EQ(kBufferSize,
3457 WriteData(entry, 1, 0, write_buffer.get(), kBufferSize, false)); 3461 WriteData(entry, 1, 0, write_buffer.get(), kBufferSize, false));
3458 entry->Close(); 3462 entry->Close();
3459 entry = NULL; 3463 entry = NULL;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3570 } 3574 }
3571 3575
3572 // Checking one more scenario of overlapped reading of a bad entry. 3576 // Checking one more scenario of overlapped reading of a bad entry.
3573 // Differs from the |SimpleCacheMultipleReadersCheckCRC| only by the order of 3577 // Differs from the |SimpleCacheMultipleReadersCheckCRC| only by the order of
3574 // last two reads. 3578 // last two reads.
3575 TEST_F(DiskCacheEntryTest, SimpleCacheMultipleReadersCheckCRC2) { 3579 TEST_F(DiskCacheEntryTest, SimpleCacheMultipleReadersCheckCRC2) {
3576 SetSimpleCacheMode(); 3580 SetSimpleCacheMode();
3577 InitCache(); 3581 InitCache();
3578 3582
3579 const char key[] = "key"; 3583 const char key[] = "key";
3580 int size; 3584 int size = 50000;
3581 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size)); 3585 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, size));
3582 3586
3583 scoped_refptr<net::IOBuffer> read_buffer1(new net::IOBuffer(size)); 3587 scoped_refptr<net::IOBuffer> read_buffer1(new net::IOBuffer(size));
3584 scoped_refptr<net::IOBuffer> read_buffer2(new net::IOBuffer(size)); 3588 scoped_refptr<net::IOBuffer> read_buffer2(new net::IOBuffer(size));
3585 3589
3586 // Advance the first reader a little. 3590 // Advance the first reader a little.
3587 disk_cache::Entry* entry = NULL; 3591 disk_cache::Entry* entry = NULL;
3588 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); 3592 ASSERT_THAT(OpenEntry(key, &entry), IsOk());
3589 ScopedEntryPtr entry_closer(entry); 3593 ScopedEntryPtr entry_closer(entry);
3590 EXPECT_EQ(1, ReadData(entry, 1, 0, read_buffer1.get(), 1)); 3594 EXPECT_EQ(1, ReadData(entry, 1, 0, read_buffer1.get(), 1));
3591 3595
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
4316 // CHECK(temp_dir_.CreateUniqueTempDir()); 4320 // CHECK(temp_dir_.CreateUniqueTempDir());
4317 // cache_path_ = temp_dir_.GetPath(); 4321 // cache_path_ = temp_dir_.GetPath();
4318 disk_cache::DeleteCache(cache_path_, 4322 disk_cache::DeleteCache(cache_path_,
4319 true /* delete the dir, what we really want*/); 4323 true /* delete the dir, what we really want*/);
4320 4324
4321 disk_cache::Entry* entry; 4325 disk_cache::Entry* entry;
4322 std::string key("a key"); 4326 std::string key("a key");
4323 ASSERT_THAT(CreateEntry(key, &entry), IsOk()); 4327 ASSERT_THAT(CreateEntry(key, &entry), IsOk());
4324 entry->Close(); 4328 entry->Close();
4325 } 4329 }
4330
4331 class DiskCacheSimplePrefetchTest : public DiskCacheEntryTest {
4332 public:
4333 DiskCacheSimplePrefetchTest()
4334 : field_trial_list_(base::MakeUnique<base::FieldTrialList>(
4335 base::MakeUnique<base::MockEntropyProvider>())) {}
4336
4337 enum { kEntrySize = 1024 };
4338
4339 void SetUp() override {
4340 payload_ = new net::IOBuffer(kEntrySize);
4341 CacheTestFillBuffer(payload_->data(), kEntrySize, false);
4342 DiskCacheEntryTest::SetUp();
4343 }
4344
4345 void SetupPrefetch(int size) {
4346 std::map<std::string, std::string> params;
4347 params[disk_cache::kSimplePrefetchBytesParam] = base::IntToString(size);
4348 scoped_feature_list_.InitAndEnableFeatureWithParameters(
4349 disk_cache::kSimpleCachePrefetchExperiment, params);
4350 }
4351
4352 void InitCacheAndCreateEntry(const std::string& key) {
4353 SetSimpleCacheMode();
4354 InitCache();
4355
4356 disk_cache::Entry* entry;
4357 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
4358 // Use stream 1 since that's what new prefetch stuff is about.
4359 ASSERT_EQ(kEntrySize,
4360 WriteData(entry, 1, 0, payload_.get(), kEntrySize, false));
4361 entry->Close();
4362 }
4363
4364 void InitCacheAndCreateEntryWithNoCrc(const std::string& key) {
4365 const int kHalfSize = kEntrySize / 2;
4366 const int kRemSize = kEntrySize - kHalfSize;
4367
4368 SetSimpleCacheMode();
4369 InitCache();
4370
4371 disk_cache::Entry* entry;
4372 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
4373 // Use stream 1 since that's what new prefetch stuff is about.
4374 ASSERT_EQ(kEntrySize,
4375 WriteData(entry, 1, 0, payload_.get(), kEntrySize, false));
4376
4377 // Overwrite later part of the buffer, since we can't keep track of
4378 // the checksum in that case. Do it with identical contents, though,
4379 // so that the only difference between here and InitCacheAndCreateEntry()
4380 // would be whether the result has a checkum or not.
4381 scoped_refptr<net::IOBuffer> second_half(new net::IOBuffer(kRemSize));
4382 memcpy(second_half->data(), payload_->data() + kHalfSize, kRemSize);
4383 ASSERT_EQ(kRemSize, WriteData(entry, 1, kHalfSize, second_half.get(),
4384 kRemSize, false));
4385 entry->Close();
4386 }
4387
4388 void TryRead(const std::string& key) {
4389 disk_cache::Entry* entry = NULL;
4390 ASSERT_THAT(OpenEntry(key, &entry), IsOk());
4391 scoped_refptr<net::IOBuffer> read_buf(new net::IOBuffer(kEntrySize));
4392 EXPECT_EQ(kEntrySize, ReadData(entry, 1, 0, read_buf.get(), kEntrySize));
4393 EXPECT_EQ(0, memcmp(read_buf->data(), payload_->data(), kEntrySize));
4394 entry->Close();
4395 }
4396
4397 protected:
4398 scoped_refptr<net::IOBuffer> payload_;
4399
4400 // Need to have the one "global" trial list before we change things.
4401 std::unique_ptr<base::FieldTrialList> field_trial_list_;
4402 base::test::ScopedFeatureList scoped_feature_list_;
4403 };
4404
4405 TEST_F(DiskCacheSimplePrefetchTest, NoPrefetch) {
4406 base::HistogramTester histogram_tester;
4407 SetupPrefetch(0);
4408
4409 const char kKey[] = "a key";
4410 InitCacheAndCreateEntry(kKey);
4411 TryRead(kKey);
4412
4413 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncOpenDidPrefetch",
4414 false, 1);
4415 histogram_tester.ExpectUniqueSample(
4416 "SimpleCache.Http.ReadStream1FromPrefetched", false, 1);
4417 }
4418
4419 TEST_F(DiskCacheSimplePrefetchTest, YesPrefetch) {
4420 base::HistogramTester histogram_tester;
4421 SetupPrefetch(2 * kEntrySize);
4422
4423 const char kKey[] = "a key";
4424 InitCacheAndCreateEntry(kKey);
4425 TryRead(kKey);
4426
4427 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncOpenDidPrefetch",
4428 true, 1);
4429 histogram_tester.ExpectUniqueSample(
4430 "SimpleCache.Http.ReadStream1FromPrefetched", true, 1);
4431 }
4432
4433 TEST_F(DiskCacheSimplePrefetchTest, YesPrefetchNoRead) {
4434 base::HistogramTester histogram_tester;
4435 SetupPrefetch(2 * kEntrySize);
4436
4437 const char kKey[] = "a key";
4438 InitCacheAndCreateEntry(kKey);
4439
4440 disk_cache::Entry* entry = NULL;
4441 ASSERT_THAT(OpenEntry(kKey, &entry), IsOk());
4442 entry->Close();
4443
4444 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncOpenDidPrefetch",
4445 true, 1);
4446 // Have to use GetHistogramSamplesSinceCreation here since it's the only
4447 // API that handles the cases where the histogram hasn't even been created.
4448 std::unique_ptr<base::HistogramSamples> samples(
4449 histogram_tester.GetHistogramSamplesSinceCreation(
4450 "SimpleCache.Http.ReadStream1FromPrefetched"));
4451 EXPECT_EQ(0, samples->TotalCount());
4452 }
4453
4454 // This makes sure we detect checksum error on entry that's small enough to be
4455 // prefetched. This is like DiskCacheEntryTest.BadChecksum, but we make sure
4456 // to configure prefetch explicitly.
4457 TEST_F(DiskCacheSimplePrefetchTest, BadChecksumSmall) {
4458 SetupPrefetch(1024); // bigger than stuff below.
4459 SetSimpleCacheMode();
4460 InitCache();
4461
4462 const char key[] = "the first key";
4463 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, 10));
4464
4465 disk_cache::Entry* entry = NULL;
4466
4467 // Open the entry. Since we made a small entry, we will detect the CRC
4468 // problem at open.
4469 EXPECT_THAT(OpenEntry(key, &entry), IsError(net::ERR_FAILED));
4470 }
4471
4472 TEST_F(DiskCacheSimplePrefetchTest, ChecksumNoPrefetch) {
4473 base::HistogramTester histogram_tester;
4474
4475 SetupPrefetch(0);
4476 const char kKey[] = "a key";
4477 InitCacheAndCreateEntry(kKey);
4478 TryRead(kKey);
4479
4480 // Expect 2 CRCs --- stream 0 and stream 1.
4481 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncCheckEOFHasCrc",
4482 true, 2);
4483 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncCheckEOFResult",
4484 disk_cache::CHECK_EOF_RESULT_SUCCESS, 2);
4485 }
4486
4487 TEST_F(DiskCacheSimplePrefetchTest, NoChecksumNoPrefetch) {
4488 base::HistogramTester histogram_tester;
4489
4490 SetupPrefetch(0);
4491 const char kKey[] = "a key";
4492 InitCacheAndCreateEntryWithNoCrc(kKey);
4493 TryRead(kKey);
4494
4495 // Stream 0 has CRC, stream 1 doesn't.
4496 histogram_tester.ExpectBucketCount("SimpleCache.Http.SyncCheckEOFHasCrc",
4497 true, 1);
4498 histogram_tester.ExpectBucketCount("SimpleCache.Http.SyncCheckEOFHasCrc",
4499 false, 1);
4500 // EOF check is recorded even if there is no CRC there.
4501 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncCheckEOFResult",
4502 disk_cache::CHECK_EOF_RESULT_SUCCESS, 2);
4503 }
4504
4505 TEST_F(DiskCacheSimplePrefetchTest, ChecksumPrefetch) {
4506 base::HistogramTester histogram_tester;
4507
4508 SetupPrefetch(2 * kEntrySize);
4509 const char kKey[] = "a key";
4510 InitCacheAndCreateEntry(kKey);
4511 TryRead(kKey);
4512
4513 // Expect 2 CRCs --- stream 0 and stream 1.
4514 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncCheckEOFHasCrc",
4515 true, 2);
4516 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncCheckEOFResult",
4517 disk_cache::CHECK_EOF_RESULT_SUCCESS, 2);
4518 }
4519
4520 TEST_F(DiskCacheSimplePrefetchTest, NoChecksumPrefetch) {
4521 base::HistogramTester histogram_tester;
4522
4523 SetupPrefetch(2 * kEntrySize);
4524 const char kKey[] = "a key";
4525 InitCacheAndCreateEntryWithNoCrc(kKey);
4526 TryRead(kKey);
4527
4528 // Stream 0 has CRC, stream 1 doesn't.
4529 histogram_tester.ExpectBucketCount("SimpleCache.Http.SyncCheckEOFHasCrc",
4530 true, 1);
4531 histogram_tester.ExpectBucketCount("SimpleCache.Http.SyncCheckEOFHasCrc",
4532 false, 1);
4533 // EOF check is recorded even if there is no CRC there.
4534 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncCheckEOFResult",
4535 disk_cache::CHECK_EOF_RESULT_SUCCESS, 2);
4536 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698