Rev 3622: Add tests for the fetching behavior. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/fetch_regression_256757

John Arbash Meinel john at arbash-meinel.com
Mon Aug 18 23:34:24 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/fetch_regression_256757

------------------------------------------------------------
revno: 3622
revision-id: john at arbash-meinel.com-20080818223421-todjny24vj4faj4t
parent: john at arbash-meinel.com-20080818192544-nohhonfyuaf2ut88
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: fetch_regression_256757
timestamp: Mon 2008-08-18 17:34:21 -0500
message:
  Add tests for the fetching behavior.
  
  The proper parameter passed is 'unordered' add an assert for it, and
  fix callers that were passing 'unsorted' instead.
  Add tests that we make the right get_record_stream call based
  on the value of _fetch_uses_deltas.
  Fix the fetch request for signatures.
modified:
  bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/reconcile.py            reweave_inventory.py-20051108164726-1e5e0934febac06e
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/test_fetch.py     testfetch.py-20050825090644-f73e07e7dfb1765a
-------------- next part --------------
=== modified file 'bzrlib/fetch.py'
--- a/bzrlib/fetch.py	2008-08-18 19:04:32 +0000
+++ b/bzrlib/fetch.py	2008-08-18 22:34:21 +0000
@@ -255,7 +255,7 @@
         to_sf.insert_record_stream(filter_absent(from_sf.get_record_stream(
             [(rev_id,) for rev_id in revs],
             self.to_repository._fetch_order,
-            self.to_repository._fetch_uses_deltas)))
+            not self.to_repository._fetch_uses_deltas)))
         self._fetch_just_revision_texts(revs)
 
     def _fetch_just_revision_texts(self, version_ids):

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2008-08-01 04:06:18 +0000
+++ b/bzrlib/knit.py	2008-08-18 22:34:21 +0000
@@ -1195,6 +1195,10 @@
                     current_source = key_source
                 source_keys[-1][1].append(key)
         else:
+            if ordering != 'unordered':
+                raise AssertionError('valid values for ordering are:'
+                    ' "unordered" or "topological" not: %r'
+                    % (ordering,))
             # Just group by source; remote sources first.
             present_keys = []
             source_keys = []

=== modified file 'bzrlib/reconcile.py'
--- a/bzrlib/reconcile.py	2008-06-11 04:20:16 +0000
+++ b/bzrlib/reconcile.py	2008-08-18 22:34:21 +0000
@@ -245,7 +245,7 @@
         revision_keys = [(rev_id,) for rev_id in
             TopoSorter(self._rev_graph.items()).iter_topo_order()]
         stream = self._change_inv_parents(
-            self.inventory.get_record_stream(revision_keys, 'unsorted', True),
+            self.inventory.get_record_stream(revision_keys, 'unordered', True),
             self._new_inv_parents,
             set(revision_keys))
         new_inventories.insert_record_stream(stream)
@@ -377,7 +377,7 @@
         revision_ids = [key[-1] for key in revision_keys]
         self._setup_steps(len(revision_keys))
         stream = self._change_inv_parents(
-            self.inventory.get_record_stream(revision_keys, 'unsorted', True),
+            self.inventory.get_record_stream(revision_keys, 'unordered', True),
             graph.__getitem__,
             set(revision_keys))
         new_inventories.insert_record_stream(stream)

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2008-08-18 19:13:51 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2008-08-18 22:34:21 +0000
@@ -1719,7 +1719,7 @@
         self._reconcile_does_inventory_gc = True
         self._reconcile_fixes_text_parents = True
         self._reconcile_backsup_inventory = False
-        self._fetch_order = 'unsorted'
+        self._fetch_order = 'unordered'
 
     def _warn_if_deprecated(self):
         # This class isn't deprecated

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2008-08-18 19:15:42 +0000
+++ b/bzrlib/repository.py	2008-08-18 22:34:21 +0000
@@ -691,9 +691,9 @@
         # Additional places to query for data.
         self._fallback_repositories = []
         # What order should fetch operations request streams in?
-        # The default is unsorted as that is the cheapest for an origin to
+        # The default is unordered as that is the cheapest for an origin to
         # provide.
-        self._fetch_order = 'unsorted'
+        self._fetch_order = 'unordered'
         # Does this repository use deltas that can be fetched as-deltas ?
         # (E.g. knits, where the knit deltas can be transplanted intact.
         # We default to False, which will ensure that enough data to get

=== modified file 'bzrlib/tests/test_fetch.py'
--- a/bzrlib/tests/test_fetch.py	2008-07-28 08:43:03 +0000
+++ b/bzrlib/tests/test_fetch.py	2008-08-18 22:34:21 +0000
@@ -24,6 +24,7 @@
     errors,
     merge,
     repository,
+    versionedfile,
     )
 from bzrlib.branch import Branch
 from bzrlib.bzrdir import BzrDir
