~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_btree_index.py

  • Committer: Martin Pool
  • Date: 2010-07-21 09:58:42 UTC
  • mfrom: (4797.58.7 2.1)
  • mto: (5050.3.13 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: mbp@canonical.com-20100721095842-hz0obu8gl0x05nty
merge up 2.1 to 2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
216
216
        leaf1_bytes = zlib.decompress(leaf1)
217
217
        sorted_node_keys = sorted(node[0] for node in nodes)
218
218
        node = btree_index._LeafNode(leaf1_bytes, 1, 0)
219
 
        self.assertEqual(231, len(node))
220
 
        self.assertEqual(sorted_node_keys[:231], node.all_keys())
 
219
        self.assertEqual(231, len(node.keys))
 
220
        self.assertEqual(sorted_node_keys[:231], sorted(node.keys))
221
221
        leaf2_bytes = zlib.decompress(leaf2)
222
222
        node = btree_index._LeafNode(leaf2_bytes, 1, 0)
223
 
        self.assertEqual(400 - 231, len(node))
224
 
        self.assertEqual(sorted_node_keys[231:], node.all_keys())
 
223
        self.assertEqual(400 - 231, len(node.keys))
 
224
        self.assertEqual(sorted_node_keys[231:], sorted(node.keys))
225
225
 
226
226
    def test_last_page_rounded_1_layer(self):
227
227
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
241
241
        leaf2 = content[74:]
242
242
        leaf2_bytes = zlib.decompress(leaf2)
243
243
        node = btree_index._LeafNode(leaf2_bytes, 1, 0)
244
 
        self.assertEqual(10, len(node))
 
244
        self.assertEqual(10, len(node.keys))
245
245
        sorted_node_keys = sorted(node[0] for node in nodes)
246
 
        self.assertEqual(sorted_node_keys, node.all_keys())
 
246
        self.assertEqual(sorted_node_keys, sorted(node.keys))
247
247
 
248
248
    def test_last_page_not_rounded_2_layer(self):
249
249
        builder = btree_index.BTreeBuilder(key_elements=1, reference_lists=0)
263
263
        leaf2 = content[8192:]
264
264
        leaf2_bytes = zlib.decompress(leaf2)
265
265
        node = btree_index._LeafNode(leaf2_bytes, 1, 0)
266
 
        self.assertEqual(400 - 231, len(node))
 
266
        self.assertEqual(400 - 231, len(node.keys))
267
267
        sorted_node_keys = sorted(node[0] for node in nodes)
268
 
        self.assertEqual(sorted_node_keys[231:], node.all_keys())
 
268
        self.assertEqual(sorted_node_keys[231:], sorted(node.keys))
269
269
 
270
270
    def test_three_level_tree_details(self):
271
271
        # The left most pointer in the second internal node in a row should
302
302
        # in the second node it points at
303
303
        pos = index._row_offsets[2] + internal_node2.offset + 1
304
304
        leaf = index._get_leaf_nodes([pos])[pos]
305
 
        self.assertTrue(internal_node2.keys[0] in leaf)
 
305
        self.assertTrue(internal_node2.keys[0] in leaf.keys)
306
306
 
307
307
    def test_2_leaves_2_2(self):
308
308
        builder = btree_index.BTreeBuilder(key_elements=2, reference_lists=2)
728
728
        nodes = dict(index._read_nodes([0]))
729
729
        self.assertEqual([0], nodes.keys())
730
730
        node = nodes[0]
731
 
        self.assertEqual([('key',)], node.all_keys())
 
731
        self.assertEqual([('key',)], node.keys.keys())
732
732
        self.assertEqual([('get', 'index')], trans._activity)
733
733
 
734
734
    def test__read_nodes_no_size_multiple_pages(self):
1112
1112
        min_l2_key = l2.min_key
1113
1113
        max_l1_key = l1.max_key
1114
1114
        self.assertTrue(max_l1_key < min_l2_key)
1115
 
        parents_min_l2_key = l2[min_l2_key][1][0]
 
1115
        parents_min_l2_key = l2.keys[min_l2_key][1][0]
1116
1116
        self.assertEqual((l1.max_key,), parents_min_l2_key)
1117
1117
        # Now, whatever key we select that would fall on the second page,
1118
1118
        # should give us all the parents until the page break
1131
1131
        parent_map = {}
1132
1132
        search_keys = index._find_ancestors([max_l1_key], 0, parent_map,
1133
1133
                                            missing_keys)
1134
 
        self.assertEqual(l1.all_keys(), sorted(parent_map))
 
1134
        self.assertEqual(sorted(l1.keys), sorted(parent_map))
1135
1135
        self.assertEqual(set(), missing_keys)
1136
1136
        self.assertEqual(set(), search_keys)
1137
1137
 
1205
1205
            ("2222222222222222222222222222222222222222",): ("value:2", ()),
1206
1206
            ("3333333333333333333333333333333333333333",): ("value:3", ()),
1207
1207
            ("4444444444444444444444444444444444444444",): ("value:4", ()),
1208
 
            }, dict(node.all_items()))
 
1208
            }, node.keys)
1209
1209
 
1210
1210
    def test_LeafNode_2_2(self):
1211
1211
        node_bytes = ("type=leaf\n"
1225
1225
            ('11', '33'): ('value:3',
1226
1226
                ((('11', 'ref22'),), (('11', 'ref22'), ('11', 'ref22')))),
1227
1227
            ('11', '44'): ('value:4', ((), (('11', 'ref00'),)))
1228
 
            }, dict(node.all_items()))
 
1228
            }, node.keys)
1229
1229
 
1230
1230
    def test_InternalNode_1(self):
1231
1231
        node_bytes = ("type=internal\n"
1266
1266
            ('11', '33'): ('value:3',
1267
1267
                ((('11', 'ref22'),), (('11', 'ref22'), ('11', 'ref22')))),
1268
1268
            ('11', '44'): ('value:4', ((), (('11', 'ref00'),)))
1269
 
            }, dict(node.all_items()))
 
1269
            }, node.keys)
1270
1270
 
1271
1271
    def assertFlattened(self, expected, key, value, refs):
1272
1272
        flat_key, flat_line = self.parse_btree._flatten_node(