~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_index.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
388
388
        size = trans.put_file('index', stream)
389
389
        return GraphIndex(trans, 'index', size)
390
390
 
 
391
    def make_index_with_offset(self, ref_lists=0, key_elements=1, nodes=[],
 
392
                               offset=0):
 
393
        builder = GraphIndexBuilder(ref_lists, key_elements=key_elements)
 
394
        for key, value, references in nodes:
 
395
            builder.add_node(key, value, references)
 
396
        content = builder.finish().read()
 
397
        size = len(content)
 
398
        trans = self.get_transport()
 
399
        trans.put_bytes('index', (' '*offset) + content)
 
400
        return GraphIndex(trans, 'index', size, offset=offset)
 
401
 
391
402
    def test_clear_cache(self):
392
403
        index = self.make_index()
393
404
        # For now, we just want to make sure the api is available. As this is
399
410
        trans.put_bytes('name', "not an index\n")
400
411
        index = GraphIndex(trans, 'name', 13)
401
412
 
 
413
    def test_with_offset(self):
 
414
        nodes = self.make_nodes(200)
 
415
        index = self.make_index_with_offset(offset=1234567, nodes=nodes)
 
416
        self.assertEqual(200, index.key_count())
 
417
 
 
418
    def test_buffer_all_with_offset(self):
 
419
        nodes = self.make_nodes(200)
 
420
        index = self.make_index_with_offset(offset=1234567, nodes=nodes)
 
421
        index._buffer_all()
 
422
        self.assertEqual(200, index.key_count())
 
423
 
 
424
    def test_side_effect_buffering_with_offset(self):
 
425
        nodes = self.make_nodes(20)
 
426
        index = self.make_index_with_offset(offset=1234567, nodes=nodes)
 
427
        index._transport.recommended_page_size = lambda:64*1024
 
428
        subset_nodes = [nodes[0][0], nodes[10][0], nodes[19][0]]
 
429
        entries = [n[1] for n in index.iter_entries(subset_nodes)]
 
430
        self.assertEqual(sorted(subset_nodes), sorted(entries))
 
431
        self.assertEqual(20, index.key_count())
 
432
 
402
433
    def test_open_sets_parsed_map_empty(self):
403
434
        index = self.make_index()
404
435
        self.assertEqual([], index._parsed_byte_map)