~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: 2010-05-11 11:47:36 UTC
  • mfrom: (5200.3.8 lock_return)
  • Revision ID: pqm@pqm.ubuntu.com-20100511114736-mc1sq9zyo3vufec7
(lifeless) Provide a consistent interface to Tree, Branch,
 Repository where lock methods return an object with an unlock method to
 unlock the lock. This breaks the API for Branch,
 Repository on their lock_write methods. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
    lru_cache,
28
28
    osutils,
29
29
    tests,
30
 
    transport,
31
30
    )
32
31
from bzrlib.tests import (
33
32
    TestCaseWithTransport,
34
 
    scenarios,
35
 
    )
36
 
from bzrlib.tests import (
37
 
    features,
38
 
    )
39
 
 
40
 
 
41
 
load_tests = scenarios.load_tests_apply_scenarios
42
 
 
43
 
 
44
 
def btreeparser_scenarios():
 
33
    condition_isinstance,
 
34
    multiply_tests,
 
35
    split_suite_by_condition,
 
36
    )
 
37
from bzrlib.transport import get_transport
 
38
 
 
39
 
 
40
def load_tests(standard_tests, module, loader):
 
41
    # parameterise the TestBTreeNodes tests
 
42
    node_tests, others = split_suite_by_condition(standard_tests,
 
43
        condition_isinstance(TestBTreeNodes))
45
44
    import bzrlib._btree_serializer_py as py_module
46
45
    scenarios = [('python', {'parse_btree': py_module})]
47
46
    if compiled_btreeparser_feature.available():
48
 
        scenarios.append(('C', 
49
 
            {'parse_btree': compiled_btreeparser_feature.module}))
50
 
    return scenarios
51
 
 
52
 
 
53
 
compiled_btreeparser_feature = features.ModuleAvailableFeature(
54
 
    'bzrlib._btree_serializer_pyx')
 
47
        scenarios.append(('C', {'parse_btree':
 
48
                                compiled_btreeparser_feature.module}))
 
49
    return multiply_tests(node_tests, scenarios, others)
 
50
 
 
51
 
 
52
compiled_btreeparser_feature = tests.ModuleAvailableFeature(
 
53
                                'bzrlib._btree_serializer_pyx')
55
54
 
56
55
 
57
56
class BTreeTestCase(TestCaseWithTransport):
217
216
        leaf1_bytes = zlib.decompress(leaf1)
218
217
        sorted_node_keys = sorted(node[0] for node in nodes)
219
218
        node = btree_index._LeafNode(leaf1_bytes, 1, 0)
220
 
        self.assertEqual(231, len(node))
221
 
        self.assertEqual(sorted_node_keys[:231], node.all_keys())
 
219
        self.assertEqual(231, len(node.keys))
 
220
        self.assertEqual(sorted_node_keys[:231], sorted(node.keys))
222
221
        leaf2_bytes = zlib.decompress(leaf2)
223
222
        node = btree_index._LeafNode(leaf2_bytes, 1, 0)
224
 
        self.assertEqual(400 - 231, len(node))
225
 
        self.assertEqual(sorted_node_keys[231:], node.all_keys())
 
223
        self.assertEqual(400 - 231, len(node.keys))
 
224
        self.assertEqual(sorted_node_keys[231:], sorted(node.keys))
226
225
 
227
226
    def test_last_page_rounded_1_layer(self):
228
227
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
242
241
        leaf2 = content[74:]
243
242
        leaf2_bytes = zlib.decompress(leaf2)
244
243
        node = btree_index._LeafNode(leaf2_bytes, 1, 0)
245
 
        self.assertEqual(10, len(node))
 
244
        self.assertEqual(10, len(node.keys))
246
245
        sorted_node_keys = sorted(node[0] for node in nodes)
247
 
        self.assertEqual(sorted_node_keys, node.all_keys())
 
246
        self.assertEqual(sorted_node_keys, sorted(node.keys))
248
247
 
249
248
    def test_last_page_not_rounded_2_layer(self):
250
249
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
264
263
        leaf2 = content[8192:]
265
264
        leaf2_bytes = zlib.decompress(leaf2)
266
265
        node = btree_index._LeafNode(leaf2_bytes, 1, 0)
267
 
        self.assertEqual(400 - 231, len(node))
 
266
        self.assertEqual(400 - 231, len(node.keys))
268
267
        sorted_node_keys = sorted(node[0] for node in nodes)
269
 
        self.assertEqual(sorted_node_keys[231:], node.all_keys())
 
