1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
1
# Copyright (C) 2008, 2009 Canonical Ltd
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
468
468
self.assertEqual(new_root, chkmap._root_node._key)
470
def test_apply_delete_to_internal_node(self):
471
# applying a delta should be convert an internal root node to a leaf
472
# node if the delta shrinks the map enough.
473
store = self.get_chk_bytes()
474
chkmap = CHKMap(store, None)
475
# Add three items: 2 small enough to fit in one node, and one huge to
476
# force multiple nodes.
477
chkmap._root_node.set_maximum_size(100)
478
chkmap.map(('small',), 'value')
479
chkmap.map(('little',), 'value')
480
chkmap.map(('very-big',), 'x' * 100)
481
# (Check that we have constructed the scenario we want to test)
482
self.assertIsInstance(chkmap._root_node, InternalNode)
483
# Delete the huge item so that the map fits in one node again.
484
delta = [(('very-big',), None, None)]
485
chkmap.apply_delta(delta)
486
self.assertCanonicalForm(chkmap)
487
self.assertIsInstance(chkmap._root_node, LeafNode)
489
470
def test_apply_new_keys_must_be_new(self):
490
471
# applying a delta (None, "a", "b") to a map with 'a' in it generates
924
905
# Unmapping the new node will check the existing nodes to see if they
926
907
# Clear the page cache so we ensure we have to read all the children
927
chk_map.clear_cache()
908
chk_map._page_cache.clear()
928
909
chkmap.unmap(('aad',))
929
910
self.assertIsInstance(chkmap._root_node._items['aaa'], LeafNode)
930
911
self.assertIsInstance(chkmap._root_node._items['aab'], LeafNode)
964
945
# Now clear the page cache, and only include 2 of the children in the
966
947
aab_key = chkmap._root_node._items['aab']
967
aab_bytes = chk_map._get_cache()[aab_key]
948
aab_bytes = chk_map._page_cache[aab_key]
968
949
aac_key = chkmap._root_node._items['aac']
969
aac_bytes = chk_map._get_cache()[aac_key]
970
chk_map.clear_cache()
971
chk_map._get_cache()[aab_key] = aab_bytes
972
chk_map._get_cache()[aac_key] = aac_bytes
950
aac_bytes = chk_map._page_cache[aac_key]
951
chk_map._page_cache.clear()
952
chk_map._page_cache[aab_key] = aab_bytes
953
chk_map._page_cache[aac_key] = aac_bytes
974
955
# Unmapping the new node will check the nodes from the page cache
975
956
# first, and not have to read in 'aaa'