~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_groupcompress.py

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import zlib
20
20
 
21
21
from bzrlib import (
 
22
    btree_index,
22
23
    groupcompress,
23
24
    errors,
 
25
    index as _mod_index,
24
26
    osutils,
25
27
    tests,
26
28
    versionedfile,
475
477
 
476
478
class TestGroupCompressVersionedFiles(TestCaseWithGroupCompressVersionedFiles):
477
479
 
 
480
    def make_g_index(self, name, ref_lists=0, nodes=[]):
 
481
        builder = btree_index.BTreeBuilder(ref_lists)
 
482
        for node, references, value in nodes:
 
483
            builder.add_node(node, references, value)
 
484
        stream = builder.finish()
 
485
        trans = self.get_transport()
 
486
        size = trans.put_file(name, stream)
 
487
        return btree_index.BTreeGraphIndex(trans, name, size)
 
488
 
 
489
    def make_g_index_missing_parent(self):
 
490
        graph_index = self.make_g_index('missing_parent', 1,
 
491
            [(('parent', ), '2 78 2 10', ([],)),
 
492
             (('tip', ), '2 78 2 10',
 
493
              ([('parent', ), ('missing-parent', )],)),
 
494
              ])
 
495
        return graph_index
 
496
 
478
497
    def test_get_record_stream_as_requested(self):
479
498
        # Consider promoting 'as-requested' to general availability, and
480
499
        # make this a VF interface test
606
625
            else:
607
626
                self.assertIs(block, record._manager._block)
608
627
 
 
628
    def test_add_missing_noncompression_parent_unvalidated_index(self):
 
629
        unvalidated = self.make_g_index_missing_parent()
 
630
        combined = _mod_index.CombinedGraphIndex([unvalidated])
 
631
        index = groupcompress._GCGraphIndex(combined,
 
632
            is_locked=lambda: True, parents=True,
 
633
            track_external_parent_refs=True)
 
634
        index.scan_unvalidated_index(unvalidated)
 
635
        self.assertEqual(
 
636
            frozenset([('missing-parent',)]), index.get_missing_parents())
 
637
 
 
638
    def test_track_external_parent_refs(self):
 
639
        g_index = self.make_g_index('empty', 1, [])
 
640
        mod_index = btree_index.BTreeBuilder(1, 1)
 
641
        combined = _mod_index.CombinedGraphIndex([g_index, mod_index])
 
642
        index = groupcompress._GCGraphIndex(combined,
 
643
            is_locked=lambda: True, parents=True,
 
644
            add_callback=mod_index.add_nodes,
 
645
            track_external_parent_refs=True)
 
646
        index.add_records([
 
647
            (('new-key',), '2 10 2 10', [(('parent-1',), ('parent-2',))])])
 
648
        self.assertEqual(
 
649
            frozenset([('parent-1',), ('parent-2',)]),
 
650
            index.get_missing_parents())
 
651
 
609
652
 
610
653
class TestLazyGroupCompress(tests.TestCaseWithTransport):
611
654