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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 23694004: sync: Remove IDs from OrderedCommitSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 ASSERT_TRUE(expected_positions.size() == 386 ASSERT_TRUE(expected_positions.size() ==
387 mock_server_->committed_ids().size()); 387 mock_server_->committed_ids().size());
388 // If this test starts failing, be aware other sort orders could be valid. 388 // If this test starts failing, be aware other sort orders could be valid.
389 for (size_t i = 0; i < expected_positions.size(); ++i) { 389 for (size_t i = 0; i < expected_positions.size(); ++i) {
390 EXPECT_EQ(1u, expected_positions.count(i)); 390 EXPECT_EQ(1u, expected_positions.count(i));
391 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]); 391 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]);
392 } 392 }
393 } 393 }
394 394
395 void DoTruncationTest(const vector<int64>& unsynced_handle_view, 395 void DoTruncationTest(const vector<int64>& unsynced_handle_view,
396 const vector<syncable::Id>& expected_id_order) { 396 const vector<int64>& expected_handle_order) {
397 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { 397 for (size_t limit = expected_handle_order.size() + 2; limit > 0; --limit) {
398 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 398 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
399 399
400 ModelSafeRoutingInfo routes; 400 ModelSafeRoutingInfo routes;
401 GetModelSafeRoutingInfo(&routes); 401 GetModelSafeRoutingInfo(&routes);
402 ModelTypeSet types = GetRoutingInfoTypes(routes); 402 ModelTypeSet types = GetRoutingInfoTypes(routes);
403 sessions::OrderedCommitSet output_set(routes); 403 sessions::OrderedCommitSet output_set(routes);
404 GetCommitIdsCommand command(&wtrans, types, limit, &output_set); 404 GetCommitIdsCommand command(&wtrans, types, limit, &output_set);
405 std::set<int64> ready_unsynced_set; 405 std::set<int64> ready_unsynced_set;
406 command.FilterUnreadyEntries(&wtrans, types, 406 command.FilterUnreadyEntries(&wtrans, types,
407 ModelTypeSet(), false, 407 ModelTypeSet(), false,
408 unsynced_handle_view, &ready_unsynced_set); 408 unsynced_handle_view, &ready_unsynced_set);
409 command.BuildCommitIds(&wtrans, routes, ready_unsynced_set); 409 command.BuildCommitIds(&wtrans, routes, ready_unsynced_set);
410 size_t truncated_size = std::min(limit, expected_id_order.size()); 410 size_t truncated_size = std::min(limit, expected_handle_order.size());
411 ASSERT_EQ(truncated_size, output_set.Size()); 411 ASSERT_EQ(truncated_size, output_set.Size());
412 for (size_t i = 0; i < truncated_size; ++i) { 412 for (size_t i = 0; i < truncated_size; ++i) {
413 ASSERT_EQ(expected_id_order[i], output_set.GetCommitIdAt(i)) 413 ASSERT_EQ(expected_handle_order[i], output_set.GetCommitHandleAt(i))
414 << "At index " << i << " with batch size limited to " << limit; 414 << "At index " << i << " with batch size limited to " << limit;
415 } 415 }
416 sessions::OrderedCommitSet::Projection proj; 416 sessions::OrderedCommitSet::Projection proj;
417 proj = output_set.GetCommitIdProjection(GROUP_PASSIVE); 417 proj = output_set.GetCommitIdProjection(GROUP_PASSIVE);
418 ASSERT_EQ(truncated_size, proj.size()); 418 ASSERT_EQ(truncated_size, proj.size());
419 for (size_t i = 0; i < truncated_size; ++i) { 419 for (size_t i = 0; i < truncated_size; ++i) {
420 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i); 420 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i);
421 syncable::Id projected = output_set.GetCommitIdAt(proj[i]); 421 int64 projected = output_set.GetCommitHandleAt(proj[i]);
422 ASSERT_EQ(expected_id_order[proj[i]], projected); 422 ASSERT_EQ(expected_handle_order[proj[i]], projected);
423 // Since this projection is the identity, the following holds. 423 // Since this projection is the identity, the following holds.
424 ASSERT_EQ(expected_id_order[i], projected); 424 ASSERT_EQ(expected_handle_order[i], projected);
425 } 425 }
426 } 426 }
427 } 427 }
428 428
429 const StatusController& status() { 429 const StatusController& status() {
430 return session_->status_controller(); 430 return session_->status_controller();
431 } 431 }
432 432
433 Directory* directory() { 433 Directory* directory() {
434 return dir_maker_.directory(); 434 return dir_maker_.directory();
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 foreign_cache_guid(), "-2"); 593 foreign_cache_guid(), "-2");
594 SyncShareNudge(); 594 SyncShareNudge();
595 595
596 // Create some new client entries. 596 // Create some new client entries.
597 CreateUnsyncedDirectory("C", ids_.MakeLocal("c")); 597 CreateUnsyncedDirectory("C", ids_.MakeLocal("c"));
598 CreateUnsyncedDirectory("B", ids_.MakeLocal("b")); 598 CreateUnsyncedDirectory("B", ids_.MakeLocal("b"));
599 CreateUnsyncedDirectory("D", ids_.MakeLocal("d")); 599 CreateUnsyncedDirectory("D", ids_.MakeLocal("d"));
600 CreateUnsyncedDirectory("E", ids_.MakeLocal("e")); 600 CreateUnsyncedDirectory("E", ids_.MakeLocal("e"));
601 CreateUnsyncedDirectory("J", ids_.MakeLocal("j")); 601 CreateUnsyncedDirectory("J", ids_.MakeLocal("j"));
602 602
603 vector<int64> expected_order;
603 { 604 {
604 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 605 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
605 MutableEntry entry_x(&wtrans, GET_BY_ID, ids_.MakeServer("x")); 606 MutableEntry entry_x(&wtrans, GET_BY_ID, ids_.MakeServer("x"));
606 MutableEntry entry_b(&wtrans, GET_BY_ID, ids_.MakeLocal("b")); 607 MutableEntry entry_b(&wtrans, GET_BY_ID, ids_.MakeLocal("b"));
607 MutableEntry entry_c(&wtrans, GET_BY_ID, ids_.MakeLocal("c")); 608 MutableEntry entry_c(&wtrans, GET_BY_ID, ids_.MakeLocal("c"));
608 MutableEntry entry_d(&wtrans, GET_BY_ID, ids_.MakeLocal("d")); 609 MutableEntry entry_d(&wtrans, GET_BY_ID, ids_.MakeLocal("d"));
609 MutableEntry entry_e(&wtrans, GET_BY_ID, ids_.MakeLocal("e")); 610 MutableEntry entry_e(&wtrans, GET_BY_ID, ids_.MakeLocal("e"));
610 MutableEntry entry_w(&wtrans, GET_BY_ID, ids_.MakeServer("w")); 611 MutableEntry entry_w(&wtrans, GET_BY_ID, ids_.MakeServer("w"));
611 MutableEntry entry_j(&wtrans, GET_BY_ID, ids_.MakeLocal("j")); 612 MutableEntry entry_j(&wtrans, GET_BY_ID, ids_.MakeLocal("j"));
612 entry_x.Put(IS_UNSYNCED, true); 613 entry_x.Put(IS_UNSYNCED, true);
613 entry_b.Put(PARENT_ID, entry_x.Get(ID)); 614 entry_b.Put(PARENT_ID, entry_x.Get(ID));
614 entry_d.Put(PARENT_ID, entry_b.Get(ID)); 615 entry_d.Put(PARENT_ID, entry_b.Get(ID));
615 entry_c.Put(PARENT_ID, entry_x.Get(ID)); 616 entry_c.Put(PARENT_ID, entry_x.Get(ID));
616 entry_c.PutPredecessor(entry_b.Get(ID)); 617 entry_c.PutPredecessor(entry_b.Get(ID));
617 entry_e.Put(PARENT_ID, entry_c.Get(ID)); 618 entry_e.Put(PARENT_ID, entry_c.Get(ID));
618 entry_w.PutPredecessor(entry_x.Get(ID)); 619 entry_w.PutPredecessor(entry_x.Get(ID));
619 entry_w.Put(IS_UNSYNCED, true); 620 entry_w.Put(IS_UNSYNCED, true);
620 entry_w.Put(SERVER_VERSION, 20); 621 entry_w.Put(SERVER_VERSION, 20);
621 entry_w.Put(IS_UNAPPLIED_UPDATE, true); // Fake a conflict. 622 entry_w.Put(IS_UNAPPLIED_UPDATE, true); // Fake a conflict.
622 entry_j.PutPredecessor(entry_w.Get(ID)); 623 entry_j.PutPredecessor(entry_w.Get(ID));
624
625 // The expected order is "x", "b", "c", "d", "e", "j", truncated
626 // appropriately.
627 expected_order.push_back(entry_x.Get(META_HANDLE));
628 expected_order.push_back(entry_b.Get(META_HANDLE));
629 expected_order.push_back(entry_c.Get(META_HANDLE));
630 expected_order.push_back(entry_d.Get(META_HANDLE));
631 expected_order.push_back(entry_e.Get(META_HANDLE));
632 expected_order.push_back(entry_j.Get(META_HANDLE));
623 } 633 }
624 634
625 // The arrangement is now: x (b (d) c (e)) w j 635 // The arrangement is now: x (b (d) c (e)) w j
626 // Entry "w" is in conflict, so it is not eligible for commit. 636 // Entry "w" is in conflict, so it is not eligible for commit.
627 vector<int64> unsynced_handle_view; 637 vector<int64> unsynced_handle_view;
628 vector<syncable::Id> expected_order;
629 { 638 {
630 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 639 syncable::ReadTransaction rtrans(FROM_HERE, directory());
631 GetUnsyncedEntries(&rtrans, &unsynced_handle_view); 640 GetUnsyncedEntries(&rtrans, &unsynced_handle_view);
632 } 641 }
633 // The expected order is "x", "b", "c", "d", "e", "j", truncated
634 // appropriately.
635 expected_order.push_back(ids_.MakeServer("x"));
636 expected_order.push_back(ids_.MakeLocal("b"));
637 expected_order.push_back(ids_.MakeLocal("c"));
638 expected_order.push_back(ids_.MakeLocal("d"));
639 expected_order.push_back(ids_.MakeLocal("e"));
640 expected_order.push_back(ids_.MakeLocal("j"));
641 DoTruncationTest(unsynced_handle_view, expected_order); 642 DoTruncationTest(unsynced_handle_view, expected_order);
642 } 643 }
643 644
644 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { 645 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) {
645 const ModelTypeSet throttled_types(BOOKMARKS); 646 const ModelTypeSet throttled_types(BOOKMARKS);
646 sync_pb::EntitySpecifics bookmark_data; 647 sync_pb::EntitySpecifics bookmark_data;
647 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); 648 AddDefaultFieldValue(BOOKMARKS, &bookmark_data);
648 649
649 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, 650 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10,
650 foreign_cache_guid(), "-1"); 651 foreign_cache_guid(), "-1");
(...skipping 4154 matching lines...) Expand 10 before | Expand all | Expand 10 after
4805 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 4806 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
4806 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 4807 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
4807 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 4808 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
4808 } else { 4809 } else {
4809 EXPECT_TRUE(final_monitor_records.empty()) 4810 EXPECT_TRUE(final_monitor_records.empty())
4810 << "Should not restore records after successful bookmark commit."; 4811 << "Should not restore records after successful bookmark commit.";
4811 } 4812 }
4812 } 4813 }
4813 4814
4814 } // namespace syncer 4815 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/process_commit_response_command_unittest.cc ('k') | sync/sessions/ordered_commit_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698