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

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: Added unit test 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 CLIENT_COUNT = 2;
Nicolas Zea 2015/03/17 01:05:17 nit: const variables should be of the form kCamelC
560 const int SERVER_COUNT = 5;
561 const int TEST_COUNT = CLIENT_COUNT + SERVER_COUNT;
562 int64 handles[TEST_COUNT];
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 < TEST_COUNT; 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 < CLIENT_COUNT) {
585 item.PutId(TestIdFactory::FromNumber(i - CLIENT_COUNT));
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 >= CLIENT_COUNT) {
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
Nicolas Zea 2015/03/17 01:05:17 nit: explain why?
614 std::vector<int64> expected_purged;
615 expected_purged.push_back(0);
616 expected_purged.push_back(5);
617
618 std::vector<int64> actually_purged;
619 {
620 ReadTransaction trans(FROM_HERE, dir().get());
621 for (int i = 0; i < TEST_COUNT; i++) {
622 Entry item(&trans, GET_BY_HANDLE, handles[i]);
623 if (!item.good()) {
624 actually_purged.push_back(i);
625 }
626 }
627 }
628
629 EXPECT_EQ(expected_purged, actually_purged);
630 }
631
555 TEST_F(SyncableDirectoryTest, TestBasicLookupNonExistantID) { 632 TEST_F(SyncableDirectoryTest, TestBasicLookupNonExistantID) {
556 ReadTransaction rtrans(FROM_HERE, dir().get()); 633 ReadTransaction rtrans(FROM_HERE, dir().get());
557 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99)); 634 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99));
558 ASSERT_FALSE(e.good()); 635 ASSERT_FALSE(e.good());
559 } 636 }
560 637
561 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) { 638 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) {
562 CreateEntry(BOOKMARKS, "rtc"); 639 CreateEntry(BOOKMARKS, "rtc");
563 ReadTransaction rtrans(FROM_HERE, dir().get()); 640 ReadTransaction rtrans(FROM_HERE, dir().get());
564 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99)); 641 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); 1953 ASSERT_EQ(1, p_root.GetTotalNodeCount() - 1);
1877 Entry a_root(&trans, GET_BY_ID, a_root_id); 1954 Entry a_root(&trans, GET_BY_ID, a_root_id);
1878 ASSERT_EQ(item2_id, a_root.GetFirstChildId()); 1955 ASSERT_EQ(item2_id, a_root.GetFirstChildId());
1879 ASSERT_EQ(1, a_root.GetTotalNodeCount() - 1); 1956 ASSERT_EQ(1, a_root.GetTotalNodeCount() - 1);
1880 } 1957 }
1881 } 1958 }
1882 1959
1883 } // namespace syncable 1960 } // namespace syncable
1884 1961
1885 } // namespace syncer 1962 } // 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