~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_index.py

  • Committer: Andrew Bennetts
  • Date: 2010-03-26 04:47:45 UTC
  • mfrom: (5116 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5117.
  • Revision ID: andrew.bennetts@canonical.com-20100326044745-ubvt5tmse1a17s1f
MergeĀ lp:bzr.

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)