268
        self.assertEqual(sorted_node_keys[231:], sorted(node.keys))
270
269
 
271
270
    def test_three_level_tree_details(self):
272
271
        # The left most pointer in the second internal node in a row should
281
280
 
282
281
        for node in nodes:
283
282
            builder.add_node(*node)
284
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
285
 
        size = t.put_file('index', self.time(builder.finish))
 
283
        transport = get_transport('trace+' + self.get_url(''))
 
284
        size = transport.put_file('index', self.time(builder.finish))
286
285
        del builder
287
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
 
286
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
288
287
        # Seed the metadata, we're using internal calls now.
289
288
        index.key_count()
290
289
        self.assertEqual(3, len(index._row_lengths),
303
302
        # in the second node it points at
304
303
        pos = index._row_offsets[2] + internal_node2.offset + 1
305
304
        leaf = index._get_leaf_nodes([pos])[pos]
306
 
        self.assertTrue(internal_node2.keys[0] in leaf)
 
305
        self.assertTrue(internal_node2.keys[0] in leaf.keys)
307
306
 
308
307
    def test_2_leaves_2_2(self):
309
308
        builder = btree_index.BTreeBuilder(key_elements=2, reference_lists=2)
410
409
        self.assertEqual(None, builder._backing_indices[2])
411
410
        self.assertEqual(16, builder._backing_indices[3].key_count())
412
411
        # Now finish, and check we got a correctly ordered tree
413
 
        t = self.get_transport('')
414
 
        size = t.put_file('index', builder.finish())
415
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
 
412
        transport = self.get_transport('')
 
413
        size = transport.put_file('index', builder.finish())
 
414
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
416
415
        nodes = list(index.iter_all_entries())
417
416
        self.assertEqual(sorted(nodes), nodes)
418
417
        self.assertEqual(16, len(nodes))
608
607
        for key, value, references in nodes:
609
608
            builder.add_node(key, value, references)
610
609
        stream = builder.finish()
611
 
        trans = transport.get_transport_from_url('trace+' + self.get_url())
 
610
        trans = get_transport('trace+' + self.get_url())
612
611
        size = trans.put_file('index', stream)
613
612
        return btree_index.BTreeGraphIndex(trans, 'index', size)
614
613
 
649
648
        self.assertEqual(0, len(index._leaf_node_cache))
650
649
 
651
650
    def test_trivial_constructor(self):
652
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
653
 
        index = btree_index.BTreeGraphIndex(t, 'index', None)
 
651
        transport = get_transport('trace+' + self.get_url(''))
 
652
        index = btree_index.BTreeGraphIndex(transport, 'index', None)
654
653
        # Checks the page size at load, but that isn't logged yet.
655
 
        self.assertEqual([], t._activity)
 
654
        self.assertEqual([], transport._activity)
656
655
 
657
656
    def test_with_size_constructor(self):
658
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
659
 
        index = btree_index.BTreeGraphIndex(t, 'index', 1)
 
657
        transport = get_transport('trace+' + self.get_url(''))
 
658
        index = btree_index.BTreeGraphIndex(transport, 'index', 1)
660
659
        # Checks the page size at load, but that isn't logged yet.
661
 
        self.assertEqual([], t._activity)
 
660
        self.assertEqual([], transport._activity)
662
661
 
663
662
    def test_empty_key_count_no_size(self):
664
663
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
665
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
666
 
        t.put_file('index', builder.finish())
667
 
        index = btree_index.BTreeGraphIndex(t, 'index', None)
668
 
        del t._activity[:]
669
 
        self.assertEqual([], t._activity)
 
664
        transport = get_transport('trace+' + self.get_url(''))
 
665
        transport.put_file('index', builder.finish())
 
666
        index = btree_index.BTreeGraphIndex(transport, 'index', None)
 
667
        del transport._activity[:]
 
668
        self.assertEqual([], transport._activity)
670
669
        self.assertEqual(0, index.key_count())
671
670
        # The entire index should have been requested (as we generally have the
672
671
        # size available, and doing many small readvs is inappropriate).
673
672
        # We can't tell how much was actually read here, but - check the code.
674
 
        self.assertEqual([('get', 'index')], t._activity)
 
673
        self.assertEqual([('get', 'index')], transport._activity)
675
674
 
676
675
    def test_empty_key_count(self):
677
676
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
678
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
679
 
        size = t.put_file('index', builder.finish())
 
677
        transport = get_transport('trace+' + self.get_url(''))
 
678
        size = transport.put_file('index', builder.finish())
680
679
        self.assertEqual(72, size)
681
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
682
 
        del t._activity[:]
683
 
        self.assertEqual([], t._activity)
 
680
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
 
681
        del transport._activity[:]
 
682
        self.assertEqual([], transport._activity)
684
683
        self.assertEqual(0, index.key_count())
685
684
        # The entire index should have been read, as 4K > size
686
685
        self.assertEqual([('readv', 'index', [(0, 72)], False, None)],
687
 
                         t._activity)
 
686
            transport._activity)
