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

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

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