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

Side by Side Diff: sync/syncable/deferred_on_disk_directory_backing_store_unittest.cc

Issue 1008103002: Sync: Avoid 3 passes over SyncDarta DB when loading the directory from the disk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "sync/syncable/deferred_on_disk_directory_backing_store.h" 7 #include "sync/syncable/deferred_on_disk_directory_backing_store.h"
8 #include "sync/syncable/directory.h" 8 #include "sync/syncable/directory.h"
9 #include "sync/syncable/entry_kernel.h" 9 #include "sync/syncable/entry_kernel.h"
10 #include "sync/syncable/on_disk_directory_backing_store.h" 10 #include "sync/syncable/on_disk_directory_backing_store.h"
(...skipping 13 matching lines...) Expand all
24 CHECK(temp_dir_.CreateUniqueTempDir()); 24 CHECK(temp_dir_.CreateUniqueTempDir());
25 db_path_ = temp_dir_.path().Append(kSyncDataFolderName); 25 db_path_ = temp_dir_.path().Append(kSyncDataFolderName);
26 } 26 }
27 27
28 void TearDown() override { STLDeleteValues(&handles_map_); } 28 void TearDown() override { STLDeleteValues(&handles_map_); }
29 29
30 base::ScopedTempDir temp_dir_; 30 base::ScopedTempDir temp_dir_;
31 base::FilePath db_path_; 31 base::FilePath db_path_;
32 Directory::MetahandlesMap handles_map_; 32 Directory::MetahandlesMap handles_map_;
33 JournalIndex delete_journals_; 33 JournalIndex delete_journals_;
34 MetahandleSet metahandles_to_purge_;
34 Directory::KernelLoadInfo kernel_load_info_; 35 Directory::KernelLoadInfo kernel_load_info_;
35 }; 36 };
36 37
37 // Test initialization of root entry when calling Load(). 38 // Test initialization of root entry when calling Load().
38 TEST_F(DeferredOnDiskDirectoryBackingStoreTest, Load) { 39 TEST_F(DeferredOnDiskDirectoryBackingStoreTest, Load) {
39 DeferredOnDiskDirectoryBackingStore store("test", db_path_); 40 DeferredOnDiskDirectoryBackingStore store("test", db_path_);
40 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_, 41 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_,
41 &kernel_load_info_)); 42 &metahandles_to_purge_, &kernel_load_info_));
42 EXPECT_TRUE(delete_journals_.empty()); 43 EXPECT_TRUE(delete_journals_.empty());
44 EXPECT_TRUE(metahandles_to_purge_.empty());
43 ASSERT_EQ(1u, handles_map_.size()); // root node 45 ASSERT_EQ(1u, handles_map_.size()); // root node
44 ASSERT_TRUE(handles_map_.count(1)); 46 ASSERT_TRUE(handles_map_.count(1));
45 EntryKernel* root = handles_map_[1]; 47 EntryKernel* root = handles_map_[1];
46 EXPECT_TRUE(root->ref(ID).IsRoot()); 48 EXPECT_TRUE(root->ref(ID).IsRoot());
47 EXPECT_EQ(1, root->ref(META_HANDLE)); 49 EXPECT_EQ(1, root->ref(META_HANDLE));
48 EXPECT_TRUE(root->ref(IS_DIR)); 50 EXPECT_TRUE(root->ref(IS_DIR));
49 } 51 }
50 52
51 // Test on-disk DB is not created if SaveChanges() is not called. 53 // Test on-disk DB is not created if SaveChanges() is not called.
52 TEST_F(DeferredOnDiskDirectoryBackingStoreTest, 54 TEST_F(DeferredOnDiskDirectoryBackingStoreTest,
53 DontPersistIfSavingChangesNotCalled) { 55 DontPersistIfSavingChangesNotCalled) {
54 { 56 {
55 // Open and close. 57 // Open and close.
56 DeferredOnDiskDirectoryBackingStore store("test", db_path_); 58 DeferredOnDiskDirectoryBackingStore store("test", db_path_);
57 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_, 59 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_,
58 &kernel_load_info_)); 60 &metahandles_to_purge_, &kernel_load_info_));
59 } 61 }
60 62
61 EXPECT_FALSE(base::PathExists(db_path_)); 63 EXPECT_FALSE(base::PathExists(db_path_));
62 } 64 }
63 65
64 // Test on-disk DB is not created when there are no changes. 66 // Test on-disk DB is not created when there are no changes.
65 TEST_F(DeferredOnDiskDirectoryBackingStoreTest, 67 TEST_F(DeferredOnDiskDirectoryBackingStoreTest,
66 DontPersistWhenSavingNoChanges) { 68 DontPersistWhenSavingNoChanges) {
67 { 69 {
68 // Open and close. 70 // Open and close.
69 DeferredOnDiskDirectoryBackingStore store("test", db_path_); 71 DeferredOnDiskDirectoryBackingStore store("test", db_path_);
70 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_, 72 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_,
71 &kernel_load_info_)); 73 &metahandles_to_purge_, &kernel_load_info_));
72 74
73 Directory::SaveChangesSnapshot snapshot; 75 Directory::SaveChangesSnapshot snapshot;
74 store.SaveChanges(snapshot); 76 store.SaveChanges(snapshot);
75 } 77 }
76 78
77 EXPECT_FALSE(base::PathExists(db_path_)); 79 EXPECT_FALSE(base::PathExists(db_path_));
78 } 80 }
79 81
80 // Test changes are persisted to disk when SaveChanges() is called. 82 // Test changes are persisted to disk when SaveChanges() is called.
81 TEST_F(DeferredOnDiskDirectoryBackingStoreTest, PersistWhenSavingValidChanges) { 83 TEST_F(DeferredOnDiskDirectoryBackingStoreTest, PersistWhenSavingValidChanges) {
82 { 84 {
83 // Open and close. 85 // Open and close.
84 DeferredOnDiskDirectoryBackingStore store("test", db_path_); 86 DeferredOnDiskDirectoryBackingStore store("test", db_path_);
85 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_, 87 EXPECT_EQ(OPENED, store.Load(&handles_map_, &delete_journals_,
86 &kernel_load_info_)); 88 &metahandles_to_purge_, &kernel_load_info_));
87 89
88 Directory::SaveChangesSnapshot snapshot; 90 Directory::SaveChangesSnapshot snapshot;
89 EntryKernel* entry = new EntryKernel(); 91 EntryKernel* entry = new EntryKernel();
90 entry->put(ID, Id::CreateFromClientString("test_entry")); 92 entry->put(ID, Id::CreateFromClientString("test_entry"));
91 entry->put(META_HANDLE, 2); 93 entry->put(META_HANDLE, 2);
92 entry->mark_dirty(NULL); 94 entry->mark_dirty(NULL);
93 snapshot.dirty_metas.insert(entry); 95 snapshot.dirty_metas.insert(entry);
94 store.SaveChanges(snapshot); 96 store.SaveChanges(snapshot);
95 } 97 }
96 98
97 STLDeleteValues(&handles_map_); 99 STLDeleteValues(&handles_map_);
98 100
99 ASSERT_TRUE(base::PathExists(db_path_)); 101 ASSERT_TRUE(base::PathExists(db_path_));
100 OnDiskDirectoryBackingStore read_store("test", db_path_); 102 OnDiskDirectoryBackingStore read_store("test", db_path_);
101 EXPECT_EQ(OPENED, read_store.Load(&handles_map_, &delete_journals_, 103 EXPECT_EQ(OPENED,
102 &kernel_load_info_)); 104 read_store.Load(&handles_map_, &delete_journals_,
105 &metahandles_to_purge_, &kernel_load_info_));
103 ASSERT_EQ(2u, handles_map_.size()); 106 ASSERT_EQ(2u, handles_map_.size());
104 ASSERT_TRUE(handles_map_.count(1)); // root node 107 ASSERT_TRUE(handles_map_.count(1)); // root node
105 ASSERT_TRUE(handles_map_.count(2)); 108 ASSERT_TRUE(handles_map_.count(2));
106 EntryKernel* entry = handles_map_[2]; 109 EntryKernel* entry = handles_map_[2];
107 EXPECT_EQ(Id::CreateFromClientString("test_entry"), entry->ref(ID)); 110 EXPECT_EQ(Id::CreateFromClientString("test_entry"), entry->ref(ID));
108 } 111 }
109 112
110 } // namespace 113 } // namespace
111 } // namespace syncable 114 } // namespace syncable
112 } // namespace syncer 115 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698