Ejemplo n.º 1
0
    def testGetChangesFromTimestampZeroForEachType(self):
        for sync_type in chromiumsync.ALL_TYPES:
            self.model = chromiumsync.SyncDataModel()
            request_types = [sync_type, chromiumsync.TOP_LEVEL]

            version, changes = self.model.GetChangesFromTimestamp(
                request_types, 0)

            expected_count = self.ExpectedPermanentItemCount(sync_type)
            self.assertEqual(expected_count, version)
            self.assertEqual(expected_count, len(changes))
            self.assertEqual('google_chrome',
                             changes[0].server_defined_unique_tag)
            for change in changes:
                self.assertTrue(change.HasField('server_defined_unique_tag'))
                self.assertEqual(change.version, change.sync_timestamp)
                self.assertTrue(change.version <= version)

            # Test idempotence: another GetUpdates from ts=0 shouldn't recreate.
            version, changes = self.model.GetChangesFromTimestamp(
                request_types, 0)
            self.assertEqual(expected_count, version)
            self.assertEqual(expected_count, len(changes))

            # Doing a wider GetUpdates from timestamp zero shouldn't recreate either.
            new_version, changes = self.model.GetChangesFromTimestamp(
                chromiumsync.ALL_TYPES, 0)
            self.assertEqual(
                len(chromiumsync.SyncDataModel._PERMANENT_ITEM_SPECS),
                new_version)
            self.assertEqual(new_version, len(changes))
            version, changes = self.model.GetChangesFromTimestamp(
                request_types, 0)
            self.assertEqual(new_version, version)
            self.assertEqual(expected_count, len(changes))
Ejemplo n.º 2
0
    def testBatchSize(self):
        for sync_type in chromiumsync.ALL_TYPES[1:]:
            specifics = chromiumsync.GetDefaultEntitySpecifics(sync_type)
            self.model = chromiumsync.SyncDataModel()
            request_types = [sync_type]

            for i in range(self.model._BATCH_SIZE * 3):
                entry = sync_pb2.SyncEntity()
                entry.id_string = 'batch test %d' % i
                entry.specifics.CopyFrom(specifics)
                self.model._SaveEntry(entry)
            last_bit = self.ExpectedPermanentItemCount(sync_type)
            version, changes, changes_remaining = (
                self.GetChangesFromTimestamp(request_types, 0))
            self.assertEqual(self.model._BATCH_SIZE, version)
            self.assertEqual(self.model._BATCH_SIZE * 2 + last_bit,
                             changes_remaining)
            version, changes, changes_remaining = (
                self.GetChangesFromTimestamp(request_types, version))
            self.assertEqual(self.model._BATCH_SIZE * 2, version)
            self.assertEqual(self.model._BATCH_SIZE + last_bit,
                             changes_remaining)
            version, changes, changes_remaining = (
                self.GetChangesFromTimestamp(request_types, version))
            self.assertEqual(self.model._BATCH_SIZE * 3, version)
            self.assertEqual(last_bit, changes_remaining)
            version, changes, changes_remaining = (
                self.GetChangesFromTimestamp(request_types, version))
            self.assertEqual(self.model._BATCH_SIZE * 3 + last_bit, version)
            self.assertEqual(0, changes_remaining)

            # Now delete a third of the items.
            for i in xrange(self.model._BATCH_SIZE * 3 - 1, 0, -3):
                entry = sync_pb2.SyncEntity()
                entry.id_string = 'batch test %d' % i
                entry.deleted = True
                self.model._SaveEntry(entry)

            # The batch counts shouldn't change.
            version, changes, changes_remaining = (
                self.GetChangesFromTimestamp(request_types, 0))
            self.assertEqual(self.model._BATCH_SIZE, len(changes))
            self.assertEqual(self.model._BATCH_SIZE * 2 + last_bit,
                             changes_remaining)
            version, changes, changes_remaining = (
                self.GetChangesFromTimestamp(request_types, version))
            self.assertEqual(self.model._BATCH_SIZE, len(changes))
            self.assertEqual(self.model._BATCH_SIZE + last_bit,
                             changes_remaining)
            version, changes, changes_remaining = (
                self.GetChangesFromTimestamp(request_types, version))
            self.assertEqual(self.model._BATCH_SIZE, len(changes))
            self.assertEqual(last_bit, changes_remaining)
            version, changes, changes_remaining = (
                self.GetChangesFromTimestamp(request_types, version))
            self.assertEqual(last_bit, len(changes))
            self.assertEqual(self.model._BATCH_SIZE * 4 + last_bit, version)
            self.assertEqual(0, changes_remaining)
