~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_chk_map.py

Merge the 2.1-static-tuple-no-use branch, but restore the
functionality to btree that involves using StaticTuple instead of tuple().
At this point, I'm leaving out the changes to string interning, as that
can easily be considered a separate patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
831
831
        # 'ab' and 'ac' nodes
832
832
        chkmap.map(('aad',), 'v')
833
833
        self.assertIsInstance(chkmap._root_node._items['aa'], InternalNode)
834
 
        self.assertIsInstance(chkmap._root_node._items['ab'], (tuple, chk_map._key_type))
835
 
        self.assertIsInstance(chkmap._root_node._items['ac'], (tuple, chk_map._key_type))
 
834
        self.assertIsInstance(chkmap._root_node._items['ab'], tuple)
 
835
        self.assertIsInstance(chkmap._root_node._items['ac'], tuple)
836
836
        # Unmapping 'acd' can notice that 'aa' is an InternalNode and not have
837
837
        # to map in 'ab'
838
838
        chkmap.unmap(('acd',))
839
839
        self.assertIsInstance(chkmap._root_node._items['aa'], InternalNode)
840
 
        self.assertIsInstance(chkmap._root_node._items['ab'], (tuple, chk_map._key_type))
 
840
        self.assertIsInstance(chkmap._root_node._items['ab'], tuple)
841
841
 
842
842
    def test_unmap_without_fitting_doesnt_page_in(self):
843
843
        store = self.get_chk_bytes()
860
860
        chkmap.map(('aaf',), 'v')
861
861
        # At this point, the previous nodes should not be paged in, but the
862
862
        # newly added nodes would be
863
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
864
 
        chk_map._key_type))
865
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple, chk_map._key_type))
 
863
        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
 
864
        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
866
865
        self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
867
866
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
868
867
        self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
870
869
        # Now unmapping one of the new nodes will use only the already-paged-in
871
870
        # nodes to determine that we don't need to do more.
872
871
        chkmap.unmap(('aaf',))
873
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple, chk_map._key_type))
874
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple, chk_map._key_type))
 
872
        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
 
873
        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
875
874
        self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
876
875
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
877
876
        self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
898
897
        chkmap.map(('aad',), 'v')
899
898
        # At this point, the previous nodes should not be paged in, but the
900
899
        # newly added node would be
901
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
902
 
        chk_map._key_type))
903
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
904
 
        chk_map._key_type))
905
 
        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
906
 
        chk_map._key_type))
 
900
        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
 
901
        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
 
902
        self.assertIsInstance(chkmap._root_node._items['aac'], tuple)
907
903
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
908
904
        # Unmapping the new node will check the existing nodes to see if they
909
905
        # would fit.
941
937
        chkmap.map(('aad',), 'v')
942
938
        # At this point, the previous nodes should not be paged in, but the
943
939
        # newly added node would be
944
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
945
 
        chk_map._key_type))
946
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
947
 
        chk_map._key_type))
948
 
        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
949
 
        chk_map._key_type))
 
940
        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
 
941
        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
 
942
        self.assertIsInstance(chkmap._root_node._items['aac'], tuple)
950
943
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
951
944
        # Now clear the page cache, and only include 2 of the children in the
952
945
        # cache
961
954
        # Unmapping the new node will check the nodes from the page cache
962
955
        # first, and not have to read in 'aaa'
963
956
        chkmap.unmap(('aad',))
964
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
965
 
        chk_map._key_type))
 
957
        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
966
958
        self.assertIsInstance(chkmap._root_node._items['aab'], LeafNode)
967
959
        self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
968
960
 
982
974
        chkmap.map(('aaf',), 'val')
983
975
        # At this point, the previous nodes should not be paged in, but the
984
976
        # newly added node would be
985
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
986
 
        chk_map._key_type))
987
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
988
 
        chk_map._key_type))
989
 
        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
990
 
        chk_map._key_type))
 
977
        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
 
978
        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
 
979
        self.assertIsInstance(chkmap._root_node._items['aac'], tuple)
991
980
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
992
981
        self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
993
982
        self.assertIsInstance(chkmap._root_node._items['aaf'], LeafNode)
995
984
        # Unmapping a new node will see the other nodes that are already in
996
985
        # memory, and not need to page in anything else
997
986
        chkmap.unmap(('aad',))
998
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
999
 
        chk_map._key_type))
1000
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
1001
 
        chk_map._key_type))
1002
 
        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
1003
 
        chk_map._key_type))
 
987
        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
 
988
        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
 
989
        self.assertIsInstance(chkmap._root_node._items['aac'], tuple)
1004
990
        self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
1005
991
        self.assertIsInstance(chkmap._root_node._items['aaf'], LeafNode)
1006
992
 
1045
1031
            {('a',): 'content here', ('b',): 'more content'},
1046
1032
            chk_bytes=basis._store, maximum_size=10)
1047
1033
        list(target.iter_changes(basis))
1048
 
        self.assertIsInstance(target._root_node, (tuple, chk_map._key_type))
1049
 
        self.assertIsInstance(basis._root_node, (tuple, chk_map._key_type))
 
1034
        self.assertIsInstance(target._root_node, tuple)
 
1035
        self.assertIsInstance(basis._root_node, tuple)
1050
1036
 
1051
1037
    def test_iter_changes_ab_ab_changed_values_shown(self):
1052
1038
        basis = self._get_map({('a',): 'content here', ('b',): 'more content'},
1946
1932
        # Ensure test validity: nothing paged in below the root.
1947
1933
        self.assertEqual(2,
1948
1934
            len([value for value in node._items.values()
1949
 
                if type(value) in (tuple, chk_map._key_type)]))
 
1935
                if type(value) == tuple]))
1950
1936
        # now, mapping to k3 should add a k3 leaf
1951
1937
        prefix, nodes = node.map(None, ('k3',), 'quux')
1952
1938
        self.assertEqual("k", prefix)
1985
1971
        # Ensure test validity: nothing paged in below the root.
1986
1972
        self.assertEqual(2,
1987
1973
            len([value for value in node._items.values()
1988
 
                if type(value) in (tuple, chk_map._key_type)]))
 
1974
                if type(value) == tuple]))
1989
1975
        # now, mapping to k23 causes k22 ('k2' in node) to split into k22 and
1990
1976
        # k23, which for simplicity in the current implementation generates
1991
1977
        # a new internal node between node, and k22/k23.