~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_groupcompress.py

  • Committer: Andrew Bennetts
  • Date: 2009-08-27 04:02:32 UTC
  • mto: This revision was merged to the branch mainline in revision 4661.
  • Revision ID: andrew.bennetts@canonical.com-20090827040232-cde7qr3w96w9ekj8
Some basic whitebox unit tests for _BatchingBlockFetcher.

Show diffs side-by-side

added added

removed removed

Lines of Context:
702
702
                              " 0 8', \(\(\('a',\),\),\)\)")
703
703
 
704
704
 
 
705
class StubGCVF(object):
 
706
    def __init__(self):
 
707
        self._group_cache = {}
 
708
    def _get_blocks(read_memos):
 
709
        return []
 
710
    
 
711
 
 
712
class Test_BatchingBlockFetcher(TestCaseWithGroupCompressVersionedFiles):
 
713
    """Simple whitebox unit tests for _BatchingBlockFetcher."""
 
714
    
 
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.
 
718
        """
 
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
 
722
        # raw bytes needed.
 
723
        read_memo = ('fake index', 100, 50)
 
724
        locations = {
 
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)
 
731
 
 
732
    def test_add_key_duplicate_read_memo(self):
 
733
        """read_memos that occur multiple times in a batch will only be fetched
 
734
        once.
 
735
        """
 
736
        read_memo = ('fake index', 100, 50)
 
737
        # Two keys, both sharing the same read memo (but different overall
 
738
        # index_memos).
 
739
        locations = {
 
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)
 
748
 
 
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.
 
752
        """
 
753
        read_memo = ('fake index', 100, 50)
 
754
        gcvf = StubGCVF()
 
755
        gcvf._group_cache[read_memo] = 'fake block'
 
756
        locations = {
 
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)
 
763
 
 
764
 
705
765
class TestLazyGroupCompress(tests.TestCaseWithTransport):
706
766
 
707
767
    _texts = {