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

Unified Diff: net/disk_cache/flash/log_store_unittest.cc

Issue 14265009: FlashCache refactorings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More refactorings. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/flash/log_store_entry_unittest.cc ('k') | net/disk_cache/flash/segment_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/flash/log_store_unittest.cc
diff --git a/net/disk_cache/flash/log_store_unittest.cc b/net/disk_cache/flash/log_store_unittest.cc
index e57eedc4a9eeaab13a2bfba0c282c5bdb2b0e8b1..2678316d499ee3c27001dead7a494baa2ed1930a 100644
--- a/net/disk_cache/flash/log_store_unittest.cc
+++ b/net/disk_cache/flash/log_store_unittest.cc
@@ -11,101 +11,118 @@
namespace disk_cache {
TEST_F(FlashCacheTest, LogStoreCreateEntry) {
+ LogStore log_store(path_, kStorageSize);
+ EXPECT_TRUE(log_store.Init());
+
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);
+ 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);
+
+ EXPECT_TRUE(log_store.Close());
}
// Also tests reading from current segment.
TEST_F(FlashCacheTest, LogStoreOpenEntry) {
+ LogStore log_store(path_, kStorageSize);
+ EXPECT_TRUE(log_store.Init());
+
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.CreateEntry(kSize, &id));
+ EXPECT_TRUE(log_store.WriteData(&expected[0], kSize));
+ log_store.CloseEntry(id);
- EXPECT_TRUE(log_store_->OpenEntry(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_TRUE(log_store.ReadData(id, &actual[0], kSize, 0));
+ log_store.CloseEntry(id);
EXPECT_EQ(expected, actual);
+ EXPECT_TRUE(log_store.Close());
}
// Also tests that writing advances segments.
TEST_F(FlashCacheTest, LogStoreReadFromClosedSegment) {
+ LogStore log_store(path_, kStorageSize);
+ EXPECT_TRUE(log_store.Init());
+
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);
+ 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);
+ 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);
+ 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));
+ 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_TRUE(log_store.ReadData(id1, &actual[0], kSize, id1));
+ log_store.CloseEntry(id1);
EXPECT_EQ(expected, actual);
+ EXPECT_TRUE(log_store.Close());
}
TEST_F(FlashCacheTest, LogStoreReadFromCurrentAfterClose) {
+ LogStore log_store(path_, kStorageSize);
+ EXPECT_TRUE(log_store.Init());
+
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);
+ 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));
+ 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);
+ 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);
+ 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_TRUE(log_store.ReadData(id1, &actual[0], kSize, id1));
+ log_store.CloseEntry(id1);
EXPECT_EQ(expected, actual);
+ EXPECT_TRUE(log_store.Close());
}
// TODO(agayev): Add a test that confirms that in-use segment is not selected as
« no previous file with comments | « net/disk_cache/flash/log_store_entry_unittest.cc ('k') | net/disk_cache/flash/segment_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698