~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.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:
48
48
    get_transport,
49
49
    )
50
50
from bzrlib.transport.memory import MemoryServer
51
 
from bzrlib.util import bencode
52
51
from bzrlib import (
 
52
    bencode,
53
53
    bzrdir,
54
54
    errors,
55
55
    inventory,
686
686
            inv.parent_id_basename_to_file_id._root_node.maximum_size)
687
687
 
688
688
 
689
 
class TestDevelopment6FindRevisionOutsideSet(TestCaseWithTransport):
690
 
    """Tests for _find_revision_outside_set."""
 
689
class TestDevelopment6FindParentIdsOfRevisions(TestCaseWithTransport):
 
690
    """Tests for _find_parent_ids_of_revisions."""
691
691
 
692
692
    def setUp(self):
693
 
        super(TestDevelopment6FindRevisionOutsideSet, self).setUp()
 
693
        super(TestDevelopment6FindParentIdsOfRevisions, self).setUp()
694
694
        self.builder = self.make_branch_builder('source',
695
695
            format='development6-rich-root')
696
696
        self.builder.start_series()
699
699
        self.repo = self.builder.get_branch().repository
700
700
        self.addCleanup(self.builder.finish_series)
701
701
 
702
 
    def assertRevisionOutsideSet(self, expected_result, rev_set):
703
 
        self.assertEqual(
704
 
            expected_result, self.repo._find_revision_outside_set(rev_set))
 
702
    def assertParentIds(self, expected_result, rev_set):
 
703
        self.assertEqual(sorted(expected_result),
 
704
            sorted(self.repo._find_parent_ids_of_revisions(rev_set)))
705
705
 
706
706
    def test_simple(self):
707
707
        self.builder.build_snapshot('revid1', None, [])
708
 
        self.builder.build_snapshot('revid2', None, [])
 
708
        self.builder.build_snapshot('revid2', ['revid1'], [])
709
709
        rev_set = ['revid2']
710
 
        self.assertRevisionOutsideSet('revid1', rev_set)
 
710
        self.assertParentIds(['revid1'], rev_set)
711
711
 
712
712
    def test_not_first_parent(self):
713
713
        self.builder.build_snapshot('revid1', None, [])
714
 
        self.builder.build_snapshot('revid2', None, [])
715
 
        self.builder.build_snapshot('revid3', None, [])
 
714
        self.builder.build_snapshot('revid2', ['revid1'], [])
 
715
        self.builder.build_snapshot('revid3', ['revid2'], [])
716
716
        rev_set = ['revid3', 'revid2']
717
 
        self.assertRevisionOutsideSet('revid1', rev_set)
 
717
        self.assertParentIds(['revid1'], rev_set)
718
718
 
719
719
    def test_not_null(self):
720
720
        rev_set = ['initial']
721
 
        self.assertRevisionOutsideSet(_mod_revision.NULL_REVISION, rev_set)
 
721
        self.assertParentIds([], rev_set)
722
722
 
723
723
    def test_not_null_set(self):
724
724
        self.builder.build_snapshot('revid1', None, [])
725
725
        rev_set = [_mod_revision.NULL_REVISION]
726
 
        self.assertRevisionOutsideSet(_mod_revision.NULL_REVISION, rev_set)
 
726
        self.assertParentIds([], rev_set)
727
727
 
728
728
    def test_ghost(self):
729
729
        self.builder.build_snapshot('revid1', None, [])
730
730
        rev_set = ['ghost', 'revid1']
731
 
        self.assertRevisionOutsideSet('initial', rev_set)
 
731
        self.assertParentIds(['initial'], rev_set)
732
732
 
733
733
    def test_ghost_parent(self):
734
734
        self.builder.build_snapshot('revid1', None, [])
735
735
        self.builder.build_snapshot('revid2', ['revid1', 'ghost'], [])
736
736
        rev_set = ['revid2', 'revid1']
737
 
        self.assertRevisionOutsideSet('initial', rev_set)
 
737
        self.assertParentIds(['ghost', 'initial'], rev_set)
738
738
 
739
739
    def test_righthand_parent(self):
740
740
        self.builder.build_snapshot('revid1', None, [])
742
742
        self.builder.build_snapshot('revid2b', ['revid1'], [])
743
743
        self.builder.build_snapshot('revid3', ['revid2a', 'revid2b'], [])
