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

Side by Side Diff: sync/syncable/directory_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: Addressed CR feedback. 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 "sync/syncable/directory_unittest.h" 5 #include "sync/syncable/directory_unittest.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/test/values_test_util.h" 8 #include "base/test/values_test_util.h"
9 #include "sync/internal_api/public/base/attachment_id_proto.h" 9 #include "sync/internal_api/public/base/attachment_id_proto.h"
10 #include "sync/syncable/syncable_proto_util.h" 10 #include "sync/syncable/syncable_proto_util.h"
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 545 }
546 546
547 { 547 {
548 // Verify undeleted entry is gone from database. 548 // Verify undeleted entry is gone from database.
549 ReadTransaction trans(FROM_HERE, dir().get()); 549 ReadTransaction trans(FROM_HERE, dir().get());
550 DeleteJournal* delete_journal = dir()->delete_journal(); 550 DeleteJournal* delete_journal = dir()->delete_journal();
551 ASSERT_EQ(0u, delete_journal->GetDeleteJournalSize(&trans)); 551 ASSERT_EQ(0u, delete_journal->GetDeleteJournalSize(&trans));
552 } 552 }
553 } 553 }
554 554
555 TEST_F(SyncableDirectoryTest, TestPurgeDeletedEntriesOnReload) {
556 sync_pb::EntitySpecifics specifics;
557 AddDefaultFieldValue(PREFERENCES, &specifics);
558
559 const int kClientCount = 2;
560 const int kServerCount = 5;
561 const int kTestCount = kClientCount + kServerCount;
562 int64 handles[kTestCount];
563
564 // The idea is to recreate various combinations of IDs, IS_DEL,
565 // IS_UNSYNCED, and IS_UNAPPLIED_UPDATE flags to test all combinations
566 // for DirectoryBackingStore::SafeToPurgeOnLoading.
567 // 0: client ID, IS_DEL, IS_UNSYNCED
568 // 1: client ID, IS_UNSYNCED
569 // 2: server ID, IS_DEL, IS_UNSYNCED, IS_UNAPPLIED_UPDATE
570 // 3: server ID, IS_DEL, IS_UNSYNCED
571 // 4: server ID, IS_DEL, IS_UNAPPLIED_UPDATE
572 // 5: server ID, IS_DEL
573 // 6: server ID
574 {
575 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get());
576
577 for (int i = 0; i < kTestCount; i++) {
578 std::string name = base::StringPrintf("item%d", i);
579 MutableEntry item(&trans, CREATE, PREFERENCES, trans.root_id(), name);
580 ASSERT_TRUE(item.good());
581
582 handles[i] = item.GetMetahandle();
583
584 if (i < kClientCount) {
585 item.PutId(TestIdFactory::FromNumber(i - kClientCount));
586 } else {
587 item.PutId(TestIdFactory::FromNumber(i));
588 }
589
590 item.PutUniqueClientTag(name);
591 item.PutIsUnsynced(true);
592 item.PutSpecifics(specifics);
593 item.PutServerSpecifics(specifics);
594
595 if (i >= kClientCount) {
596 item.PutBaseVersion(10);
597 item.PutServerVersion(10);
598 }
599
600 // Set flags
601 if (i != 1 && i != 6)
602 item.PutIsDel(true);
603
604 if (i >= 4)
605 item.PutIsUnsynced(false);
606
607 if (i == 2 || i == 4)
608 item.PutIsUnappliedUpdate(true);
609 }
610 }
611 ASSERT_EQ(OPENED, SimulateSaveAndReloadDir());
612
613 // Expect items 0 and 5 to be purged according to
614 // DirectoryBackingStore::SafeToPurgeOnLoading:
615 // - Item 0 is an item with IS_DEL flag and client ID.
616 // - Item 5 is an item with IS_DEL flag which has both
617 // IS_UNSYNCED and IS_UNAPPLIED_UPDATE unset.
618 std::vector<int64> expected_purged;
619 expected_purged.push_back(0);
620 expected_purged.push_back(5);
621
622 std::vector<int64> actually_purged;
623 {
624 ReadTransaction trans(FROM_HERE, dir().get());
625 for (int i = 0; i < kTestCount; i++) {
626 Entry item(&trans, GET_BY_HANDLE, handles[i]);
627 if (!item.good()) {
628 actually_purged.push_back(i);
629 }
630 }
631 }
632
633 EXPECT_EQ(expected_purged, actually_purged);
634 }
635
555 TEST_F(SyncableDirectoryTest, TestBasicLookupNonExistantID) { 636 TEST_F(SyncableDirectoryTest, TestBasicLookupNonExistantID) {
556 ReadTransaction rtrans(FROM_HERE, dir().get()); 637 ReadTransaction rtrans(FROM_HERE, dir().get());
557 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99)); 638 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99));
558 ASSERT_FALSE(e.good()); 639 ASSERT_FALSE(e.good());
559 } 640 }
560 641
561 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) { 642 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) {
562 CreateEntry(BOOKMARKS, "rtc"); 643 CreateEntry(BOOKMARKS, "rtc");
563 ReadTransaction rtrans(FROM_HERE, dir().get()); 644 ReadTransaction rtrans(FROM_HERE, dir().get());
564 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99)); 645 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99));
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 ASSERT_EQ(1, p_root.GetTotalNodeCount() - 1); 1957 ASSERT_EQ(1, p_root.GetTotalNodeCount() - 1);
1877 Entry a_root(&trans, GET_BY_ID, a_root_id); 1958 Entry a_root(&trans, GET_BY_ID, a_root_id);
1878 ASSERT_EQ(item2_id, a_root.GetFirstChildId()); 1959 ASSERT_EQ(item2_id, a_root.GetFirstChildId());
1879 ASSERT_EQ(1, a_root.GetTotalNodeCount() - 1); 1960 ASSERT_EQ(1, a_root.GetTotalNodeCount() - 1);
1880 } 1961 }
1881 } 1962 }
1882 1963
1883 } // namespace syncable 1964 } // namespace syncable
1884 1965
1885 } // namespace syncer 1966 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_backing_store_unittest.cc ('k') | sync/syncable/in_memory_directory_backing_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698