~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_btree_index.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-11-12 05:49:02 UTC
  • mfrom: (3824.1.2 btree_no_size)
  • Revision ID: pqm@pqm.ubuntu.com-20081112054902-n6p0qrvl4cb26ij8
(jam) reading pack-names only issues a single read request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
579
579
        # The entire index should have been requested (as we generally have the
580
580
        # size available, and doing many small readvs is inappropriate).
581
581
        # We can't tell how much was actually read here, but - check the code.
582
 
        self.assertEqual([('get', 'index'),
583
 
            ('readv', 'index', [(0, 72)], False, None)],
584
 
            transport._activity)
 
582
        self.assertEqual([('get', 'index')], transport._activity)
585
583
 
586
584
    def test_empty_key_count(self):
587
585
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
612
610
            transport._activity)
613
611
        self.assertEqual(1199, size)
614
612
 
 
613
    def test__read_nodes_no_size_one_page_reads_once(self):
 
614
        self.make_index(nodes=[(('key',), 'value', ())])
 
615
        trans = get_transport('trace+' + self.get_url())
 
616
        index = btree_index.BTreeGraphIndex(trans, 'index', None)
 
617
        del trans._activity[:]
 
618
        nodes = dict(index._read_nodes([0]))
 
619
        self.assertEqual([0], nodes.keys())
 
620
        node = nodes[0]
 
621
        self.assertEqual([('key',)], node.keys.keys())
 
622
        self.assertEqual([('get', 'index')], trans._activity)
 
623
 
 
624
    def test__read_nodes_no_size_multiple_pages(self):
 
625
        index = self.make_index(2, 2, nodes=self.make_nodes(160, 2, 2))
 
626
        index.key_count()
 
627
        num_pages = index._row_offsets[-1]
 
628
        # Reopen with a traced transport and no size
 
629
        trans = get_transport('trace+' + self.get_url())
 
630
        index = btree_index.BTreeGraphIndex(trans, 'index', None)
 
631
        del trans._activity[:]
 
632
        nodes = dict(index._read_nodes([0]))
 
633
        self.assertEqual(range(num_pages), nodes.keys())
 
634
 
615
635
    def test_2_levels_key_count_2_2(self):
616
636
        builder = btree_index.BTreeBuilder(key_elements=2, reference_lists=2)
617
637
        nodes = self.make_nodes(160, 2, 2)
699
719
            btree_index.BTreeGraphIndex(transport1, 'index', 10) !=
700
720
            btree_index.BTreeGraphIndex(transport1, 'index', 20))
701
721
 
 
722
    def test_iter_all_only_root_no_size(self):
 
723
        self.make_index(nodes=[(('key',), 'value', ())])
 
724
        trans = get_transport('trace+' + self.get_url(''))
 
725
        index = btree_index.BTreeGraphIndex(trans, 'index', None)
 
726
        del trans._activity[:]
 
727
        self.assertEqual([(('key',), 'value')],
 
728
                         [x[1:] for x in index.iter_all_entries()])
 
729
        self.assertEqual([('get', 'index')], trans._activity)
 
730
 
702
731
    def test_iter_all_entries_reads(self):
703
732
        # iterating all entries reads the header, then does a linear
704
733
        # read.