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

Side by Side Diff: sync/internal_api/sync_rollback_manager_unittest.cc

Issue 477813002: Revert of Let SyncBackupManager keep backup data in memory until shutdown. Only persist (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 "sync/internal_api/sync_rollback_manager.h" 5 #include "sync/internal_api/sync_rollback_manager.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "sync/internal_api/public/read_node.h" 9 #include "sync/internal_api/public/read_node.h"
10 #include "sync/internal_api/public/read_transaction.h" 10 #include "sync/internal_api/public/read_transaction.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 ReadNode type_root(&trans); 95 ReadNode type_root(&trans);
96 EXPECT_EQ(BaseNode::INIT_OK, type_root.InitTypeRoot(type)); 96 EXPECT_EQ(BaseNode::INIT_OK, type_root.InitTypeRoot(type));
97 97
98 WriteNode node(&trans); 98 WriteNode node(&trans);
99 EXPECT_EQ(WriteNode::INIT_SUCCESS, 99 EXPECT_EQ(WriteNode::INIT_SUCCESS,
100 node.InitUniqueByCreation(type, type_root, client_tag)); 100 node.InitUniqueByCreation(type, type_root, client_tag));
101 return node.GetEntry()->GetMetahandle(); 101 return node.GetEntry()->GetMetahandle();
102 } 102 }
103 103
104 void InitManager(SyncManager* manager, ModelTypeSet types, 104 void InitManager(SyncManager* manager, ModelTypeSet types,
105 TestChangeDelegate* delegate, 105 TestChangeDelegate* delegate, StorageOption storage_option) {
106 InternalComponentsFactory::StorageOption storage_option) {
107 manager_ = manager; 106 manager_ = manager;
108 types_ = types; 107 types_ = types;
109 108
110 EXPECT_CALL(*this, OnInitializationComplete(_, _, _, _)) 109 EXPECT_CALL(*this, OnInitializationComplete(_, _, _, _))
111 .WillOnce(WithArgs<2>(Invoke(this, 110 .WillOnce(WithArgs<2>(Invoke(this,
112 &SyncRollbackManagerTest::HandleInit))); 111 &SyncRollbackManagerTest::HandleInit)));
113 112
114 manager->AddObserver(this); 113 manager->AddObserver(this);
115 114
116 base::RunLoop run_loop; 115 base::RunLoop run_loop;
117 SyncManager::InitArgs args; 116 SyncManager::InitArgs args;
118 args.database_location = temp_dir_.path(); 117 args.database_location = temp_dir_.path();
119 args.service_url = GURL("https://example.com/"); 118 args.service_url = GURL("https://example.com/");
120 args.workers.push_back(worker_); 119 args.workers.push_back(worker_);
121 args.change_delegate = delegate; 120 args.change_delegate = delegate;
122
123 InternalComponentsFactory::StorageOption storage_used;
124 args.internal_components_factory.reset(new TestInternalComponentsFactory( 121 args.internal_components_factory.reset(new TestInternalComponentsFactory(
125 InternalComponentsFactory::Switches(), storage_option, &storage_used)); 122 InternalComponentsFactory::Switches(), storage_option));
126 manager->Init(&args); 123 manager->Init(&args);
127 EXPECT_EQ(storage_option, storage_used);
128 loop_.PostTask(FROM_HERE, run_loop.QuitClosure()); 124 loop_.PostTask(FROM_HERE, run_loop.QuitClosure());
129 run_loop.Run(); 125 run_loop.Run();
130 } 126 }
131 127
132 // Create and persist an entry by unique tag in DB. 128 // Create and persist an entry by unique tag in DB.
133 void PrepopulateDb(ModelType type, const std::string& client_tag) { 129 void PrepopulateDb(ModelType type, const std::string& client_tag) {
134 SyncBackupManager backup_manager; 130 SyncBackupManager backup_manager;
135 TestChangeDelegate delegate; 131 TestChangeDelegate delegate;
136 InitManager(&backup_manager, ModelTypeSet(type), &delegate, 132 InitManager(&backup_manager, ModelTypeSet(type), &delegate,
137 InternalComponentsFactory::STORAGE_ON_DISK_DEFERRED); 133 STORAGE_ON_DISK);
138 CreateEntry(backup_manager.GetUserShare(), type, client_tag); 134 CreateEntry(backup_manager.GetUserShare(), type, client_tag);
139 backup_manager.ShutdownOnSyncThread(SWITCH_MODE_SYNC); 135 backup_manager.ShutdownOnSyncThread(STOP_SYNC);
140 } 136 }
141 137
142 // Verify entry with |client_tag| exists in sync directory. 138 // Verify entry with |client_tag| exists in sync directory.
143 bool VerifyEntry(UserShare* user_share, ModelType type, 139 bool VerifyEntry(UserShare* user_share, ModelType type,
144 const std::string& client_tag) { 140 const std::string& client_tag) {
145 ReadTransaction trans(FROM_HERE, user_share); 141 ReadTransaction trans(FROM_HERE, user_share);
146 ReadNode node(&trans); 142 ReadNode node(&trans);
147 return BaseNode::INIT_OK == node.InitByClientTagLookup(type, client_tag); 143 return BaseNode::INIT_OK == node.InitByClientTagLookup(type, client_tag);
148 } 144 }
149 145
(...skipping 30 matching lines...) Expand all
180 bool IsRollbackDoneAction(SyncProtocolError e) { 176 bool IsRollbackDoneAction(SyncProtocolError e) {
181 return e.action == syncer::ROLLBACK_DONE; 177 return e.action == syncer::ROLLBACK_DONE;
182 } 178 }
183 179
184 TEST_F(SyncRollbackManagerTest, RollbackBasic) { 180 TEST_F(SyncRollbackManagerTest, RollbackBasic) {
185 PrepopulateDb(PREFERENCES, "pref1"); 181 PrepopulateDb(PREFERENCES, "pref1");
186 182
187 TestChangeDelegate delegate; 183 TestChangeDelegate delegate;
188 SyncRollbackManager rollback_manager; 184 SyncRollbackManager rollback_manager;
189 InitManager(&rollback_manager, ModelTypeSet(PREFERENCES), &delegate, 185 InitManager(&rollback_manager, ModelTypeSet(PREFERENCES), &delegate,
190 InternalComponentsFactory::STORAGE_ON_DISK); 186 STORAGE_ON_DISK);
191 187
192 // Simulate a new entry added during type initialization. 188 // Simulate a new entry added during type initialization.
193 int64 new_pref_id = 189 int64 new_pref_id =
194 CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2"); 190 CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2");
195 191
196 delegate.add_expected_delete(new_pref_id); 192 delegate.add_expected_delete(new_pref_id);
197 EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _)) 193 EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _))
198 .Times(1) 194 .Times(1)
199 .WillOnce(DoDefault()); 195 .WillOnce(DoDefault());
200 EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1); 196 EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1);
201 EXPECT_CALL(*this, OnActionableError(Truly(IsRollbackDoneAction))).Times(1); 197 EXPECT_CALL(*this, OnActionableError(Truly(IsRollbackDoneAction))).Times(1);
202 198
203 ModelSafeRoutingInfo routing_info; 199 ModelSafeRoutingInfo routing_info;
204 routing_info[PREFERENCES] = GROUP_UI; 200 routing_info[PREFERENCES] = GROUP_UI;
205 rollback_manager.StartSyncingNormally(routing_info); 201 rollback_manager.StartSyncingNormally(routing_info);
206 } 202 }
207 203
208 TEST_F(SyncRollbackManagerTest, NoRollbackOfTypesNotBackedUp) { 204 TEST_F(SyncRollbackManagerTest, NoRollbackOfTypesNotBackedUp) {
209 PrepopulateDb(PREFERENCES, "pref1"); 205 PrepopulateDb(PREFERENCES, "pref1");
210 206
211 TestChangeDelegate delegate; 207 TestChangeDelegate delegate;
212 SyncRollbackManager rollback_manager; 208 SyncRollbackManager rollback_manager;
213 InitManager(&rollback_manager, ModelTypeSet(PREFERENCES, APPS), &delegate, 209 InitManager(&rollback_manager, ModelTypeSet(PREFERENCES, APPS), &delegate,
214 InternalComponentsFactory::STORAGE_ON_DISK); 210 STORAGE_ON_DISK);
215 211
216 // Simulate new entry added during type initialization. 212 // Simulate new entry added during type initialization.
217 int64 new_pref_id = 213 int64 new_pref_id =
218 CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2"); 214 CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2");
219 CreateEntry(rollback_manager.GetUserShare(), APPS, "app1"); 215 CreateEntry(rollback_manager.GetUserShare(), APPS, "app1");
220 216
221 delegate.add_expected_delete(new_pref_id); 217 delegate.add_expected_delete(new_pref_id);
222 EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _)) 218 EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _))
223 .Times(1) 219 .Times(1)
224 .WillOnce(DoDefault()); 220 .WillOnce(DoDefault());
225 EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1); 221 EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1);
226 222
227 ModelSafeRoutingInfo routing_info; 223 ModelSafeRoutingInfo routing_info;
228 routing_info[PREFERENCES] = GROUP_UI; 224 routing_info[PREFERENCES] = GROUP_UI;
229 rollback_manager.StartSyncingNormally(routing_info); 225 rollback_manager.StartSyncingNormally(routing_info);
230 226
231 // APP entry is still valid. 227 // APP entry is still valid.
232 EXPECT_TRUE(VerifyEntry(rollback_manager.GetUserShare(), APPS, "app1")); 228 EXPECT_TRUE(VerifyEntry(rollback_manager.GetUserShare(), APPS, "app1"));
233 } 229 }
234 230
235 TEST_F(SyncRollbackManagerTest, BackupDbNotChangedOnAbort) { 231 TEST_F(SyncRollbackManagerTest, BackupDbNotChangedOnAbort) {
236 PrepopulateDb(PREFERENCES, "pref1"); 232 PrepopulateDb(PREFERENCES, "pref1");
237 233
238 TestChangeDelegate delegate; 234 TestChangeDelegate delegate;
239 scoped_ptr<SyncRollbackManager> rollback_manager( 235 scoped_ptr<SyncRollbackManager> rollback_manager(
240 new SyncRollbackManager); 236 new SyncRollbackManager);
241 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate, 237 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate,
242 InternalComponentsFactory::STORAGE_ON_DISK); 238 STORAGE_ON_DISK);
243 239
244 // Simulate a new entry added during type initialization. 240 // Simulate a new entry added during type initialization.
245 CreateEntry(rollback_manager->GetUserShare(), PREFERENCES, "pref2"); 241 CreateEntry(rollback_manager->GetUserShare(), PREFERENCES, "pref2");
246 242
247 // Manager was shut down before sync starts. 243 // Manager was shut down before sync starts.
248 rollback_manager->ShutdownOnSyncThread(STOP_SYNC); 244 rollback_manager->ShutdownOnSyncThread(STOP_SYNC);
249 245
250 // Verify new entry was not persisted. 246 // Verify new entry was not persisted.
251 rollback_manager.reset(new SyncRollbackManager); 247 rollback_manager.reset(new SyncRollbackManager);
252 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate, 248 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate,
253 InternalComponentsFactory::STORAGE_ON_DISK); 249 STORAGE_ON_DISK);
254 EXPECT_FALSE(VerifyEntry(rollback_manager->GetUserShare(), PREFERENCES, 250 EXPECT_FALSE(VerifyEntry(rollback_manager->GetUserShare(), PREFERENCES,
255 "pref2")); 251 "pref2"));
256 } 252 }
257 253
258 TEST_F(SyncRollbackManagerTest, OnInitializationFailure) { 254 TEST_F(SyncRollbackManagerTest, OnInitializationFailure) {
259 // Test graceful shutdown on initialization failure. 255 // Test graceful shutdown on initialization failure.
260 scoped_ptr<SyncRollbackManager> rollback_manager( 256 scoped_ptr<SyncRollbackManager> rollback_manager(
261 new SyncRollbackManager); 257 new SyncRollbackManager);
262 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), NULL, 258 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), NULL,
263 InternalComponentsFactory::STORAGE_ON_DISK); 259 STORAGE_ON_DISK);
264 } 260 }
265 261
266 } // anonymous namespace 262 } // anonymous namespace
267 263
268 } // namespace syncer 264 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_rollback_manager_base_unittest.cc ('k') | sync/internal_api/test/test_internal_components_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698