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
1853
exp_tuple = (exp_record, sorted(exp_items))
1855
act_tuple = (None, sorted(items))
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))
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')])],
1865
[(target, [(('a',), 'content')]),
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')])],
1872
[(None, [(('a',), 'content')]),
1874
], [target], [basis])
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(
1875
1881
[target], [basis])
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(
1900
([b_key], [(('b',), 'other content')])],
1906
(b_key, [(('b',), 'other content')])],
1901
1907
[target], [basis])
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(
1929
([aab_key], [(('aab',), 'new')])],
1935
(aab_key, [(('aab',), 'new')])],
1930
1936
[target], [basis])
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',
1944
target3 = self.get_map_key({('aaa',): 'common',
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(
1954
" ('aaa',) 'common'\n",
1955
target1_map._dump_tree())
1956
target2_map = CHKMap(self.get_chk_bytes(), target2)
1957
self.assertEqualDiff(
1960
" ('aaa',) 'common'\n"
1962
" ('bbb',) 'new'\n",
1963
target2_map._dump_tree())
1964
target3_map = CHKMap(self.get_chk_bytes(), target3)
1965
self.assertEqualDiff(
1967
" 'a' InternalNode\n"
1969
" ('aaa',) 'common'\n"
1971
" ('aac',) 'other'\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')]),
1984
(b_key, [(('bbb',), 'new')]),
1986
(aac_key, [(('aac',), 'other')]),
1987
], [target1, target2, target3], [basis])
1989
self.assertIterInteresting(
1992
(b_key, [(('bbb',), 'new')]),
1994
(aac_key, [(('aac',), 'other')]),
1995
], [target2, target3], [target1])
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
2001
self.assertIterInteresting(
2002
[], [target1], [target3])
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], []),
1982
([aac_key], [(('aac',), 'target1')]),
1983
([bba_key], [(('bba',), 'target2')]),
2055
(aac_key, [(('aac',), 'target1')]),
2056
(bba_key, [(('bba',), 'target2')]),
1984
2057
], [target1, target2], [basis1, basis2])