Rev 4538: Start working on tests that get_record_stream gives reasonable results w/ stacking. in http://bazaar.launchpad.net/~jameinel/bzr/1.18-stack-and-annotate-393366

John Arbash Meinel john at arbash-meinel.com
Wed Jul 15 18:51:46 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/1.18-stack-and-annotate-393366

------------------------------------------------------------
revno: 4538
revision-id: john at arbash-meinel.com-20090715175140-qlawjpy5w97ulg8j
parent: pqm at pqm.ubuntu.com-20090715083553-ssotnv68cr0x5yxr
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.18-stack-and-annotate-393366
timestamp: Wed 2009-07-15 12:51:40 -0500
message:
  Start working on tests that get_record_stream gives reasonable results w/ stacking.
-------------- next part --------------
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2009-07-08 23:10:47 +0000
+++ b/bzrlib/knit.py	2009-07-15 17:51:40 +0000
@@ -1489,7 +1489,8 @@
                                                                 non_local_keys,
                                                                 positions):
                 generator = _VFContentMapGenerator(self, keys, non_local_keys,
-                                                   global_map)
+                                                   global_map,
+                                                   ordering=ordering)
                 for record in generator.get_record_stream():
                     yield record
         else:
@@ -1993,6 +1994,9 @@
 class _ContentMapGenerator(object):
     """Generate texts or expose raw deltas for a set of texts."""
 
+    def __init__(self, ordering='unordered'):
+        self._ordering = ordering
+
     def _get_content(self, key):
         """Get the content object for key."""
         # Note that _get_content is only called when the _ContentMapGenerator
@@ -2032,7 +2036,7 @@
             # Loop over fallback repositories asking them for texts - ignore
             # any missing from a particular fallback.
             for record in source.get_record_stream(missing_keys,
-                'unordered', True):
+                self._ordering, True):
                 if record.storage_kind == 'absent':
                     # Not in thie particular stream, may be in one of the
                     # other fallback vfs objects.
@@ -2170,7 +2174,7 @@
     """Content map generator reading from a VersionedFiles object."""
 
     def __init__(self, versioned_files, keys, nonlocal_keys=None,
-        global_map=None, raw_record_map=None):
+        global_map=None, raw_record_map=None, ordering='unordered'):
         """Create a _ContentMapGenerator.
 
         :param versioned_files: The versioned files that the texts are being
@@ -2184,6 +2188,7 @@
         :param raw_record_map: A unparsed raw record map to use for answering
             contents.
         """
+        _ContentMapGenerator.__init__(self, ordering=ordering)
         # The vf to source data from
         self.vf = versioned_files
         # The keys desired

=== modified file 'bzrlib/tests/per_repository_reference/__init__.py'
--- a/bzrlib/tests/per_repository_reference/__init__.py	2009-06-15 06:47:14 +0000
+++ b/bzrlib/tests/per_repository_reference/__init__.py	2009-07-15 17:51:40 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Canonical Ltd
+# Copyright (C) 2008, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -98,6 +98,7 @@
         'bzrlib.tests.per_repository_reference.test_check',
         'bzrlib.tests.per_repository_reference.test_default_stacking',
         'bzrlib.tests.per_repository_reference.test_fetch',
+        'bzrlib.tests.per_repository_reference.test_get_record_stream',
         'bzrlib.tests.per_repository_reference.test_get_rev_id_for_revno',
         'bzrlib.tests.per_repository_reference.test_initialize',
         'bzrlib.tests.per_repository_reference.test_unlock',

=== added file 'bzrlib/tests/per_repository_reference/test_get_record_stream.py'
--- a/bzrlib/tests/per_repository_reference/test_get_record_stream.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_repository_reference/test_get_record_stream.py	2009-07-15 17:51:40 +0000
@@ -0,0 +1,102 @@
+# Copyright (C) 2008, 2009 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Tests that get_record_stream() behaves itself properly when stacked."""
+
+from bzrlib import errors
+from bzrlib.tests.per_repository_reference import (
+    TestCaseWithExternalReferenceRepository,
+    )
+
+
+class TestGetRecordStream(TestCaseWithExternalReferenceRepository):
+
+    def setUp(self):
+        super(TestGetRecordStream, self).setUp()
+        builder = self.make_branch_builder('all')
+        builder.start_series()
+        # Graph of revisions:
+        #
+        #   A
+        #   |\
+        #   B C
+        #   |/|
+        #   D E
+        #   |\|
+        #   F G
+        # These can be split up among the different repos as desired
+        #
+
+        builder.build_snapshot('A', None, [
+            ('add', ('', 'root-id', 'directory', None)),
+            ('add', ('file', 'f-id', 'file', 'initial content\n')),
+            ])
+        builder.build_snapshot('B', ['A'], [
+            ('modify', ('f-id', 'initial content\n'
+                                'and B content\n')),
+            ])
+        builder.build_snapshot('C', ['A'], [
+            ('modify', ('f-id', 'initial content\n'
+                                'and C content\n')),
+            ])
+        builder.build_snapshot('D', ['B', 'C'], [
+            ('modify', ('f-id', 'initial content\n'
+                                'and B content\n'
+                                'and C content\n')),
+            ])
+        builder.build_snapshot('E', ['C'], [
+            ('modify', ('f-id', 'initial content\n'
+                                'and C content\n'
+                                'and E content\n')),
+            ])
+        builder.build_snapshot('F', ['D'], [
+            ('modify', ('f-id', 'initial content\n'
+                                'and B content\n'
+                                'and C content\n'
+                                'and F content\n')),
+            ])
+        builder.build_snapshot('G', ['E', 'D'], [
+            ('modify', ('f-id', 'initial content\n'
+                                'and B content\n'
+                                'and C content\n'
+                                'and E content\n')),
+            ])
+        builder.finish_series()
+        self.all_repo = builder.get_branch().repository
+        self.all_repo.lock_read()
+        self.addCleanup(self.all_repo.unlock)
+        self.base_repo = self.make_repository('base')
+        self.stacked_repo = self.make_referring('referring', 'base')
+
+    def make_stacked_hold_f(self):
+        """Set up the repositories so that everything is in base except F"""
+        self.base_repo.fetch(self.all_repo, revision_id='G')
+        self.stacked_repo.fetch(self.all_repo, revision_id='F')
+
+    def test_unordered_fetch(self):
+        self.make_stacked_hold_f()
+        keys = [('f-id', r) for r in ['A', 'B', 'C', 'D', 'F']]
+        self.stacked_repo.lock_read()
+        self.addCleanup(self.stacked_repo.unlock)
+        stream = self.stacked_repo.texts.get_record_stream(
+            keys, 'unordered', False)
+        record_keys = set()
+        for record in stream:
+            if record.storage_kind == 'absent':
+                raise ValueError('absent record: %s' % (record.key,))
+            record_keys.add(record.key)
+        # everything should be present, we don't care about the order
+        self.assertEqual(keys, sorted(record_keys))



More information about the bazaar-commits mailing list