~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_btree_index.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-09 19:25:42 UTC
  • mto: (5777.5.1 inventoryworkingtree)
  • mto: This revision was merged to the branch mainline in revision 5781.
  • Revision ID: jelmer@samba.org-20110409192542-8bbedp36s7nj928e
Split InventoryTree out of Tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    TestCaseWithTransport,
34
34
    scenarios,
35
35
    )
36
 
from bzrlib.tests import (
37
 
    features,
38
 
    )
39
36
 
40
37
 
41
38
load_tests = scenarios.load_tests_apply_scenarios
50
47
    return scenarios
51
48
 
52
49
 
53
 
compiled_btreeparser_feature = features.ModuleAvailableFeature(
 
50
compiled_btreeparser_feature = tests.ModuleAvailableFeature(
54
51
    'bzrlib._btree_serializer_pyx')
55
52
 
56
53
 
281
278
 
282
279
        for node in nodes:
283
280
            builder.add_node(*node)
284
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
281
        t = transport.get_transport('trace+' + self.get_url(''))
285
282
        size = t.put_file('index', self.time(builder.finish))
286
283
        del builder
287
284
        index = btree_index.BTreeGraphIndex(t, 'index', size)
608
605
        for key, value, references in nodes:
609
606
            builder.add_node(key, value, references)
610
607
        stream = builder.finish()
611
 
        trans = transport.get_transport_from_url('trace+' + self.get_url())
 
608
        trans = transport.get_transport('trace+' + self.get_url())
612
609
        size = trans.put_file('index', stream)
613
610
        return btree_index.BTreeGraphIndex(trans, 'index', size)
614
611
 
649
646
        self.assertEqual(0, len(index._leaf_node_cache))
650
647
 
651
648
    def test_trivial_constructor(self):
652
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
649
        t = transport.get_transport('trace+' + self.get_url(''))
653
650
        index = btree_index.BTreeGraphIndex(t, 'index', None)
654
651
        # Checks the page size at load, but that isn't logged yet.
655
652
        self.assertEqual([], t._activity)
656
653
 
657
654
    def test_with_size_constructor(self):
658
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
655
        t = transport.get_transport('trace+' + self.get_url(''))
659
656
        index = btree_index.BTreeGraphIndex(t, 'index', 1)
660
657
        # Checks the page size at load, but that isn't logged yet.
661
658
        self.assertEqual([], t._activity)
662
659
 
663
660
    def test_empty_key_count_no_size(self):
664
661
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
665
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
662
        t = transport.get_transport('trace+' + self.get_url(''))
666
663
        t.put_file('index', builder.finish())
667
664
        index = btree_index.BTreeGraphIndex(t, 'index', None)
668
665
        del t._activity[:]
675
672
 
676
673
    def test_empty_key_count(self):
677
674
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
678
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
675
        t = transport.get_transport('trace+' + self.get_url(''))
679
676
        size = t.put_file('index', builder.finish())
680
677
        self.assertEqual(72, size)
681
678
        index = btree_index.BTreeGraphIndex(t, 'index', size)
691
688
        nodes = self.make_nodes(35, 2, 2)
692
689
        for node in nodes:
693
690
            builder.add_node(*node)
694
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
691
        t = transport.get_transport('trace+' + self.get_url(''))
695
692
        size = t.put_file('index', builder.finish())
696
693
        index = btree_index.BTreeGraphIndex(t, 'index', size)
697
694
        del t._activity[:]
723
720
 
724
721
    def test__read_nodes_no_size_one_page_reads_once(self):
725
722
        self.make_index(nodes=[(('key',), 'value', ())])
726
 
        trans = transport.get_transport_from_url('trace+' + self.get_url())
 
723
        trans = transport.get_transport('trace+' + self.get_url())
727
724
        index = btree_index.BTreeGraphIndex(trans, 'index', None)
728
725
        del trans._activity[:]
729
726
        nodes = dict(index._read_nodes([0]))
737
734
        index.key_count()
738
735
        num_pages = index._row_offsets[-1]
739
736
        # Reopen with a traced transport and no size
740
 
        trans = transport.get_transport_from_url('trace+' + self.get_url())
 
737
        trans = transport.get_transport('trace+' + self.get_url())
741
738
        index = btree_index.BTreeGraphIndex(trans, 'index', None)
742
739
        del trans._activity[:]
743
740
        nodes = dict(index._read_nodes([0]))
748
745
        nodes = self.make_nodes(160, 2, 2)
749
746
        for node in nodes:
750
747
            builder.add_node(*node)
751
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
748
        t = transport.get_transport('trace+' + self.get_url(''))
752
749
        size = t.put_file('index', builder.finish())
753
750
        self.assertEqual(17692, size)
754
751
        index = btree_index.BTreeGraphIndex(t, 'index', size)
764
761
        nodes = self.make_nodes(45, 2, 2)
765
762
        for node in nodes:
766
763
            builder.add_node(*node)
767
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
764
        t = transport.get_transport('trace+' + self.get_url(''))
768
765
        size = t.put_file('index', builder.finish())
769
766
        index = btree_index.BTreeGraphIndex(t, 'index', size)
770
767
        del t._activity[:]
780
777
        nodes = self.make_nodes(80, 2, 2)
781
778
        for node in nodes:
782
779
            builder.add_node(*node)
783
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
780
        t = transport.get_transport('trace+' + self.get_url(''))
784
781
        size = t.put_file('index', builder.finish())
785
782
        # Root page, 2 leaf pages
786
783
        self.assertEqual(9339, size)
798
795
 
799
796
    def test_eq_ne(self):
800
797
        # two indices are equal when constructed with the same parameters:
801
 
        t1 = transport.get_transport_from_url('trace+' + self.get_url(''))
 
798
        t1 = transport.get_transport('trace+' + self.get_url(''))
802
799
        t2 = self.get_transport()
803
800
        self.assertTrue(
804
801
            btree_index.BTreeGraphIndex(t1, 'index', None) ==
833
830
 
834
831
    def test_iter_all_only_root_no_size(self):
835
832
        self.make_index(nodes=[(('key',), 'value', ())])
836
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
833
        t = transport.get_transport('trace+' + self.get_url(''))
837
834
        index = btree_index.BTreeGraphIndex(t, 'index', None)
838
835
        del t._activity[:]
839
836
        self.assertEqual([(('key',), 'value')],
850
847
        nodes = self.make_nodes(10000, 2, 2)
851
848
        for node in nodes:
852
849
            builder.add_node(*node)
853
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
850
        t = transport.get_transport('trace+' + self.get_url(''))
854
851
        size = t.put_file('index', builder.finish())
855
852
        self.assertEqual(1303220, size, 'number of expected bytes in the'
856
853
                                        ' output changed')
905
902
        nodes = self.make_nodes(160, 2, 2)
906
903
        for node in nodes:
907
904
            builder.add_node(*node)
908
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
 
905
        t = transport.get_transport('trace+' + self.get_url(''))
909
906
        size = t.put_file('index', builder.finish())
910
907
        del builder
911
908
        index = btree_index.BTreeGraphIndex(t, 'index', size)
1354
1351
        BTreeGraphIndex with the recommended information.
1355
1352
        """
1356
1353
        index = btree_index.BTreeGraphIndex(
1357
 
            transport.get_transport_from_url('memory:///'),
1358
 
            'test-index', size=size)
 
1354
            transport.get_transport('memory:///'), 'test-index', size=size)
1359
1355
        if recommended_pages is not None:
1360
1356
            index._recommended_pages = recommended_pages
1361
1357
        return index