~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_btree_index.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-13 05:20:50 UTC
  • mfrom: (4634.52.16 2.0)
  • mto: This revision was merged to the branch mainline in revision 4738.
  • Revision ID: andrew.bennetts@canonical.com-20091013052050-u1w6tv0z7kqhn8d0
Merge 2.0 into lp:bzr, resolving conflicts in NEWS and releasing.txt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib import (
24
24
    btree_index,
25
25
    errors,
 
26
    fifo_cache,
 
27
    lru_cache,
26
28
    osutils,
27
29
    tests,
28
30
    )
1115
1117
        self.assertEqual({}, parent_map)
1116
1118
        self.assertEqual(set([('one',), ('two',)]), missing_keys)
1117
1119
 
 
1120
    def test_supports_unlimited_cache(self):
 
1121
        builder = btree_index.BTreeBuilder(reference_lists=0, key_elements=1)
 
1122
        # We need enough nodes to cause a page split (so we have both an
 
1123
        # internal node and a couple leaf nodes. 500 seems to be enough.)
 
1124
        nodes = self.make_nodes(500, 1, 0)
 
1125
        for node in nodes:
 
1126
            builder.add_node(*node)
 
1127
        stream = builder.finish()
 
1128
        trans = get_transport(self.get_url())
 
1129
        size = trans.put_file('index', stream)
 
1130
        index = btree_index.BTreeGraphIndex(trans, 'index', size)
 
1131
        self.assertEqual(500, index.key_count())
 
1132
        # We have an internal node
 
1133
        self.assertEqual(2, len(index._row_lengths))
 
1134
        # We have at least 2 leaf nodes
 
1135
        self.assertTrue(index._row_lengths[-1] >= 2)
 
1136
        self.assertIsInstance(index._leaf_node_cache, lru_cache.LRUCache)
 
1137
        self.assertEqual(btree_index._NODE_CACHE_SIZE,
 
1138
                         index._leaf_node_cache._max_cache)
 
1139
        self.assertIsInstance(index._internal_node_cache, fifo_cache.FIFOCache)
 
1140
        self.assertEqual(100, index._internal_node_cache._max_cache)
 
1141
        # No change if unlimited_cache=False is passed
 
1142
        index = btree_index.BTreeGraphIndex(trans, 'index', size,
 
1143
                                            unlimited_cache=False)
 
1144
        self.assertIsInstance(index._leaf_node_cache, lru_cache.LRUCache)
 
1145
        self.assertEqual(btree_index._NODE_CACHE_SIZE,
 
1146
                         index._leaf_node_cache._max_cache)
 
1147
        self.assertIsInstance(index._internal_node_cache, fifo_cache.FIFOCache)
 
1148
        self.assertEqual(100, index._internal_node_cache._max_cache)
 
1149
        index = btree_index.BTreeGraphIndex(trans, 'index', size,
 
1150
                                            unlimited_cache=True)
 
1151
        self.assertIsInstance(index._leaf_node_cache, dict)
 
1152
        self.assertIs(type(index._internal_node_cache), dict)
 
1153
        # Exercise the lookup code
 
1154
        entries = set(index.iter_entries([n[0] for n in nodes]))
 
1155
        self.assertEqual(500, len(entries))
 
1156
 
1118
1157
 
1119
1158
class TestBTreeNodes(BTreeTestCase):
1120
1159