diff options
author | agayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-12 20:47:18 +0000 |
---|---|---|
committer | agayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-12 20:47:18 +0000 |
commit | 6a74a93c35aff1afa3bf94cd08f68e97a48d331f (patch) | |
tree | a2b76f1eef04ea1b3cec0450ad4516e0b5482bef /net/disk_cache/flash | |
parent | 6e3920611d6243e2860235146baa11c49a49f668 (diff) | |
download | chromium_src-6a74a93c35aff1afa3bf94cd08f68e97a48d331f.zip chromium_src-6a74a93c35aff1afa3bf94cd08f68e97a48d331f.tar.gz chromium_src-6a74a93c35aff1afa3bf94cd08f68e97a48d331f.tar.bz2 |
Renamed classes for consistency.
BUG=157187
TEST=net_unittests --gtest_filter="FlashCacheTest.*" --gtest_repeat=10 --shuffle
Review URL: https://chromiumcodereview.appspot.com/11532011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/flash')
-rw-r--r-- | net/disk_cache/flash/flash_cache_test_base.cc | 11 | ||||
-rw-r--r-- | net/disk_cache/flash/flash_cache_test_base.h | 4 | ||||
-rw-r--r-- | net/disk_cache/flash/format.h | 6 | ||||
-rw-r--r-- | net/disk_cache/flash/log_store.cc (renamed from net/disk_cache/flash/log_structured_store.cc) | 24 | ||||
-rw-r--r-- | net/disk_cache/flash/log_store.h (renamed from net/disk_cache/flash/log_structured_store.h) | 22 | ||||
-rw-r--r-- | net/disk_cache/flash/log_store_entry.cc (renamed from net/disk_cache/flash/cache_entry.cc) | 68 | ||||
-rw-r--r-- | net/disk_cache/flash/log_store_entry.h (renamed from net/disk_cache/flash/cache_entry.h) | 22 | ||||
-rw-r--r-- | net/disk_cache/flash/log_store_entry_unittest.cc (renamed from net/disk_cache/flash/cache_entry_unittest.cc) | 29 | ||||
-rw-r--r-- | net/disk_cache/flash/log_store_unittest.cc | 114 | ||||
-rw-r--r-- | net/disk_cache/flash/log_structured_store_unittest.cc | 114 |
10 files changed, 207 insertions, 207 deletions
diff --git a/net/disk_cache/flash/flash_cache_test_base.cc b/net/disk_cache/flash/flash_cache_test_base.cc index 0123e16..368eb91 100644 --- a/net/disk_cache/flash/flash_cache_test_base.cc +++ b/net/disk_cache/flash/flash_cache_test_base.cc @@ -8,7 +8,7 @@ #include "base/files/scoped_temp_dir.h" #include "base/time.h" #include "net/disk_cache/flash/format.h" -#include "net/disk_cache/flash/log_structured_store.h" +#include "net/disk_cache/flash/log_store.h" #include "net/disk_cache/flash/storage.h" namespace { @@ -34,13 +34,12 @@ void FlashCacheTest::SetUp() { storage_.reset(new disk_cache::Storage(path, storage_size)); ASSERT_TRUE(storage_->Init()); - log_structured_store_.reset( - new disk_cache::LogStructuredStore(storage_.get())); - ASSERT_TRUE(log_structured_store_->Init()); + log_store_.reset(new disk_cache::LogStore(storage_.get())); + ASSERT_TRUE(log_store_->Init()); } void FlashCacheTest::TearDown() { - ASSERT_TRUE(log_structured_store_->Close()); - log_structured_store_.reset(); + ASSERT_TRUE(log_store_->Close()); + log_store_.reset(); storage_.reset(); } diff --git a/net/disk_cache/flash/flash_cache_test_base.h b/net/disk_cache/flash/flash_cache_test_base.h index cd6e54f..09bc7a7 100644 --- a/net/disk_cache/flash/flash_cache_test_base.h +++ b/net/disk_cache/flash/flash_cache_test_base.h @@ -13,7 +13,7 @@ namespace disk_cache { -class LogStructuredStore; +class LogStore; class Storage; } // namespace disk_cache @@ -26,7 +26,7 @@ class FlashCacheTest : public testing::Test { virtual void SetUp() OVERRIDE; virtual void TearDown() OVERRIDE; - scoped_ptr<disk_cache::LogStructuredStore> log_structured_store_; + scoped_ptr<disk_cache::LogStore> log_store_; scoped_ptr<disk_cache::Storage> storage_; base::ScopedTempDir temp_dir_; int32 num_segments_in_storage_; diff --git a/net/disk_cache/flash/format.h b/net/disk_cache/flash/format.h index 660c614..872d96b 100644 --- a/net/disk_cache/flash/format.h +++ b/net/disk_cache/flash/format.h @@ -23,9 +23,9 @@ const int32 kFlashSummarySize = (1 + kFlashMaxEntryCount) * sizeof(int32); const int32 kFlashSegmentFreeSpace = kFlashSegmentSize - kFlashSummarySize; // An entry consists of a fixed number of streams. -const int32 kFlashCacheEntryNumStreams = 4; -const int32 kFlashCacheEntryHeaderSize = - kFlashCacheEntryNumStreams * sizeof(int32); +const int32 kFlashLogStoreEntryNumStreams = 4; +const int32 kFlashLogStoreEntryHeaderSize = + kFlashLogStoreEntryNumStreams * sizeof(int32); } // namespace disk_cache diff --git a/net/disk_cache/flash/log_structured_store.cc b/net/disk_cache/flash/log_store.cc index f372de0..6837e35 100644 --- a/net/disk_cache/flash/log_structured_store.cc +++ b/net/disk_cache/flash/log_store.cc @@ -6,13 +6,13 @@ #include "base/memory/scoped_ptr.h" #include "base/stl_util.h" #include "net/disk_cache/flash/format.h" -#include "net/disk_cache/flash/log_structured_store.h" +#include "net/disk_cache/flash/log_store.h" #include "net/disk_cache/flash/segment.h" #include "net/disk_cache/flash/storage.h" namespace disk_cache { -LogStructuredStore::LogStructuredStore(Storage* storage) +LogStore::LogStore(Storage* storage) : storage_(storage), num_segments_(storage->size() / kFlashSegmentSize), open_segments_(num_segments_), @@ -24,12 +24,12 @@ LogStructuredStore::LogStructuredStore(Storage* storage) DCHECK(storage->size() % kFlashSegmentSize == 0); } -LogStructuredStore::~LogStructuredStore() { +LogStore::~LogStore() { DCHECK(!init_ || closed_); STLDeleteElements(&open_segments_); } -bool LogStructuredStore::Init() { +bool LogStore::Init() { DCHECK(!init_); // TODO(agayev): Once we start persisting segment metadata to disk, we will // start from where we left off during the last shutdown. @@ -43,7 +43,7 @@ bool LogStructuredStore::Init() { return true; } -bool LogStructuredStore::Close() { +bool LogStore::Close() { DCHECK(init_ && !closed_); open_segments_[write_index_]->ReleaseUser(); if (!open_segments_[write_index_]->Close()) @@ -53,7 +53,7 @@ bool LogStructuredStore::Close() { // TODO(agayev): persist metadata to disk. } -bool LogStructuredStore::CreateEntry(int32 size, int32* id) { +bool LogStore::CreateEntry(int32 size, int32* id) { DCHECK(init_ && !closed_); DCHECK(current_entry_id_ == -1 && size <= disk_cache::kFlashSegmentFreeSpace); @@ -85,7 +85,7 @@ bool LogStructuredStore::CreateEntry(int32 size, int32* id) { return true; } -bool LogStructuredStore::WriteData(const void* buffer, int32 size) { +bool LogStore::WriteData(const void* buffer, int32 size) { DCHECK(init_ && !closed_); DCHECK(current_entry_id_ != -1 && size <= current_entry_num_bytes_left_to_write_); @@ -96,7 +96,7 @@ bool LogStructuredStore::WriteData(const void* buffer, int32 size) { return false; } -bool LogStructuredStore::OpenEntry(int32 id) { +bool LogStore::OpenEntry(int32 id) { DCHECK(init_ && !closed_); if (open_entries_.find(id) != open_entries_.end()) return false; @@ -122,7 +122,7 @@ bool LogStructuredStore::OpenEntry(int32 id) { return true; } -bool LogStructuredStore::ReadData(int32 id, void* buffer, int32 size, +bool LogStore::ReadData(int32 id, void* buffer, int32 size, int32 offset) const { DCHECK(init_ && !closed_); DCHECK(open_entries_.find(id) != open_entries_.end()); @@ -132,7 +132,7 @@ bool LogStructuredStore::ReadData(int32 id, void* buffer, int32 size, return open_segments_[index]->ReadData(buffer, size, id + offset); } -void LogStructuredStore::CloseEntry(int32 id) { +void LogStore::CloseEntry(int32 id) { DCHECK(init_ && !closed_); std::set<int32>::iterator entry_iter = open_entries_.find(id); DCHECK(entry_iter != open_entries_.end()); @@ -155,7 +155,7 @@ void LogStructuredStore::CloseEntry(int32 id) { } } -int32 LogStructuredStore::GetNextSegmentIndex() { +int32 LogStore::GetNextSegmentIndex() { DCHECK(init_ && !closed_); int32 next_index = (write_index_ + 1) % num_segments_; @@ -166,7 +166,7 @@ int32 LogStructuredStore::GetNextSegmentIndex() { return next_index; } -bool LogStructuredStore::InUse(int32 index) const { +bool LogStore::InUse(int32 index) const { DCHECK(init_ && !closed_); DCHECK(index >= 0 && index < num_segments_); return open_segments_[index] != NULL; diff --git a/net/disk_cache/flash/log_structured_store.h b/net/disk_cache/flash/log_store.h index ea65d34..7dc57aa 100644 --- a/net/disk_cache/flash/log_structured_store.h +++ b/net/disk_cache/flash/log_store.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef NET_DISK_CACHE_FLASH_LOG_STRUCTURED_STORE_H_ -#define NET_DISK_CACHE_FLASH_LOG_STRUCTURED_STORE_H_ +#ifndef NET_DISK_CACHE_FLASH_LOG_STORE_H_ +#define NET_DISK_CACHE_FLASH_LOG_STORE_H_ #include <set> #include <vector> @@ -22,10 +22,10 @@ class Storage; // i.e. it's not possible to overwrite data in place. In order to update an // entry, a new version must be written. Only one entry can be written to at // any given time, while concurrent reading of multiple entries is supported. -class NET_EXPORT_PRIVATE LogStructuredStore { +class NET_EXPORT_PRIVATE LogStore { public: - explicit LogStructuredStore(Storage* storage); - ~LogStructuredStore(); + explicit LogStore(Storage* storage); + ~LogStore(); // Performs initialization. Must be the first function called and further // calls should be made only if it is successful. @@ -56,13 +56,13 @@ class NET_EXPORT_PRIVATE LogStructuredStore { private: FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, - LogStructuredStoreReadFromClosedSegment); + LogStoreReadFromClosedSegment); FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, - LogStructuredStoreSegmentSelectionIsFifo); + LogStoreSegmentSelectionIsFifo); FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, - LogStructuredStoreInUseSegmentIsSkipped); + LogStoreInUseSegmentIsSkipped); FRIEND_TEST_ALL_PREFIXES(FlashCacheTest, - LogStructuredStoreReadFromCurrentAfterClose); + LogStoreReadFromCurrentAfterClose); int32 GetNextSegmentIndex(); bool InUse(int32 segment_index) const; @@ -94,9 +94,9 @@ class NET_EXPORT_PRIVATE LogStructuredStore { bool init_; // Init was called. bool closed_; // Close was called. - DISALLOW_COPY_AND_ASSIGN(LogStructuredStore); + DISALLOW_COPY_AND_ASSIGN(LogStore); }; } // namespace disk_cache -#endif // NET_DISK_CACHE_FLASH_LOG_STRUCTURED_STORE_H_ +#endif // NET_DISK_CACHE_FLASH_LOG_STORE_H_ diff --git a/net/disk_cache/flash/cache_entry.cc b/net/disk_cache/flash/log_store_entry.cc index f063629..99f2bf4 100644 --- a/net/disk_cache/flash/cache_entry.cc +++ b/net/disk_cache/flash/log_store_entry.cc @@ -5,43 +5,43 @@ #include "base/logging.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" -#include "net/disk_cache/flash/cache_entry.h" #include "net/disk_cache/flash/format.h" -#include "net/disk_cache/flash/log_structured_store.h" +#include "net/disk_cache/flash/log_store.h" +#include "net/disk_cache/flash/log_store_entry.h" namespace disk_cache { -CacheEntry::CacheEntry(LogStructuredStore* store) +LogStoreEntry::LogStoreEntry(LogStore* store) : store_(store), id_(-1), init_(false), closed_(false) { DCHECK(store); } -CacheEntry::CacheEntry(LogStructuredStore* store, int32 id) +LogStoreEntry::LogStoreEntry(LogStore* store, int32 id) : store_(store), id_(id), init_(false), closed_(false) { DCHECK(store); } -CacheEntry::~CacheEntry() { +LogStoreEntry::~LogStoreEntry() { DCHECK(!init_ || closed_); } -bool CacheEntry::Init() { +bool LogStoreEntry::Init() { DCHECK(!init_); if (!OnDisk()) { init_ = true; return true; } - int32 stream_sizes[kFlashCacheEntryNumStreams]; - COMPILE_ASSERT(sizeof(stream_sizes) == kFlashCacheEntryHeaderSize, - invalid_cache_entry_header_size); + int32 stream_sizes[kFlashLogStoreEntryNumStreams]; + COMPILE_ASSERT(sizeof(stream_sizes) == kFlashLogStoreEntryHeaderSize, + invalid_log_store_entry_header_size); if (!store_->OpenEntry(id_) || - !store_->ReadData(id_, stream_sizes, kFlashCacheEntryHeaderSize, 0)) { + !store_->ReadData(id_, stream_sizes, kFlashLogStoreEntryHeaderSize, 0)) { return false; } - for (int i = 0, offset = kFlashCacheEntryHeaderSize; - i < kFlashCacheEntryNumStreams; ++i) { + for (int i = 0, offset = kFlashLogStoreEntryHeaderSize; + i < kFlashLogStoreEntryNumStreams; ++i) { streams_[i].offset = offset; streams_[i].size = stream_sizes[i]; offset += stream_sizes[i]; @@ -50,7 +50,7 @@ bool CacheEntry::Init() { return true; } -bool CacheEntry::Close() { +bool LogStoreEntry::Close() { DCHECK(init_ && !closed_); if (OnDisk()) store_->CloseEntry(id_); @@ -60,18 +60,18 @@ bool CacheEntry::Close() { return true; } -int32 CacheEntry::id() const { +int32 LogStoreEntry::id() const { DCHECK(init_); return id_; } -int32 CacheEntry::GetDataSize(int index) const { +int32 LogStoreEntry::GetDataSize(int index) const { DCHECK(init_); return InvalidStream(index) ? 0 : streams_[index].size; } -int CacheEntry::ReadData(int index, int offset, net::IOBuffer* buf, - int buf_len) { +int LogStoreEntry::ReadData(int index, int offset, net::IOBuffer* buf, + int buf_len) { DCHECK(init_); if (InvalidStream(index)) return net::ERR_INVALID_ARGUMENT; @@ -92,8 +92,8 @@ int CacheEntry::ReadData(int index, int offset, net::IOBuffer* buf, return buf_len; } -int CacheEntry::WriteData(int index, int offset, net::IOBuffer* buf, - int buf_len) { +int LogStoreEntry::WriteData(int index, int offset, net::IOBuffer* buf, + int buf_len) { DCHECK(init_ && !closed_); if (InvalidStream(index)) return net::ERR_INVALID_ARGUMENT; @@ -113,37 +113,37 @@ int CacheEntry::WriteData(int index, int offset, net::IOBuffer* buf, return buf_len; } -bool CacheEntry::OnDisk() const { +bool LogStoreEntry::OnDisk() const { return id_ != -1; } -bool CacheEntry::InvalidStream(int stream_index) const { - return stream_index < 0 || stream_index >= kFlashCacheEntryNumStreams; +bool LogStoreEntry::InvalidStream(int stream_index) const { + return stream_index < 0 || stream_index >= kFlashLogStoreEntryNumStreams; } -int32 CacheEntry::Size() const { +int32 LogStoreEntry::Size() const { DCHECK(init_); - int32 size = kFlashCacheEntryHeaderSize; - for (int i = 0; i < kFlashCacheEntryNumStreams; ++i) + int32 size = kFlashLogStoreEntryHeaderSize; + for (int i = 0; i < kFlashLogStoreEntryNumStreams; ++i) size += streams_[i].size; DCHECK(size > 0 && size <= kFlashSegmentFreeSpace); return size; } -bool CacheEntry::Save() { +bool LogStoreEntry::Save() { DCHECK(init_ && !closed_ && !OnDisk()); - int32 stream_sizes[kFlashCacheEntryNumStreams]; - COMPILE_ASSERT(sizeof(stream_sizes) == kFlashCacheEntryHeaderSize, - invalid_cache_entry_header_size); + int32 stream_sizes[kFlashLogStoreEntryNumStreams]; + COMPILE_ASSERT(sizeof(stream_sizes) == kFlashLogStoreEntryHeaderSize, + invalid_log_store_entry_header_size); - for (int i = 0; i < kFlashCacheEntryNumStreams; ++i) + for (int i = 0; i < kFlashLogStoreEntryNumStreams; ++i) stream_sizes[i] = streams_[i].size; if (!store_->CreateEntry(Size(), &id_)) return false; - if (!store_->WriteData(stream_sizes, kFlashCacheEntryHeaderSize)) + if (!store_->WriteData(stream_sizes, kFlashLogStoreEntryHeaderSize)) return false; - for (int i = 0; i < kFlashCacheEntryNumStreams; ++i) { + for (int i = 0; i < kFlashLogStoreEntryNumStreams; ++i) { if (streams_[i].size > 0 && !store_->WriteData(&streams_[i].write_buffer[0], streams_[i].size)) { return false; @@ -153,10 +153,10 @@ bool CacheEntry::Save() { return true; } -CacheEntry::Stream::Stream() : offset(0), size(0) { +LogStoreEntry::Stream::Stream() : offset(0), size(0) { } -CacheEntry::Stream::~Stream() { +LogStoreEntry::Stream::~Stream() { } } // namespace disk_cache diff --git a/net/disk_cache/flash/cache_entry.h b/net/disk_cache/flash/log_store_entry.h index 05f08eb..c172457 100644 --- a/net/disk_cache/flash/cache_entry.h +++ b/net/disk_cache/flash/log_store_entry.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef NET_DISK_CACHE_FLASH_LOG_ENTRY_H_ -#define NET_DISK_CACHE_FLASH_LOG_ENTRY_H_ +#ifndef NET_DISK_CACHE_FLASH_LOG_STORE_ENTRY_H_ +#define NET_DISK_CACHE_FLASH_LOG_STORE_ENTRY_H_ #include <vector> @@ -18,13 +18,13 @@ class IOBuffer; namespace disk_cache { -class LogStructuredStore; +class LogStore; -class NET_EXPORT_PRIVATE CacheEntry { +class NET_EXPORT_PRIVATE LogStoreEntry { public: - explicit CacheEntry(LogStructuredStore* store); - CacheEntry(LogStructuredStore* store, int32 id); - ~CacheEntry(); + explicit LogStoreEntry(LogStore* store); + LogStoreEntry(LogStore* store, int32 id); + ~LogStoreEntry(); bool Init(); bool Close(); @@ -49,15 +49,15 @@ class NET_EXPORT_PRIVATE CacheEntry { int32 Size() const; bool Save(); - LogStructuredStore* store_; + LogStore* store_; int32 id_; - Stream streams_[kFlashCacheEntryNumStreams]; + Stream streams_[kFlashLogStoreEntryNumStreams]; bool init_; bool closed_; - DISALLOW_COPY_AND_ASSIGN(CacheEntry); + DISALLOW_COPY_AND_ASSIGN(LogStoreEntry); }; } // namespace disk_cache -#endif // NET_DISK_CACHE_FLASH_LOG_ENTRY_H_ +#endif // NET_DISK_CACHE_FLASH_LOG_STORE_ENTRY_H_ diff --git a/net/disk_cache/flash/cache_entry_unittest.cc b/net/disk_cache/flash/log_store_entry_unittest.cc index 206f283..8ea3186 100644 --- a/net/disk_cache/flash/cache_entry_unittest.cc +++ b/net/disk_cache/flash/log_store_entry_unittest.cc @@ -5,23 +5,23 @@ #include "base/memory/scoped_ptr.h" #include "net/base/io_buffer.h" #include "net/disk_cache/disk_cache_test_util.h" -#include "net/disk_cache/flash/cache_entry.h" #include "net/disk_cache/flash/flash_cache_test_base.h" #include "net/disk_cache/flash/format.h" +#include "net/disk_cache/flash/log_store_entry.h" #include "testing/gtest/include/gtest/gtest.h" -using disk_cache::CacheEntry; +using disk_cache::LogStoreEntry; -// Tests the behavior of a CacheEntry with empty streams. -TEST_F(FlashCacheTest, CacheEntryEmpty) { - scoped_ptr<CacheEntry> entry(new CacheEntry(log_structured_store_.get())); +// Tests the behavior of a LogStoreEntry with empty streams. +TEST_F(FlashCacheTest, LogStoreEntryEmpty) { + scoped_ptr<LogStoreEntry> entry(new LogStoreEntry(log_store_.get())); EXPECT_TRUE(entry->Init()); EXPECT_TRUE(entry->Close()); - entry.reset(new CacheEntry(log_structured_store_.get(), entry->id())); + entry.reset(new LogStoreEntry(log_store_.get(), entry->id())); EXPECT_TRUE(entry->Init()); - for (int i = 0; i < disk_cache::kFlashCacheEntryNumStreams; ++i) { + for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { const int kSize = 1024; scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); EXPECT_EQ(0, entry->GetDataSize(i)); @@ -30,14 +30,15 @@ TEST_F(FlashCacheTest, CacheEntryEmpty) { EXPECT_TRUE(entry->Close()); } -TEST_F(FlashCacheTest, CacheEntryWriteRead) { - scoped_ptr<CacheEntry> entry(new CacheEntry(log_structured_store_.get())); +TEST_F(FlashCacheTest, LogStoreEntryWriteRead) { + scoped_ptr<LogStoreEntry> entry(new LogStoreEntry(log_store_.get())); EXPECT_TRUE(entry->Init()); - int sizes[disk_cache::kFlashCacheEntryNumStreams] = {333, 444, 555, 666}; - scoped_refptr<net::IOBuffer> buffers[disk_cache::kFlashCacheEntryNumStreams]; + int sizes[disk_cache::kFlashLogStoreEntryNumStreams] = {333, 444, 555, 666}; + scoped_refptr<net::IOBuffer> buffers[ + disk_cache::kFlashLogStoreEntryNumStreams]; - for (int i = 0; i < disk_cache::kFlashCacheEntryNumStreams; ++i) { + for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { buffers[i] = new net::IOBuffer(sizes[i]); CacheTestFillBuffer(buffers[i]->data(), sizes[i], false); EXPECT_EQ(sizes[i], entry->WriteData(i, 0, buffers[i], sizes[i])); @@ -45,10 +46,10 @@ TEST_F(FlashCacheTest, CacheEntryWriteRead) { EXPECT_TRUE(entry->Close()); int32 id = entry->id(); - entry.reset(new CacheEntry(log_structured_store_.get(), id)); + entry.reset(new LogStoreEntry(log_store_.get(), id)); EXPECT_TRUE(entry->Init()); - for (int i = 0; i < disk_cache::kFlashCacheEntryNumStreams; ++i) { + for (int i = 0; i < disk_cache::kFlashLogStoreEntryNumStreams; ++i) { EXPECT_EQ(sizes[i], entry->GetDataSize(i)); scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(sizes[i])); EXPECT_EQ(sizes[i], entry->ReadData(i, 0, buffer, sizes[i])); diff --git a/net/disk_cache/flash/log_store_unittest.cc b/net/disk_cache/flash/log_store_unittest.cc new file mode 100644 index 0000000..e57eedc --- /dev/null +++ b/net/disk_cache/flash/log_store_unittest.cc @@ -0,0 +1,114 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/disk_cache/flash/flash_cache_test_base.h" +#include "net/disk_cache/flash/format.h" +#include "net/disk_cache/flash/log_store.h" +#include "net/disk_cache/flash/segment.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace disk_cache { + +TEST_F(FlashCacheTest, LogStoreCreateEntry) { + const int32 kSize = 100; + const std::string buf(kSize, 0); + + int32 id; + EXPECT_TRUE(log_store_->CreateEntry(kSize, &id)); + EXPECT_TRUE(log_store_->WriteData(buf.data(), kSize/2)); + EXPECT_TRUE(log_store_->WriteData(buf.data(), kSize/2)); + log_store_->CloseEntry(id); +} + +// Also tests reading from current segment. +TEST_F(FlashCacheTest, LogStoreOpenEntry) { + const int32 kSize = 100; + const std::vector<char> expected(kSize, 'b'); + + int32 id; + EXPECT_TRUE(log_store_->CreateEntry(kSize, &id)); + EXPECT_TRUE(log_store_->WriteData(&expected[0], kSize)); + log_store_->CloseEntry(id); + + EXPECT_TRUE(log_store_->OpenEntry(id)); + std::vector<char> actual(kSize, 0); + EXPECT_TRUE(log_store_->ReadData(id, &actual[0], kSize, 0)); + log_store_->CloseEntry(id); + + EXPECT_EQ(expected, actual); +} + +// Also tests that writing advances segments. +TEST_F(FlashCacheTest, LogStoreReadFromClosedSegment) { + const int32 kSize = disk_cache::kFlashSegmentFreeSpace; + const std::vector<char> expected(kSize, 'a'); + + // First two entries go to segment 0. + int32 id1; + EXPECT_EQ(0, log_store_->write_index_); + EXPECT_TRUE(log_store_->CreateEntry(kSize/2, &id1)); + EXPECT_TRUE(log_store_->WriteData(&expected[0], kSize/2)); + log_store_->CloseEntry(id1); + + int32 id2; + EXPECT_EQ(0, log_store_->write_index_); + EXPECT_TRUE(log_store_->CreateEntry(kSize/2, &id2)); + EXPECT_TRUE(log_store_->WriteData(&expected[0], kSize/2)); + log_store_->CloseEntry(id2); + + // This entry goes to segment 1. + int32 id3; + EXPECT_TRUE(log_store_->CreateEntry(kSize, &id3)); + EXPECT_EQ(1, log_store_->write_index_); + EXPECT_TRUE(log_store_->WriteData(&expected[0], kSize)); + log_store_->CloseEntry(id3); + + // We read from segment 0. + EXPECT_TRUE(log_store_->OpenEntry(id1)); + std::vector<char> actual(kSize, 0); + EXPECT_TRUE(log_store_->ReadData(id1, &actual[0], kSize, id1)); + log_store_->CloseEntry(id1); + + EXPECT_EQ(expected, actual); +} + +TEST_F(FlashCacheTest, LogStoreReadFromCurrentAfterClose) { + const int32 kSize = disk_cache::kFlashSegmentFreeSpace; + const std::vector<char> expected(kSize, 'a'); + + int32 id1; + EXPECT_EQ(0, log_store_->write_index_); + EXPECT_TRUE(log_store_->CreateEntry(kSize/2, &id1)); + EXPECT_TRUE(log_store_->WriteData(&expected[0], kSize/2)); + log_store_->CloseEntry(id1); + + // Create a reference to above entry. + EXPECT_TRUE(log_store_->OpenEntry(id1)); + + // This entry fills the first segment. + int32 id2; + EXPECT_EQ(0, log_store_->write_index_); + EXPECT_TRUE(log_store_->CreateEntry(kSize/2, &id2)); + EXPECT_TRUE(log_store_->WriteData(&expected[0], kSize/2)); + log_store_->CloseEntry(id2); + + // Creating this entry forces closing of the first segment. + int32 id3; + EXPECT_TRUE(log_store_->CreateEntry(kSize, &id3)); + EXPECT_EQ(1, log_store_->write_index_); + EXPECT_TRUE(log_store_->WriteData(&expected[0], kSize)); + log_store_->CloseEntry(id3); + + // Now attempt to read from the closed segment. + std::vector<char> actual(kSize, 0); + EXPECT_TRUE(log_store_->ReadData(id1, &actual[0], kSize, id1)); + log_store_->CloseEntry(id1); + + EXPECT_EQ(expected, actual); +} + +// TODO(agayev): Add a test that confirms that in-use segment is not selected as +// the next write segment. + +} // namespace disk_cache diff --git a/net/disk_cache/flash/log_structured_store_unittest.cc b/net/disk_cache/flash/log_structured_store_unittest.cc deleted file mode 100644 index b41d264..0000000 --- a/net/disk_cache/flash/log_structured_store_unittest.cc +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/disk_cache/flash/flash_cache_test_base.h" -#include "net/disk_cache/flash/format.h" -#include "net/disk_cache/flash/log_structured_store.h" -#include "net/disk_cache/flash/segment.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace disk_cache { - -TEST_F(FlashCacheTest, LogStructuredStoreCreateEntry) { - const int32 kSize = 100; - const std::string buf(kSize, 0); - - int32 id; - EXPECT_TRUE(log_structured_store_->CreateEntry(kSize, &id)); - EXPECT_TRUE(log_structured_store_->WriteData(buf.data(), kSize/2)); - EXPECT_TRUE(log_structured_store_->WriteData(buf.data(), kSize/2)); - log_structured_store_->CloseEntry(id); -} - -// Also tests reading from current segment. -TEST_F(FlashCacheTest, LogStructuredStoreOpenEntry) { - const int32 kSize = 100; - const std::vector<char> expected(kSize, 'b'); - - int32 id; - EXPECT_TRUE(log_structured_store_->CreateEntry(kSize, &id)); - EXPECT_TRUE(log_structured_store_->WriteData(&expected[0], kSize)); - log_structured_store_->CloseEntry(id); - - EXPECT_TRUE(log_structured_store_->OpenEntry(id)); - std::vector<char> actual(kSize, 0); - EXPECT_TRUE(log_structured_store_->ReadData(id, &actual[0], kSize, 0)); - log_structured_store_->CloseEntry(id); - - EXPECT_EQ(expected, actual); -} - -// Also tests that writing advances segments. -TEST_F(FlashCacheTest, LogStructuredStoreReadFromClosedSegment) { - const int32 kSize = disk_cache::kFlashSegmentFreeSpace; - const std::vector<char> expected(kSize, 'a'); - - // First two entries go to segment 0. - int32 id1; - EXPECT_EQ(0, log_structured_store_->write_index_); - EXPECT_TRUE(log_structured_store_->CreateEntry(kSize/2, &id1)); - EXPECT_TRUE(log_structured_store_->WriteData(&expected[0], kSize/2)); - log_structured_store_->CloseEntry(id1); - - int32 id2; - EXPECT_EQ(0, log_structured_store_->write_index_); - EXPECT_TRUE(log_structured_store_->CreateEntry(kSize/2, &id2)); - EXPECT_TRUE(log_structured_store_->WriteData(&expected[0], kSize/2)); - log_structured_store_->CloseEntry(id2); - - // This entry goes to segment 1. - int32 id3; - EXPECT_TRUE(log_structured_store_->CreateEntry(kSize, &id3)); - EXPECT_EQ(1, log_structured_store_->write_index_); - EXPECT_TRUE(log_structured_store_->WriteData(&expected[0], kSize)); - log_structured_store_->CloseEntry(id3); - - // We read from segment 0. - EXPECT_TRUE(log_structured_store_->OpenEntry(id1)); - std::vector<char> actual(kSize, 0); - EXPECT_TRUE(log_structured_store_->ReadData(id1, &actual[0], kSize, id1)); - log_structured_store_->CloseEntry(id1); - - EXPECT_EQ(expected, actual); -} - -TEST_F(FlashCacheTest, LogStructuredStoreReadFromCurrentAfterClose) { - const int32 kSize = disk_cache::kFlashSegmentFreeSpace; - const std::vector<char> expected(kSize, 'a'); - - int32 id1; - EXPECT_EQ(0, log_structured_store_->write_index_); - EXPECT_TRUE(log_structured_store_->CreateEntry(kSize/2, &id1)); - EXPECT_TRUE(log_structured_store_->WriteData(&expected[0], kSize/2)); - log_structured_store_->CloseEntry(id1); - - // Create a reference to above entry. - EXPECT_TRUE(log_structured_store_->OpenEntry(id1)); - - // This entry fills the first segment. - int32 id2; - EXPECT_EQ(0, log_structured_store_->write_index_); - EXPECT_TRUE(log_structured_store_->CreateEntry(kSize/2, &id2)); - EXPECT_TRUE(log_structured_store_->WriteData(&expected[0], kSize/2)); - log_structured_store_->CloseEntry(id2); - - // Creating this entry forces closing of the first segment. - int32 id3; - EXPECT_TRUE(log_structured_store_->CreateEntry(kSize, &id3)); - EXPECT_EQ(1, log_structured_store_->write_index_); - EXPECT_TRUE(log_structured_store_->WriteData(&expected[0], kSize)); - log_structured_store_->CloseEntry(id3); - - // Now attempt to read from the closed segment. - std::vector<char> actual(kSize, 0); - EXPECT_TRUE(log_structured_store_->ReadData(id1, &actual[0], kSize, id1)); - log_structured_store_->CloseEntry(id1); - - EXPECT_EQ(expected, actual); -} - -// TODO(agayev): Add a test that confirms that in-use segment is not selected as -// the next write segment. - -} // namespace disk_cache |