1115
1117
self.assertEqual({}, parent_map)
1116
1118
self.assertEqual(set([('one',), ('two',)]), missing_keys)
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)
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))
1119
1158
class TestBTreeNodes(BTreeTestCase):