~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_index.py

  • Committer: Robert Collins
  • Date: 2007-10-07 22:52:05 UTC
  • mto: (2592.3.168 repository)
  • mto: This revision was merged to the branch mainline in revision 2908.
  • Revision ID: robertc@robertcollins.net-20071007225205-4ttygs5100xl33ac
Add support for key references to the index lookup_keys_via_location bisection interface.

Show diffs side-by-side

added added

removed removed

Lines of Context:
546
546
        self.assertEqual([((index._size // 2, ('50', )), +1)],
547
547
            result)
548
548
 
 
549
    def test_lookup_key_resolves_references(self):
 
550
        # generate a big enough index that we only read some of it on a typical
 
551
        # bisection lookup.
 
552
        nodes = []
 
553
        def make_key(number):
 
554
            return (str(number) + 'X'*100,)
 
555
        def make_value(number):
 
556
            return str(number) + 'Y'*100
 
557
        for counter in range(64):
 
558
            nodes.append((make_key(counter), make_value(counter),
 
559
                ((make_key(counter + 20),),)  ))
 
560
        index = self.make_index(ref_lists=1, nodes=nodes)
 
561
        # lookup a key in the middle that does not exist, so that when we can
 
562
        # check that the referred-to-keys are not accessed automatically.
 
563
        result =index.lookup_keys_via_location(
 
564
            [(index._size // 2, ('40', ))])
 
565
        # check the parse map - only the start and middle should have been
 
566
        # parsed.
 
567
        self.assertEqual([(0, 3890), (6444, 10274)], index._parsed_byte_map)
 
568
        self.assertEqual([(None, make_key(25)), (make_key(37), make_key(52))],
 
569
            index._parsed_key_map)
 
570
        # and check the transport activity likewise.
 
571
        self.assertEqual(
 
572
            [('readv', 'index', [(7906, 800), (0, 200)], True, 15813)],
 
573
            index._transport._activity)
 
574
        # reset the transport log for testing the reference lookup
 
575
        del index._transport._activity[:]
 
576
        # now looking up a key in the portion of the file already parsed should
 
577
        # only perform IO to resolve its key references.
 
578
        result = index.lookup_keys_via_location([(4000, make_key(40))])
 
579
        self.assertEqual(
 
580
            [((4000, make_key(40)),
 
581
              (index, make_key(40), make_value(40), ((make_key(60),),)))],
 
582
            result)
 
583
        self.assertEqual([('readv', 'index', [(11976, 800)], True, 15813)],
 
584
            index._transport._activity)
 
585
 
 
586
 
549
587
    def test_iter_all_entries_empty(self):
550
588
        index = self.make_index()
551
589
        self.assertEqual([], list(index.iter_all_entries()))