688
687
 
689
688
    def test_non_empty_key_count_2_2(self):
690
689
        builder = btree_index.BTreeBuilder(key_elements=2, reference_lists=2)
691
690
        nodes = self.make_nodes(35, 2, 2)
692
691
        for node in nodes:
693
692
            builder.add_node(*node)
694
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
695
 
        size = t.put_file('index', builder.finish())
696
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
697
 
        del t._activity[:]
698
 
        self.assertEqual([], t._activity)
 
693
        transport = get_transport('trace+' + self.get_url(''))
 
694
        size = transport.put_file('index', builder.finish())
 
695
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
 
696
        del transport._activity[:]
 
697
        self.assertEqual([], transport._activity)
699
698
        self.assertEqual(70, index.key_count())
700
699
        # The entire index should have been read, as it is one page long.
701
700
        self.assertEqual([('readv', 'index', [(0, size)], False, None)],
702
 
            t._activity)
 
701
            transport._activity)
703
702
        self.assertEqual(1173, size)
704
703
 
705
704
    def test_with_offset_no_size(self):
723
722
 
724
723
    def test__read_nodes_no_size_one_page_reads_once(self):
725
724
        self.make_index(nodes=[(('key',), 'value', ())])
726
 
        trans = transport.get_transport_from_url('trace+' + self.get_url())
 
725
        trans = get_transport('trace+' + self.get_url())
727
726
        index = btree_index.BTreeGraphIndex(trans, 'index', None)
728
727
        del trans._activity[:]
729
728
        nodes = dict(index._read_nodes([0]))
730
729
        self.assertEqual([0], nodes.keys())
731
730
        node = nodes[0]
732
 
        self.assertEqual([('key',)], node.all_keys())
 
731
        self.assertEqual([('key',)], node.keys.keys())
733
732
        self.assertEqual([('get', 'index')], trans._activity)
734
733
 
735
734
    def test__read_nodes_no_size_multiple_pages(self):
737
736
        index.key_count()
738
737
        num_pages = index._row_offsets[-1]
739
738
        # Reopen with a traced transport and no size
740
 
        trans = transport.get_transport_from_url('trace+' + self.get_url())
 
739
        trans = get_transport('trace+' + self.get_url())
741
740
        index = btree_index.BTreeGraphIndex(trans, 'index', None)
742
741
        del trans._activity[:]
743
742
        nodes = dict(index._read_nodes([0]))
748
747
        nodes = self.make_nodes(160, 2, 2)
749
748
        for node in nodes:
750
749
            builder.add_node(*node)
751
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
752
 
        size = t.put_file('index', builder.finish())
 
750
        transport = get_transport('trace+' + self.get_url(''))
 
751
        size = transport.put_file('index', builder.finish())
753
752
        self.assertEqual(17692, size)
754
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
755
 
        del t._activity[:]
756
 
        self.assertEqual([], t._activity)
 
753
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
 
754
        del transport._activity[:]
 
755
        self.assertEqual([], transport._activity)
757
756
        self.assertEqual(320, index.key_count())
758
757
        # The entire index should not have been read.
759
758
        self.assertEqual([('readv', 'index', [(0, 4096)], False, None)],
760
 
                         t._activity)
 
759
            transport._activity)
761
760
 
762
761
    def test_validate_one_page(self):
763
762
        builder = btree_index.BTreeBuilder(key_elements=2, reference_lists=2)
764
763
        nodes = self.make_nodes(45, 2, 2)
765
764
        for node in nodes:
766
765
            builder.add_node(*node)
767
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
768
 
        size = t.put_file('index', builder.finish())
769
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
770
 
        del t._activity[:]
771
 
        self.assertEqual([], t._activity)
 
766
        transport = get_transport('trace+' + self.get_url(''))
 
767
        size = transport.put_file('index', builder.finish())
 
768
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
 
769
        del transport._activity[:]
 
770
        self.assertEqual([], transport._activity)
772
771
        index.validate()
