Ejemplo n.º 1
0
    def test_insert_stream_passes_resume_info(self):
        repo = self.make_repository('test-repo')
        if (not repo._format.supports_external_lookups
                or isinstance(repo, remote.RemoteRepository)):
            raise tests.TestNotApplicable(
                'only valid for direct connections to resumable repos')
        # log calls to get_missing_parent_inventories, so that we can assert it
        # is called with the correct parameters
        call_log = []
        orig = repo.get_missing_parent_inventories

        def get_missing(check_for_missing_texts=True):
            call_log.append(check_for_missing_texts)
            return orig(check_for_missing_texts=check_for_missing_texts)

        repo.get_missing_parent_inventories = get_missing
        repo.lock_write()
        self.addCleanup(repo.unlock)
        sink = repo._get_sink()
        sink.insert_stream((), repo._format, [])
        self.assertEqual([False], call_log)
        del call_log[:]
        repo.start_write_group()
        # We need to insert something, or suspend_write_group won't actually
        # create a token
        repo.texts.insert_record_stream([
            versionedfile.FulltextContentFactory((b'file-id', b'rev-id'), (),
                                                 None, b'lines\n')
        ])
        tokens = repo.suspend_write_group()
        self.assertNotEqual([], tokens)
        sink.insert_stream((), repo._format, tokens)
        self.assertEqual([True], call_log)
Ejemplo n.º 2
0
 def test_insert_stream_without_locking_fails_without_lock(self):
     repo = self.make_repository('test-repo')
     sink = repo._get_sink()
     stream = [('texts', [versionedfile.FulltextContentFactory(
         (b'file-id', b'rev-id'), (), None, b'lines\n')])]
     self.assertRaises(errors.ObjectNotLocked,
                       sink.insert_stream_without_locking, stream, repo._format)
Ejemplo n.º 3
0
 def test_insert_stream_without_locking_fails_without_write_group(self):
     repo = self.make_repository('test-repo')
     self.addCleanup(repo.lock_write().unlock)
     sink = repo._get_sink()
     stream = [('texts', [versionedfile.FulltextContentFactory(
         (b'file-id', b'rev-id'), (), None, b'lines\n')])]
     self.assertRaises(errors.BzrError,
                       sink.insert_stream_without_locking, stream, repo._format)
Ejemplo n.º 4
0
 def test_insert_stream_without_locking(self):
     repo = self.make_repository('test-repo')
     self.addCleanup(repo.lock_write().unlock)
     repo.start_write_group()
     sink = repo._get_sink()
     stream = [('texts', [versionedfile.FulltextContentFactory(
         (b'file-id', b'rev-id'), (), None, b'lines\n')])]
     missing_keys = sink.insert_stream_without_locking(stream, repo._format)
     repo.commit_write_group()
     self.assertEqual(set(), missing_keys)
Ejemplo n.º 5
0
    def test_fetch_inconsistent_last_changed_entries(self):
        """If an inventory has odd data we should still get what it references.

        This test tests that we do fetch a file text created in a revision not
        being fetched, but referenced from the revision we are fetching when the
        adjacent revisions to the one being fetched do not reference that text.
        """
        if not self.repository_format.supports_full_versioned_files:
            raise TestNotApplicable('Need full versioned files')
        tree = self.make_branch_and_tree('source')
        revid = tree.commit('old')
        to_repo = self.make_to_repository('to_repo')
        try:
            to_repo.fetch(tree.branch.repository, revid)
        except errors.NoRoundtrippingSupport:
            raise TestNotApplicable('roundtripping not supported')
        # Make a broken revision and fetch it.
        source = tree.branch.repository
        source.lock_write()
        self.addCleanup(source.unlock)
        source.start_write_group()
        try:
            # We need two revisions: OLD and NEW. NEW will claim to need a file
            # 'FOO' changed in 'OLD'. OLD will not have that file at all.
            source.texts.insert_record_stream([
                versionedfile.FulltextContentFactory((b'foo', revid), (), None,
                                                     b'contents')])
            basis = source.revision_tree(revid)
            parent_id = basis.path2id('')
            entry = inventory.make_entry('file', 'foo-path', parent_id, b'foo')
            entry.revision = revid
            entry.text_size = len('contents')
            entry.text_sha1 = osutils.sha_string(b'contents')
            inv_sha1, _ = source.add_inventory_by_delta(revid, [
                (None, 'foo-path', b'foo', entry)], b'new', [revid])
            rev = Revision(timestamp=0,
                           timezone=None,
                           committer="Foo Bar <*****@*****.**>",
                           message="Message",
                           inventory_sha1=inv_sha1,
                           revision_id=b'new',
                           parent_ids=[revid])
            source.add_revision(rev.revision_id, rev)
        except:
            source.abort_write_group()
            raise
        else:
            source.commit_write_group()
        to_repo.fetch(source, b'new')
        to_repo.lock_read()
        self.addCleanup(to_repo.unlock)
        self.assertEqual(b'contents',
                         next(to_repo.texts.get_record_stream([(b'foo', revid)],
                                                              'unordered', True)).get_bytes_as('fulltext'))
Ejemplo n.º 6
0
 def text_stream():
     yield versionedfile.FulltextContentFactory(key_base, (), None,
                                                b'lines\n')
     yield versionedfile.FulltextContentFactory(key_delta, (key_base, ),
                                                None, b'more\nlines\n')