Ejemplo n.º 3
0
    def testGetChangesFromTimestampZeroForEachType(self):
        all_types = chromiumsync.ALL_TYPES[1:]
        for sync_type in all_types:
            self.model = chromiumsync.SyncDataModel()
            request_types = [sync_type]

            version, changes, remaining = (self.GetChangesFromTimestamp(
                request_types, 0))

            expected_count = self.ExpectedPermanentItemCount(sync_type)
            self.assertEqual(expected_count, version)
            self.assertEqual(expected_count, len(changes))
            self.assertEqual('google_chrome',
                             changes[0].server_defined_unique_tag)
            for change in changes:
                self.assertTrue(change.HasField('server_defined_unique_tag'))
                self.assertEqual(change.version, change.sync_timestamp)
                self.assertTrue(change.version <= version)

            # Test idempotence: another GetUpdates from ts=0 shouldn't recreate.
            version, changes, remaining = (self.GetChangesFromTimestamp(
                request_types, 0))
            self.assertEqual(expected_count, version)
            self.assertEqual(expected_count, len(changes))
            self.assertEqual(0, remaining)

            # Doing a wider GetUpdates from timestamp zero shouldn't recreate either.
            new_version, changes, remaining = (self.GetChangesFromTimestamp(
                all_types, 0))
            if self._expect_synced_bookmarks_folder:
                self.assertEqual(
                    len(chromiumsync.SyncDataModel._PERMANENT_ITEM_SPECS),
                    new_version)
            else:
                self.assertEqual(
                    len(chromiumsync.SyncDataModel._PERMANENT_ITEM_SPECS) - 1,
                    new_version)
            self.assertEqual(new_version, len(changes))
            self.assertEqual(0, remaining)
            version, changes, remaining = (self.GetChangesFromTimestamp(
                request_types, 0))
            self.assertEqual(new_version, version)
            self.assertEqual(expected_count, len(changes))
            self.assertEqual(0, remaining)