773
772
        # The entire index should have been read linearly.
774
773
        self.assertEqual([('readv', 'index', [(0, size)], False, None)],
775
 
                         t._activity)
 
774
            transport._activity)
776
775
        self.assertEqual(1488, size)
777
776
 
778
777
    def test_validate_two_pages(self):
780
779
        nodes = self.make_nodes(80, 2, 2)
781
780
        for node in nodes:
782
781
            builder.add_node(*node)
783
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
784
 
        size = t.put_file('index', builder.finish())
 
782
        transport = get_transport('trace+' + self.get_url(''))
 
783
        size = transport.put_file('index', builder.finish())
785
784
        # Root page, 2 leaf pages
786
785
        self.assertEqual(9339, size)
787
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
788
 
        del t._activity[:]
789
 
        self.assertEqual([], t._activity)
 
786
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
 
787
        del transport._activity[:]
 
788
        self.assertEqual([], transport._activity)
790
789
        index.validate()
791
790
        # The entire index should have been read linearly.
792
 
        self.assertEqual(
793
 
            [('readv', 'index', [(0, 4096)], False, None),
794
 
             ('readv', 'index', [(4096, 4096), (8192, 1147)], False, None)],
795
 
            t._activity)
 
791
        self.assertEqual([('readv', 'index', [(0, 4096)], False, None),
 
792
            ('readv', 'index', [(4096, 4096), (8192, 1147)], False, None)],
 
793
            transport._activity)
796
794
        # XXX: TODO: write some badly-ordered nodes, and some pointers-to-wrong
797
795
        # node and make validate find them.
798
796
 
799
797
    def test_eq_ne(self):
800
798
        # two indices are equal when constructed with the same parameters:
801
 
        t1 = transport.get_transport_from_url('trace+' + self.get_url(''))
802
 
        t2 = self.get_transport()
803
 
        self.assertTrue(
804
 
            btree_index.BTreeGraphIndex(t1, 'index', None) ==
805
 
            btree_index.BTreeGraphIndex(t1, 'index', None))
806
 
        self.assertTrue(
807
 
            btree_index.BTreeGraphIndex(t1, 'index', 20) ==
808
 
            btree_index.BTreeGraphIndex(t1, 'index', 20))
809
 
        self.assertFalse(
810
 
            btree_index.BTreeGraphIndex(t1, 'index', 20) ==
811
 
            btree_index.BTreeGraphIndex(t2, 'index', 20))
812
 
        self.assertFalse(
813
 
            btree_index.BTreeGraphIndex(t1, 'inde1', 20) ==
814
 
            btree_index.BTreeGraphIndex(t1, 'inde2', 20))
815
 
        self.assertFalse(
816
 
            btree_index.BTreeGraphIndex(t1, 'index', 10) ==
817
 
            btree_index.BTreeGraphIndex(t1, 'index', 20))
818
 
        self.assertFalse(
819
 
            btree_index.BTreeGraphIndex(t1, 'index', None) !=
820
 
            btree_index.BTreeGraphIndex(t1, 'index', None))
821
 
        self.assertFalse(
822
 
            btree_index.BTreeGraphIndex(t1, 'index', 20) !=
823
 
            btree_index.BTreeGraphIndex(t1, 'index', 20))
824
 
        self.assertTrue(
825
 
            btree_index.BTreeGraphIndex(t1, 'index', 20) !=
826
 
            btree_index.BTreeGraphIndex(t2, 'index', 20))
827
 
        self.assertTrue(
828
 
            btree_index.BTreeGraphIndex(t1, 'inde1', 20) !=
829
 
            btree_index.BTreeGraphIndex(t1, 'inde2', 20))
830
 
        self.assertTrue(
831
 
            btree_index.BTreeGraphIndex(t1, 'index', 10) !=
832
 
            btree_index.BTreeGraphIndex(t1, 'index', 20))
 
799
        transport1 = get_transport('trace+' + self.get_url(''))
 
800
        transport2 = get_transport(self.get_url(''))
 
801
        self.assertTrue(
 
802
            btree_index.BTreeGraphIndex(transport1, 'index', None) ==
 
803
            btree_index.BTreeGraphIndex(transport1, 'index', None))
 
804
        self.assertTrue(
 
805
            btree_index.BTreeGraphIndex(transport1, 'index', 20) ==
 
806
            btree_index.BTreeGraphIndex(transport1, 'index', 20))
 
