702
702
" 0 8', \(\(\('a',\),\),\)\)")
705
class StubGCVF(object):
707
self._group_cache = {}
708
def _get_blocks(read_memos):
712
class Test_BatchingBlockFetcher(TestCaseWithGroupCompressVersionedFiles):
713
"""Simple whitebox unit tests for _BatchingBlockFetcher."""
715
def test_add_key_new_read_memo(self):
716
"""Adding a key with an uncached read_memo new to this batch adds that
717
read_memo to the list of memos to fetch.
719
# locations are: index_memo, ignored, parents, ignored
720
# where index_memo is: (idx, offset, len, factory_start, factory_end)
721
# and (idx, offset, size) is known as the 'read_memo', identifying the
723
read_memo = ('fake index', 100, 50)
725
('key',): (read_memo + (None, None), None, None, None)}
726
batcher = groupcompress._BatchingBlockFetcher(StubGCVF(), locations)
727
total_size = batcher.add_key(('key',))
728
self.assertEqual(50, total_size)
729
self.assertEqual([('key',)], batcher.keys)
730
self.assertEqual([read_memo], batcher.memos_to_get)
732
def test_add_key_duplicate_read_memo(self):
733
"""read_memos that occur multiple times in a batch will only be fetched
736
read_memo = ('fake index', 100, 50)
737
# Two keys, both sharing the same read memo (but different overall
740
('key1',): (read_memo + (0, 1), None, None, None),
741
('key2',): (read_memo + (1, 2), None, None, None)}
742
batcher = groupcompress._BatchingBlockFetcher(StubGCVF(), locations)
743
total_size = batcher.add_key(('key1',))
744
total_size = batcher.add_key(('key2',))
745
self.assertEqual(50, total_size)
746
self.assertEqual([('key1',), ('key2',)], batcher.keys)
747
self.assertEqual([read_memo], batcher.memos_to_get)
749
def test_add_key_cached_read_memo(self):
750
"""Adding a key with a cached read_memo will not cause that read_memo
751
to be added to the list to fetch.
753
read_memo = ('fake index', 100, 50)
755
gcvf._group_cache[read_memo] = 'fake block'
757
('key',): (read_memo + (None, None), None, None, None)}
758
batcher = groupcompress._BatchingBlockFetcher(gcvf, locations)
759
total_size = batcher.add_key(('key',))
760
self.assertEqual(0, total_size)
761
self.assertEqual([('key',)], batcher.keys)
762
self.assertEqual([], batcher.memos_to_get)
705
765
class TestLazyGroupCompress(tests.TestCaseWithTransport):