@@ -329,6 +330,105 @@
         self.assertEqual(4, len(http_logs))
 
 
+class TestKnitToPackFetch(TestCaseWithTransport):
+
+    def find_get_record_stream(self, calls):
+        """In a list of calls, find 'get_record_stream' calls.
+
+        This also ensures that there is only one get_record_stream call.
+        """
+        get_record_call = None
+        for call in calls:
+            if call[0] == 'get_record_stream':
+                self.assertIs(None, get_record_call,
+                              "there should only be one call to"
+                              " get_record_stream")
+                get_record_call = call
+        self.assertIsNot(None, get_record_call,
+                         "there should be exactly one call to "
+                         " get_record_stream")
+        return get_record_call
+
+    def test_fetch_with_deltas_no_delta_closure(self):
+        tree = self.make_branch_and_tree('source', format='dirstate')
+        target = self.make_repository('target', format='pack-0.92')
+        self.build_tree(['source/file'])
+        tree.set_root_id('root-id')
+        tree.add('file', 'file-id')
+        tree.commit('one', rev_id='rev-one')
+        source = tree.branch.repository
+        source.texts = versionedfile.RecordingVersionedFilesDecorator(
+                        source.texts)
+        source.signatures = versionedfile.RecordingVersionedFilesDecorator(
+                        source.signatures)
+        source.revisions = versionedfile.RecordingVersionedFilesDecorator(
+                        source.revisions)
+        source.inventories = versionedfile.RecordingVersionedFilesDecorator(
+                        source.inventories)
+        # precondition
+        self.assertTrue(target._fetch_uses_deltas)
+        target.fetch(source, revision_id='rev-one')
+        self.assertEqual(('get_record_stream', [('file-id', 'rev-one')],
+                          target._fetch_order, False),
+                         self.find_get_record_stream(source.texts.calls))
+        self.assertEqual(('get_record_stream', [('rev-one',)],
+                          target._fetch_order, False),
+                         self.find_get_record_stream(source.inventories.calls))
+        self.assertEqual(('get_record_stream', [('rev-one',)],
+                          target._fetch_order, False),
+                         self.find_get_record_stream(source.revisions.calls))
+        # XXX: Signatures is special, and slightly broken. The
+        # standard item_keys_introduced_by actually does a lookup for every
+        # signature to see if it exists, rather than waiting to do them all at
+        # once at the end. The fetch code then does an all-at-once and just
+        # allows for some of them to be missing.
+        # So we know there will be extra calls, but the *last* one is the one
+        # we care about.
+        signature_calls = source.signatures.calls[-1:]
+        self.assertEqual(('get_record_stream', [('rev-one',)],
+                          target._fetch_order, False),
+                         self.find_get_record_stream(signature_calls))
+
+    def test_fetch_no_deltas_with_delta_closure(self):
+        tree = self.make_branch_and_tree('source', format='dirstate')
+        target = self.make_repository('target', format='pack-0.92')
+        self.build_tree(['source/file'])
+        tree.set_root_id('root-id')
+        tree.add('file', 'file-id')
+        tree.commit('one', rev_id='rev-one')
+        source = tree.branch.repository
+        source.texts = versionedfile.RecordingVersionedFilesDecorator(
+                        source.texts)
+        source.signatures = versionedfile.RecordingVersionedFilesDecorator(
+                        source.signatures)
+        source.revisions = versionedfile.RecordingVersionedFilesDecorator(
+                        source.revisions)
+        source.inventories = versionedfile.RecordingVersionedFilesDecorator(
+                        source.inventories)
+        target._fetch_uses_deltas = False
+        target.fetch(source, revision_id='rev-one')
+        self.assertEqual(('get_record_stream', [('file-id', 'rev-one')],
+                          target._fetch_order, True),
+                         self.find_get_record_stream(source.texts.calls))
+        self.assertEqual(('get_record_stream', [('rev-one',)],
+                          target._fetch_order, True),
+                         self.find_get_record_stream(source.inventories.calls))
+        self.assertEqual(('get_record_stream', [('rev-one',)],
+                          target._fetch_order, True),
+                         self.find_get_record_stream(source.revisions.calls))
+        # XXX: Signatures is special, and slightly broken. The
+        # standard item_keys_introduced_by actually does a lookup for every
+        # signature to see if it exists, rather than waiting to do them all at
+        # once at the end. The fetch code then does an all-at-once and just
+        # allows for some of them to be missing.
+        # So we know there will be extra calls, but the *last* one is the one
+        # we care about.
+        signature_calls = source.signatures.calls[-1:]
+        self.assertEqual(('get_record_stream', [('rev-one',)],
+                          target._fetch_order, True),
+                         self.find_get_record_stream(signature_calls))
+
+
 class Test1To2Fetch(TestCaseWithTransport):
     """Tests for Model1To2 failure modes"""
 



More information about the bazaar-commits mailing list