807
        self.assertFalse(
 
808
            btree_index.BTreeGraphIndex(transport1, 'index', 20) ==
 
809
            btree_index.BTreeGraphIndex(transport2, 'index', 20))
 
810
        self.assertFalse(
 
811
            btree_index.BTreeGraphIndex(transport1, 'inde1', 20) ==
 
812
            btree_index.BTreeGraphIndex(transport1, 'inde2', 20))
 
813
        self.assertFalse(
 
814
            btree_index.BTreeGraphIndex(transport1, 'index', 10) ==
 
815
            btree_index.BTreeGraphIndex(transport1, 'index', 20))
 
816
        self.assertFalse(
 
817
            btree_index.BTreeGraphIndex(transport1, 'index', None) !=
 
818
            btree_index.BTreeGraphIndex(transport1, 'index', None))
 
819
        self.assertFalse(
 
820
            btree_index.BTreeGraphIndex(transport1, 'index', 20) !=
 
821
            btree_index.BTreeGraphIndex(transport1, 'index', 20))
 
822
        self.assertTrue(
 
823
            btree_index.BTreeGraphIndex(transport1, 'index', 20) !=
 
824
            btree_index.BTreeGraphIndex(transport2, 'index', 20))
 
825
        self.assertTrue(
 
826
            btree_index.BTreeGraphIndex(transport1, 'inde1', 20) !=
 
827
            btree_index.BTreeGraphIndex(transport1, 'inde2', 20))
 
828
        self.assertTrue(
 
829
            btree_index.BTreeGraphIndex(transport1, 'index', 10) !=
 
830
            btree_index.BTreeGraphIndex(transport1, 'index', 20))
833
831
 
834
832
    def test_iter_all_only_root_no_size(self):
835
833
        self.make_index(nodes=[(('key',), 'value', ())])
836
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
837
 
        index = btree_index.BTreeGraphIndex(t, 'index', None)
838
 
        del t._activity[:]
 
834
        trans = get_transport('trace+' + self.get_url(''))
 
835
        index = btree_index.BTreeGraphIndex(trans, 'index', None)
 
836
        del trans._activity[:]
839
837
        self.assertEqual([(('key',), 'value')],
840
838
                         [x[1:] for x in index.iter_all_entries()])
841
 
        self.assertEqual([('get', 'index')], t._activity)
 
839
        self.assertEqual([('get', 'index')], trans._activity)
842
840
 
843
841
    def test_iter_all_entries_reads(self):
844
842
        # iterating all entries reads the header, then does a linear
850
848
        nodes = self.make_nodes(10000, 2, 2)
851
849
        for node in nodes:
852
850
            builder.add_node(*node)
853
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
854
 
        size = t.put_file('index', builder.finish())
 
851
        transport = get_transport('trace+' + self.get_url(''))
 
852
        size = transport.put_file('index', builder.finish())
855
853
        self.assertEqual(1303220, size, 'number of expected bytes in the'
856
854
                                        ' output changed')
857
855
        page_size = btree_index._PAGE_SIZE
858
856
        del builder
859
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
860
 
        del t._activity[:]
861
 
        self.assertEqual([], t._activity)
 
857
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
 
858
        del transport._activity[:]
 
859
        self.assertEqual([], transport._activity)
862
860
        found_nodes = self.time(list, index.iter_all_entries())
863
861
        bare_nodes = []
864
862
        for node in found_nodes:
885
883
        readv_request[-1] = (readv_request[-1][0], 1303220 % page_size)
886
884
        expected = [('readv', 'index', [(0, page_size)], False, None),
887
885
             ('readv',  'index', readv_request, False, None)]
888
 
        if expected != t._activity:
 
886
        if expected != transport._activity:
889
887
            self.assertEqualDiff(pprint.pformat(expected),
890
888
                                 pprint.pformat(transport._activity))
891
889
 
905
903
        nodes = self.make_nodes(160, 2, 2)
906
904
        for node in nodes:
907
905
            builder.add_node(*node)
908
 
        t = transport.get_transport_from_url('trace+' + self.get_url(''))
909
 
        size = t.put_file('index', builder.finish())
 
906
        transport = get_transport('trace+' + self.get_url(''))
 
907
        size = transport.put_file('index', builder.finish())
910
908
        del builder
911
 
        index = btree_index.BTreeGraphIndex(t, 'index', size)
912
 
        del t._activity[:]
913
 
        self.assertEqual([], t._activity)
 
909
        index = btree_index.BTreeGraphIndex(transport, 'index', size)
 
910
        del transport._activity[:]
 
