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(('file-id', 'rev-id'), (), None, 'lines\n') ]) tokens = repo.suspend_write_group() self.assertNotEqual([], tokens) sink.insert_stream((), repo._format, tokens) self.assertEqual([True], call_log)
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(('file-id', 'rev-id'), (), None, 'lines\n') ])] self.assertRaises(errors.BzrError, sink.insert_stream_without_locking, stream, repo._format)
def test_insert_stream_without_locking_fails_without_lock(self): repo = self.make_repository('test-repo') sink = repo._get_sink() stream = [('texts', [ versionedfile.FulltextContentFactory(('file-id', 'rev-id'), (), None, 'lines\n') ])] self.assertRaises(errors.ObjectNotLocked, sink.insert_stream_without_locking, stream, repo._format)
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(('file-id', 'rev-id'), (), None, 'lines\n') ])] missing_keys = sink.insert_stream_without_locking(stream, repo._format) repo.commit_write_group() self.assertEqual(set(), missing_keys)
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. """ tree = self.make_branch_and_tree('source') revid = tree.commit('old') to_repo = self.make_to_repository('to_repo') to_repo.fetch(tree.branch.repository, revid) # 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(('foo', revid), (), None, 'contents') ]) basis = source.revision_tree(revid) parent_id = basis.path2id('') entry = inventory.make_entry('file', 'foo-path', parent_id, 'foo') entry.revision = revid entry.text_size = len('contents') entry.text_sha1 = osutils.sha_string('contents') inv_sha1, _ = source.add_inventory_by_delta( revid, [(None, 'foo-path', 'foo', entry)], 'new', [revid]) rev = Revision(timestamp=0, timezone=None, committer="Foo Bar <*****@*****.**>", message="Message", inventory_sha1=inv_sha1, revision_id='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, 'new') to_repo.lock_read() self.addCleanup(to_repo.unlock) self.assertEqual( 'contents', to_repo.texts.get_record_stream( [('foo', revid)], 'unordered', True).next().get_bytes_as('fulltext'))
def text_stream(): yield versionedfile.FulltextContentFactory(key_base, (), None, 'lines\n') yield versionedfile.FulltextContentFactory(key_delta, (key_base, ), None, 'more\nlines\n')