Rev 3802: Add a multiple-record test, though it isn't quite what we want for the readv tests. in http://bzr.arbash-meinel.com/branches/bzr/1.9-dev/pack_retry_153786
John Arbash Meinel
john at arbash-meinel.com
Fri Oct 24 21:54:04 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.9-dev/pack_retry_153786
------------------------------------------------------------
revno: 3802
revision-id: john at arbash-meinel.com-20081024205359-dqeht8yxzc6b6r89
parent: john at arbash-meinel.com-20081024203126-koei1a77u0qa4abq
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: pack_retry_153786
timestamp: Fri 2008-10-24 15:53:59 -0500
message:
Add a multiple-record test, though it isn't quite what we want for the readv tests.
Mark functions that we want to make retry.
-------------- next part --------------
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py 2008-10-24 20:13:11 +0000
+++ b/bzrlib/knit.py 2008-10-24 20:53:59 +0000
@@ -1113,6 +1113,9 @@
:param allow_missing: If some records are missing, rather than
error, just return the data that could be generated.
"""
+ # TODO: We want to build in retrying, because we only hold the
+ # 'records' for the duration of this function, outside of this
+ # function we deal in 'keys'.
position_map = self._get_components_positions(keys,
allow_missing=allow_missing)
# key = component_id, r = record_details, i_m = index_memo, n = next
@@ -1180,6 +1183,7 @@
def _get_remaining_record_stream(self, keys, ordering,
include_delta_closure):
+ """This function is the 'retry' portion for get_record_stream."""
if include_delta_closure:
positions = self._get_components_positions(keys, allow_missing=True)
else:
@@ -1440,6 +1444,9 @@
:return: An iterator over (line, key).
"""
+ # TODO: We want to build in retrying, because we only hold the
+ # 'records' for the duration of this function, outside of this
+ # function we deal in 'keys'.
if pb is None:
pb = progress.DummyProgress()
keys = set(keys)
@@ -2757,6 +2764,9 @@
if len(self._knit._fallback_vfs) > 0:
# stacked knits can't use the fast path at present.
return self._simple_annotate(key)
+ # TODO: We want to create retry logic at this level, between
+ # _get_build_graph and _annotate_records, since that is the level
+ # that we talk in terms of 'records' and not in terms of keys
records = self._get_build_graph(key)
if key in self._ghosts:
raise errors.RevisionNotPresent(key, self._knit)
=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py 2008-10-24 20:31:26 +0000
+++ b/bzrlib/tests/test_knit.py 2008-10-24 20:53:59 +0000
@@ -450,6 +450,26 @@
gz_file.close()
return sio.getvalue()
+ def make_multiple_records(self):
+ """Create the content for multiple records."""
+ sha1sum = osutils.sha('foo\nbar\n').hexdigest()
+ total_txt = []
+ gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
+ 'foo\n'
+ 'bar\n'
+ 'end rev-id-1\n'
+ % (sha1sum,))
+ record_1 = (0, len(gz_txt), sha1sum)
+ total_txt.append(gz_txt)
+ sha1sum = osutils.sha('baz\n').hexdigest()
+ gz_txt = self.create_gz_content('version rev-id-2 1 %s\n'
+ 'baz\n'
+ 'end rev-id-2\n'
+ % (sha1sum,))
+ record_2 = (record_1[1], len(gz_txt), sha1sum)
+ total_txt.append(gz_txt)
+ return total_txt, record_1, record_2
+
def test_valid_knit_data(self):
sha1sum = osutils.sha('foo\nbar\n').hexdigest()
gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
@@ -469,6 +489,24 @@
raw_contents = list(knit._read_records_iter_raw(records))
self.assertEqual([(('rev-id-1',), gz_txt, sha1sum)], raw_contents)
+ def test_multiple_records_valid(self):
+ total_txt, record_1, record_2 = self.make_multiple_records()
+ transport = MockTransport([''.join(total_txt)])
+ access = _KnitKeyAccess(transport, ConstantMapper('filename'))
+ knit = KnitVersionedFiles(None, access)
+ records = [(('rev-id-1',), (('rev-id-1',), record_1[0], record_1[1])),
+ (('rev-id-2',), (('rev-id-2',), record_2[0], record_2[1]))]
+
+ contents = list(knit._read_records_iter(records))
+ self.assertEqual([(('rev-id-1',), ['foo\n', 'bar\n'], record_1[2]),
+ (('rev-id-2',), ['baz\n'], record_2[2])],
+ contents)
+
+ raw_contents = list(knit._read_records_iter_raw(records))
+ self.assertEqual([(('rev-id-1',), total_txt[0], record_1[2]),
+ (('rev-id-2',), total_txt[1], record_2[2])],
+ raw_contents)
+
def test_not_enough_lines(self):
sha1sum = osutils.sha('foo\n').hexdigest()
# record says 2 lines data says 1
More information about the bazaar-commits
mailing list