744
744
        rev_set = ['revid3', 'revid2a']
745
 
        self.assertRevisionOutsideSet('revid2b', rev_set)
 
745
        self.assertParentIds(['revid1', 'revid2b'], rev_set)
746
746
 
747
747
 
748
748
class TestWithBrokenRepo(TestCaseWithTransport):
1220
1220
        stream = source._get_source(target._format)
1221
1221
        # We don't want the child GroupCHKStreamSource
1222
1222
        self.assertIs(type(stream), repository.StreamSource)
 
1223
 
 
1224
    def test_get_stream_for_missing_keys_includes_all_chk_refs(self):
 
1225
        source_builder = self.make_branch_builder('source',
 
1226
                            format='development6-rich-root')
 
1227
        # We have to build a fairly large tree, so that we are sure the chk
 
1228
        # pages will have split into multiple pages.
 
1229
        entries = [('add', ('', 'a-root-id', 'directory', None))]
 
1230
        for i in 'abcdefghijklmnopqrstuvwxyz123456789':
 
1231
            for j in 'abcdefghijklmnopqrstuvwxyz123456789':
 
1232
                fname = i + j
 
1233
                fid = fname + '-id'
 
1234
                content = 'content for %s\n' % (fname,)
 
1235
                entries.append(('add', (fname, fid, 'file', content)))
 
1236
        source_builder.start_series()
 
1237
        source_builder.build_snapshot('rev-1', None, entries)
 
1238
        # Now change a few of them, so we get a few new pages for the second
 
1239
        # revision
 
1240
        source_builder.build_snapshot('rev-2', ['rev-1'], [
 
1241
            ('modify', ('aa-id', 'new content for aa-id\n')),
 
1242
            ('modify', ('cc-id', 'new content for cc-id\n')),
 
1243
            ('modify', ('zz-id', 'new content for zz-id\n')),
 
1244
            ])
 
1245
        source_builder.finish_series()
 
1246
        source_branch = source_builder.get_branch()
 
1247
        source_branch.lock_read()
 
1248
        self.addCleanup(source_branch.unlock)
 
1249
        target = self.make_repository('target', format='development6-rich-root')
 
1250
        source = source_branch.repository._get_source(target._format)
 
1251
        self.assertIsInstance(source, groupcompress_repo.GroupCHKStreamSource)
 
1252
 
 
1253
        # On a regular pass, getting the inventories and chk pages for rev-2
 
1254
        # would only get the newly created chk pages
 
1255
        search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
 
1256
                                    set(['rev-2']))
 
1257
        simple_chk_records = []
 
1258
        for vf_name, substream in source.get_stream(search):
 
1259
            if vf_name == 'chk_bytes':
 
1260
                for record in substream:
 
1261
                    simple_chk_records.append(record.key)
 
1262
            else:
 
1263
                for _ in substream:
 
1264
                    continue
 
1265
        # 3 pages, the root (InternalNode), + 2 pages which actually changed
 
1266
        self.assertEqual([('sha1:91481f539e802c76542ea5e4c83ad416bf219f73',),
 
1267
                          ('sha1:4ff91971043668583985aec83f4f0ab10a907d3f',),
 
1268
                          ('sha1:81e7324507c5ca132eedaf2d8414ee4bb2226187',),
 
1269
                          ('sha1:b101b7da280596c71a4540e9a1eeba8045985ee0',)],
 
1270
                         simple_chk_records)
 
1271
        # Now, when we do a similar call using 'get_stream_for_missing_keys'
 
1272
        # we should get a much larger set of pages.
 
1273
        missing = [('inventories', 'rev-2')]
 
1274
        full_chk_records = []
 
1275
        for vf_name, substream in source.get_stream_for_missing_keys(missing):
 
1276
            if vf_name == 'inventories':
 
1277
                for record in substream:
 
1278
                    self.assertEqual(('rev-2',), record.key)
 
1279
            elif vf_name == 'chk_bytes':
 
1280
                for record in substream:
 
1281
                    full_chk_records.append(record.key)
 
1282
            else:
 
1283
                self.fail('Should not be getting a stream of %s' % (vf_name,))
 
1284
        # We have 257 records now. This is because we have 1 root page, and 256
 
1285
        # leaf pages in a complete listing.
 
1286
        self.assertEqual(257, len(full_chk_records))
 
1287
        self.assertSubset(simple_chk_records, full_chk_records)