911
        self.assertEqual([], transport._activity)
914
912
        # search for one key
915
913
        found_nodes = list(index.iter_entries([nodes[30][0]]))
916
914
        bare_nodes = []
924
922
        # Should have read the root node, then one leaf page:
925
923
        self.assertEqual([('readv', 'index', [(0, 4096)], False, None),
926
924
             ('readv',  'index', [(8192, 4096), ], False, None)],
927
 
            t._activity)
 
925
            transport._activity)
928
926
 
929
927
    def test_iter_key_prefix_1_element_key_None(self):
930
928
        index = self.make_index()
1113
1111
        min_l2_key = l2.min_key
1114
1112
        max_l1_key = l1.max_key
1115
1113
        self.assertTrue(max_l1_key < min_l2_key)
1116
 
        parents_min_l2_key = l2[min_l2_key][1][0]
 
1114
        parents_min_l2_key = l2.keys[min_l2_key][1][0]
1117
1115
        self.assertEqual((l1.max_key,), parents_min_l2_key)
1118
1116
        # Now, whatever key we select that would fall on the second page,
1119
1117
        # should give us all the parents until the page break
1132
1130
        parent_map = {}
1133
1131
        search_keys = index._find_ancestors([max_l1_key], 0, parent_map,
1134
1132
                                            missing_keys)
1135
 
        self.assertEqual(l1.all_keys(), sorted(parent_map))
 
1133
        self.assertEqual(sorted(l1.keys), sorted(parent_map))
1136
1134
        self.assertEqual(set(), missing_keys)
1137
1135
        self.assertEqual(set(), search_keys)
1138
1136
 
1154
1152
        for node in nodes:
1155
1153
            builder.add_node(*node)
1156
1154
        stream = builder.finish()
1157
 
        trans = self.get_transport()
 
1155
        trans = get_transport(self.get_url())
1158
1156
        size = trans.put_file('index', stream)
1159
1157
        index = btree_index.BTreeGraphIndex(trans, 'index', size)
1160
1158
        self.assertEqual(500, index.key_count())
1186
1184
 
1187
1185
class TestBTreeNodes(BTreeTestCase):
1188
1186
 
1189
 
    scenarios = btreeparser_scenarios()
1190
 
 
1191
1187
    def setUp(self):
1192
1188
        BTreeTestCase.setUp(self)
1193
1189
        self.overrideAttr(btree_index, '_btree_serializer', self.parse_btree)
1208
1204
            ("2222222222222222222222222222222222222222",): ("value:2", ()),
1209
1205
            ("3333333333333333333333333333333333333333",): ("value:3", ()),
1210
1206
            ("4444444444444444444444444444444444444444",): ("value:4", ()),
1211
 
            }, dict(node.all_items()))
 
1207
            }, node.keys)
1212
1208
 
1213
1209
    def test_LeafNode_2_2(self):
1214
1210
        node_bytes = ("type=leaf\n"
1228
1224
            ('11', '33'): ('value:3',
1229
1225
                ((('11', 'ref22'),), (('11', 'ref22'), ('11', 'ref22')))),
1230
1226
            ('11', '44'): ('value:4', ((), (('11', 'ref00'),)))
1231
 
            }, dict(node.all_items()))
 
1227
            }, node.keys)
1232
1228
 
1233
1229
    def test_InternalNode_1(self):
1234
1230
        node_bytes = ("type=internal\n"
1269
1265
            ('11', '33'): ('value:3',
1270
1266
                ((('11', 'ref22'),), (('11', 'ref22'), ('11', 'ref22')))),
1271
1267
            ('11', '44'): ('value:4', ((), (('11', 'ref00'),)))
1272
 
            }, dict(node.all_items()))
 
1268
            }, node.keys)
1273
1269
 
1274
1270
    def assertFlattened(self, expected, key, value, refs):
1275
1271
        flat_key, flat_line = self.parse_btree._flatten_node(
1353
1349
        This doesn't actually create anything on disk, it just primes a
1354
1350
        BTreeGraphIndex with the recommended information.
1355
1351
        """
1356
 
        index = btree_index.BTreeGraphIndex(
1357
 
            transport.get_transport_from_url('memory:///'),
1358
 
            'test-index', size=size)
 
1352
        index = btree_index.BTreeGraphIndex(get_transport('memory:///'),
 
1353
                                            'test-index', size=size)
1359
1354
        if recommended_pages is not None:
1360
1355
            index._recommended_pages = recommended_pages
1361
1356
        return index