Ejemplo n.º 4
0
    def testCommitEachDataType(self):
        for sync_type in chromiumsync.ALL_TYPES[1:]:
            specifics = chromiumsync.GetDefaultEntitySpecifics(sync_type)
            self.model = chromiumsync.SyncDataModel()
            my_cache_guid = '112358132134'
            parent = 'foobar'
            commit_session = {}

            # Start with a GetUpdates from timestamp 0, to populate permanent items.
            original_version, original_changes, changes_remaining = (
                self.GetChangesFromTimestamp([sync_type], 0))

            def DoCommit(original=None,
                         id_string='',
                         name=None,
                         parent=None,
                         position=0):
                proto = sync_pb2.SyncEntity()
                if original is not None:
                    proto.version = original.version
                    proto.id_string = original.id_string
                    proto.parent_id_string = original.parent_id_string
                    proto.name = original.name
                else:
                    proto.id_string = id_string
                    proto.version = 0
                proto.specifics.CopyFrom(specifics)
                if name is not None:
                    proto.name = name
                if parent:
                    proto.parent_id_string = parent.id_string
                proto.insert_after_item_id = 'please discard'
                proto.position_in_parent = position
                proto.folder = True
                proto.deleted = False
                result = self.model.CommitEntry(proto, my_cache_guid,
                                                commit_session)
                self.assertTrue(result)
                return (proto, result)

            # Commit a new item.
            proto1, result1 = DoCommit(name='namae',
                                       id_string='Foo',
                                       parent=original_changes[-1],
                                       position=100)
            # Commit an item whose parent is another item (referenced via the
            # pre-commit ID).
            proto2, result2 = DoCommit(name='Secondo',
                                       id_string='Bar',
                                       parent=proto1,
                                       position=-100)
            # Commit a sibling of the second item.
            proto3, result3 = DoCommit(name='Third!',
                                       id_string='Baz',
                                       parent=proto1,
                                       position=-50)

            self.assertEqual(3, len(commit_session))
            for p, r in [(proto1, result1), (proto2, result2),
                         (proto3, result3)]:
                self.assertNotEqual(r.id_string, p.id_string)
                self.assertEqual(r.originator_client_item_id, p.id_string)
                self.assertEqual(r.originator_cache_guid, my_cache_guid)
                self.assertTrue(r is not self.model._entries[r.id_string],
                                "Commit result didn't make a defensive copy.")
                self.assertTrue(p is not self.model._entries[r.id_string],
                                "Commit result didn't make a defensive copy.")
                self.assertEqual(commit_session.get(p.id_string), r.id_string)
                self.assertTrue(r.version > original_version)
            self.assertEqual(result1.parent_id_string, proto1.parent_id_string)
            self.assertEqual(result2.parent_id_string, result1.id_string)
            version, changes, remaining = (self.GetChangesFromTimestamp(
                [sync_type], original_version))
            self.assertEqual(3, len(changes))
            self.assertEqual(0, remaining)
            self.assertEqual(original_version + 3, version)
            self.assertEqual([result1, result2, result3], changes)
            for c in changes:
                self.assertTrue(c is not self.model._entries[c.id_string],
                                "GetChanges didn't make a defensive copy.")
            self.assertTrue(
                result2.position_in_parent < result3.position_in_parent)
            self.assertEqual(-100, result2.position_in_parent)

            # Now update the items so that the second item is the parent of the
            # first; with the first sandwiched between two new items (4 and 5).
            # Do this in a new commit session, meaning we'll reference items from
            # the first batch by their post-commit, server IDs.
            commit_session = {}
            old_cache_guid = my_cache_guid
            my_cache_guid = 'A different GUID'
            proto2b, result2b = DoCommit(original=result2,
                                         parent=original_changes[-1])
            proto4, result4 = DoCommit(id_string='ID4',
                                       name='Four',
                                       parent=result2,
                                       position=-200)
            proto1b, result1b = DoCommit(original=result1,
                                         parent=result2,
                                         position=-150)
            proto5, result5 = DoCommit(id_string='ID5',
                                       name='Five',
                                       parent=result2,
                                       position=150)

            self.assertEqual(
                2, len(commit_session), 'Only new items in second '
                'batch should be in the session')
            for p, r, original in [(proto2b, result2b, proto2),
                                   (proto4, result4, proto4),
                                   (proto1b, result1b, proto1),
                                   (proto5, result5, proto5)]:
                self.assertEqual(r.originator_client_item_id,
                                 original.id_string)
                if original is not p:
                    self.assertEqual(
                        r.id_string, p.id_string,
                        'Ids should be stable after first commit')
                    self.assertEqual(r.originator_cache_guid, old_cache_guid)
                else:
                    self.assertNotEqual(r.id_string, p.id_string)
                    self.assertEqual(r.originator_cache_guid, my_cache_guid)
                    self.assertEqual(commit_session.get(p.id_string),
                                     r.id_string)
                self.assertTrue(r is not self.model._entries[r.id_string],
                                "Commit result didn't make a defensive copy.")
                self.assertTrue(p is not self.model._entries[r.id_string],
                                "Commit didn't make a defensive copy.")
                self.assertTrue(r.version > p.version)
            version, changes, remaining = (self.GetChangesFromTimestamp(
                [sync_type], original_version))
            self.assertEqual(5, len(changes))
            self.assertEqual(0, remaining)
            self.assertEqual(original_version + 7, version)
            self.assertEqual([result3, result2b, result4, result1b, result5],
                             changes)
            for c in changes:
                self.assertTrue(c is not self.model._entries[c.id_string],
                                "GetChanges didn't make a defensive copy.")
            self.assertTrue(
                result4.parent_id_string == result1b.parent_id_string ==
                result5.parent_id_string == result2b.id_string)
            self.assertTrue(result4.position_in_parent < result1b.
                            position_in_parent < result5.position_in_parent)
Ejemplo n.º 5
0
 def setUp(self):
     self.model = chromiumsync.SyncDataModel()
     # The Synced Bookmarks folder is not created by default
     self._expect_synced_bookmarks_folder = False
Ejemplo n.º 6
0
 def setUp(self):
   self.model = chromiumsync.SyncDataModel()