~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_chk_map.py

iter_interesting_nodes no longer buffers record objects.
Instead, it double-requests them, which means that we can now cleanly
clear the refcycle from lazy content manager to the lazy content.
(at the end of get_record_stream()).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1846
1846
        store = self.get_chk_bytes()
1847
1847
        iter_nodes = chk_map.iter_interesting_nodes(store, interesting_keys,
1848
1848
                                                    uninteresting_keys)
1849
 
        for count, (exp, act) in enumerate(izip(expected, iter_nodes)):
1850
 
            exp_record_keys, exp_items = exp
1851
 
            records, items = act
1852
 
            exp_tuple = (sorted(exp_record_keys), sorted(exp_items))
1853
 
            act_tuple = (sorted(records.keys()), sorted(items))
1854
 
            self.assertEqual(exp_tuple, act_tuple)
1855
 
        self.assertEqual(len(expected), count + 1)
 
1849
        nodes = list(iter_nodes)
 
1850
        for count, (exp, act) in enumerate(izip(expected, nodes)):
 
1851
            exp_record, exp_items = exp
 
1852
            record, items = act
 
1853
            exp_tuple = (exp_record, sorted(exp_items))
 
1854
            if record is None:
 
1855
                act_tuple = (None, sorted(items))
 
1856
            else:
 
1857
                act_tuple = (record.key, sorted(items))
 
1858
            self.assertEqual(exp_tuple, act_tuple,
 
1859
                             'entry %d did not match expected' % count)
 
1860
        self.assertEqual(len(expected), len(nodes))
1856
1861
 
1857
1862
    def test_empty_to_one_keys(self):
1858
1863
        target = self.get_map_key({('a',): 'content'})
1859
1864
        self.assertIterInteresting(
1860
 
            [([target], [(('a',), 'content')])],
1861
 
            [target], [])
 
1865
            [(target, [(('a',), 'content')]),
 
1866
            ], [target], [])
1862
1867
 
1863
1868
    def test_none_to_one_key(self):
1864
1869
        basis = self.get_map_key({})
1865
1870
        target = self.get_map_key({('a',): 'content'})
1866
1871
        self.assertIterInteresting(
1867
 
            [([target], [(('a',), 'content')])],
1868
 
            [target], [basis])
 
1872
            [(None, [(('a',), 'content')]),
 
1873
             (target, []),
 
1874
            ], [target], [basis])
1869
1875
 
1870
1876
    def test_one_to_none_key(self):
1871
1877
        basis = self.get_map_key({('a',): 'content'})
1872
1878
        target = self.get_map_key({})
1873
1879
        self.assertIterInteresting(
1874
 
            [([target], [])],
 
1880
            [(target, [])],
1875
1881
            [target], [basis])
1876
1882
 
1877
1883
    def test_common_pages(self):
1896
1902
        b_key = target_map._root_node._items['b'].key()
1897
1903
        # This should return the root node, and the node for the 'b' key
1898
1904
        self.assertIterInteresting(
1899
 
            [([target], []),
1900
 
             ([b_key], [(('b',), 'other content')])],
 
1905
            [(target, []),
 
1906
             (b_key, [(('b',), 'other content')])],
1901
1907
            [target], [basis])
1902
1908
 
1903
1909
    def test_common_sub_page(self):
1924
1930
        # The key for the leaf aab node
1925
1931
        aab_key = target_map._root_node._items['a']._items['aab'].key()
1926
1932
        self.assertIterInteresting(
1927
 
            [([target], []),
1928
 
             ([a_key], []),
1929
 
             ([aab_key], [(('aab',), 'new')])],
 
1933
            [(target, []),
 
1934
             (a_key, []),
 
1935
             (aab_key, [(('aab',), 'new')])],
1930
1936
            [target], [basis])
1931
1937
 
 
1938
    def test_common_leaf(self):
 
1939
        basis = self.get_map_key({})
 
1940
        target1 = self.get_map_key({('aaa',): 'common'})
 
1941
        target2 = self.get_map_key({('aaa',): 'common',
 
1942
                                    ('bbb',): 'new',
 
1943
                                   })
 
1944
        target3 = self.get_map_key({('aaa',): 'common',
 
1945
                                    ('aac',): 'other',
 
1946
                                    ('bbb',): 'new',
 
1947
                                   })
 
1948
        # The LeafNode containing 'aaa': 'common' occurs at 3 different levels.
 
1949
        # Once as a root node, once as a second layer, and once as a third
 
1950
        # layer. It should only be returned one time regardless
 
1951
        target1_map = CHKMap(self.get_chk_bytes(), target1)
 
1952
        self.assertEqualDiff(
 
1953
            "'' LeafNode\n"
 
1954
            "      ('aaa',) 'common'\n",
 
1955
            target1_map._dump_tree())
 
1956
        target2_map = CHKMap(self.get_chk_bytes(), target2)
 
1957
        self.assertEqualDiff(
 
1958
            "'' InternalNode\n"
 
1959
            "  'a' LeafNode\n"
 
1960
            "      ('aaa',) 'common'\n"
 
1961
            "  'b' LeafNode\n"
 
1962
            "      ('bbb',) 'new'\n",
 
1963
            target2_map._dump_tree())
 
1964
        target3_map = CHKMap(self.get_chk_bytes(), target3)
 
1965
        self.assertEqualDiff(
 
1966
            "'' InternalNode\n"
 
1967
            "  'a' InternalNode\n"
 
1968
            "    'aaa' LeafNode\n"
 
1969
            "      ('aaa',) 'common'\n"
 
1970
            "    'aac' LeafNode\n"
 
1971
            "      ('aac',) 'other'\n"
 
1972
            "  'b' LeafNode\n"
 
1973
            "      ('bbb',) 'new'\n",
 
1974
            target3_map._dump_tree())
 
1975
        aaa_key = target1_map._root_node.key()
 
1976
        b_key = target2_map._root_node._items['b'].key()
 
1977
        a_key = target3_map._root_node._items['a'].key()
 
1978
        aac_key = target3_map._root_node._items['a']._items['aac'].key()
 
1979
        self.assertIterInteresting(
 
1980
            [(None, [(('aaa',), 'common')]),
 
1981
             (target1, []),
 
1982
             (target2, []),
 
1983
             (target3, []),
 
1984
             (b_key, [(('bbb',), 'new')]),
 
1985
             (a_key, []),
 
1986
             (aac_key, [(('aac',), 'other')]),
 
1987
            ], [target1, target2, target3], [basis])
 
1988
 
 
1989
        self.assertIterInteresting(
 
1990
            [(target2, []),
 
1991
             (target3, []),
 
1992
             (b_key, [(('bbb',), 'new')]),
 
1993
             (a_key, []),
 
1994
             (aac_key, [(('aac',), 'other')]),
 
1995
            ], [target2, target3], [target1])
 
1996
 
 
1997
        # This may be a case that we relax. A root node is a deep child of the
 
1998
        # excluded set. The cost is buffering root nodes until we have
 
1999
        # determined all possible exclusions. (Because a prefix of '', cannot
 
2000
        # be excluded.)
 
2001
        self.assertIterInteresting(
 
2002
            [], [target1], [target3])
 
2003
 
1932
2004
    def test_multiple_maps(self):
1933
2005
        basis1 = self.get_map_key({('aaa',): 'common',
1934
2006
                                   ('aab',): 'basis1',
1976
2048
        # The key for the leaf bba node
1977
2049
        bba_key = target2_map._root_node._items['b']._items['bba'].key()
1978
2050
        self.assertIterInteresting(
1979
 
            [([target1, target2], []),
1980
 
             ([a_key], []),
1981
 
             ([b_key], []),
1982
 
             ([aac_key], [(('aac',), 'target1')]),
1983
 
             ([bba_key], [(('bba',), 'target2')]),
 
2051
            [(target1, []),
 
2052
             (target2, []),
 
2053
             (a_key, []),
 
2054
             (b_key, []),
 
2055
             (aac_key, [(('aac',), 'target1')]),
 
2056
             (bba_key, [(('bba',), 'target2')]),
1984
2057
            ], [target1, target2], [basis1, basis2])