/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_pack_repository.py

  • Committer: Robert Collins
  • Date: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for pack repositories.
18
18
 
38
38
    upgrade,
39
39
    workingtree,
40
40
    )
 
41
from bzrlib.repofmt.groupcompress_repo import RepositoryFormatCHK1
41
42
from bzrlib.smart import (
42
43
    client,
43
44
    server,
79
80
        """Packs reuse deltas."""
80
81
        format = self.get_format()
81
82
        repo = self.make_repository('.', format=format)
82
 
        self.assertEqual(True, repo._format._fetch_uses_deltas)
 
83
        if isinstance(format.repository_format, RepositoryFormatCHK1):
 
84
            # TODO: This is currently a workaround. CHK format repositories
 
85
            #       ignore the 'deltas' flag, but during conversions, we can't
 
86
            #       do unordered delta fetches. Remove this clause once we
 
87
            #       improve the inter-format fetching.
 
88
            self.assertEqual(False, repo._format._fetch_uses_deltas)
 
89
        else:
 
90
            self.assertEqual(True, repo._format._fetch_uses_deltas)
83
91
 
84
92
    def test_disk_layout(self):
85
93
        format = self.get_format()
208
216
        tree = tree.bzrdir.open_workingtree()
209
217
        check_result = tree.branch.repository.check(
210
218
            [tree.branch.last_revision()])
211
 
        # We should have 50 (10x5) files in the obsolete_packs directory.
 
219
        nb_files = 5 # .pack, .rix, .iix, .tix, .six
 
220
        if tree.branch.repository._format.supports_chks:
 
221
            nb_files += 1 # .cix
 
222
        # We should have 10 x nb_files files in the obsolete_packs directory.
212
223
        obsolete_files = list(trans.list_dir('obsolete_packs'))
213
224
        self.assertFalse('foo' in obsolete_files)
214
225
        self.assertFalse('bar' in obsolete_files)
215
 
        self.assertEqual(50, len(obsolete_files))
 
226
        self.assertEqual(10 * nb_files, len(obsolete_files))
216
227
        # XXX: Todo check packs obsoleted correctly - old packs and indices
217
228
        # in the obsolete_packs directory.
218
229
        large_pack_name = list(index.iter_all_entries())[0][1][0]
252
263
        self.assertEqual(2, len(tree.branch.repository.all_revision_ids()))
253
264
 
254
265
    def test_pack_layout(self):
 
266
        # Test that the ordering of revisions in pack repositories is
 
267
        # tip->ancestor
255
268
        format = self.get_format()
256
269
        tree = self.make_branch_and_tree('.', format=format)
257
270
        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
265
278
        # revision access tends to be tip->ancestor, so ordering that way on
266
279
        # disk is a good idea.
267
280
        for _1, key, val, refs in pack.revision_index.iter_all_entries():
 
281
            if type(format.repository_format) is RepositoryFormatCHK1:
 
282
                # group_start, group_len, internal_start, internal_len
 
283
                pos = map(int, val.split())
 
284
            else:
 
285
                # eol_flag, start, len
 
286
                pos = int(val[1:].split()[0])
268
287
            if key == ('1',):
269
 
                pos_1 = int(val[1:].split()[0])
 
288
                pos_1 = pos
270
289
            else:
271
 
                pos_2 = int(val[1:].split()[0])
272
 
        self.assertTrue(pos_2 < pos_1)
 
290
                pos_2 = pos
 
291
        self.assertTrue(pos_2 < pos_1, 'rev 1 came before rev 2 %s > %s'
 
292
                                       % (pos_1, pos_2))
273
293
 
274
294
    def test_pack_repositories_support_multiple_write_locks(self):
275
295
        format = self.get_format()
283
303
 
284
304
    def _add_text(self, repo, fileid):
285
305
        """Add a text to the repository within a write group."""
286
 
        repo.texts.add_lines((fileid, 'samplerev+'+fileid), [], [])
 
306
        repo.texts.add_lines((fileid, 'samplerev+'+fileid), [],
 
307
            ['smaplerev+'+fileid])
287
308
 
288
309
    def test_concurrent_writers_merge_new_packs(self):
289
310
        format = self.get_format()
543
564
    def test_missing_inventories_compression_parent_prevents_commit(self):
544
565
        repo = self.make_write_ready_repo()
545
566
        key = ('junk',)
 
567
        if not getattr(repo.inventories._index, '_missing_compression_parents',
 
568
            None):
 
569
            raise TestSkipped("No missing compression parents")
546
570
        repo.inventories._index._missing_compression_parents.add(key)
547
571
        self.assertRaises(errors.BzrCheckError, repo.commit_write_group)
548
572
        self.assertRaises(errors.BzrCheckError, repo.commit_write_group)
552
576
    def test_missing_revisions_compression_parent_prevents_commit(self):
553
577
        repo = self.make_write_ready_repo()
554
578
        key = ('junk',)
 
579
        if not getattr(repo.inventories._index, '_missing_compression_parents',
 
580
            None):
 
581
            raise TestSkipped("No missing compression parents")
555
582
        repo.revisions._index._missing_compression_parents.add(key)
556
583
        self.assertRaises(errors.BzrCheckError, repo.commit_write_group)
557
584
        self.assertRaises(errors.BzrCheckError, repo.commit_write_group)
561
588
    def test_missing_signatures_compression_parent_prevents_commit(self):
562
589
        repo = self.make_write_ready_repo()
563
590
        key = ('junk',)
 
591
        if not getattr(repo.inventories._index, '_missing_compression_parents',
 
592
            None):
 
593
            raise TestSkipped("No missing compression parents")
564
594
        repo.signatures._index._missing_compression_parents.add(key)
565
595
        self.assertRaises(errors.BzrCheckError, repo.commit_write_group)
566
596
        self.assertRaises(errors.BzrCheckError, repo.commit_write_group)
570
600
    def test_missing_text_compression_parent_prevents_commit(self):
571
601
        repo = self.make_write_ready_repo()
572
602
        key = ('some', 'junk')
 
603
        if not getattr(repo.inventories._index, '_missing_compression_parents',
 
604
            None):
 
605
            raise TestSkipped("No missing compression parents")
573
606
        repo.texts._index._missing_compression_parents.add(key)
574
607
        self.assertRaises(errors.BzrCheckError, repo.commit_write_group)
575
608
        e = self.assertRaises(errors.BzrCheckError, repo.commit_write_group)
699
732
            # can only stack on repositories that have compatible internal
700
733
            # metadata
701
734
            if getattr(repo._format, 'supports_tree_reference', False):
702
 
                matching_format_name = 'pack-0.92-subtree'
 
735
                if repo._format.supports_chks:
 
736
                    matching_format_name = 'development6-rich-root'
 
737
                else:
 
738
                    matching_format_name = 'pack-0.92-subtree'
703
739
            else:
704
740
                matching_format_name = 'rich-root-pack'
705
741
            mismatching_format_name = 'pack-0.92'
706
742
        else:
707
 
            matching_format_name = 'pack-0.92'
 
743
            # We don't have a non-rich-root CHK format.
 
744
            if repo._format.supports_chks:
 
745
                raise AssertionError("no non-rich-root CHK formats known")
 
746
            else:
 
747
                matching_format_name = 'pack-0.92'
708
748
            mismatching_format_name = 'pack-0.92-subtree'
709
749
        base = self.make_repository('base', format=matching_format_name)
710
750
        repo.add_fallback_repository(base)
715
755
            repo.add_fallback_repository, bad_repo)
716
756
        self.assertContainsRe(str(e),
717
757
            r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
718
 
            r'KnitPackRepository.*/repo/.*\n'
 
758
            r'.*Repository.*/repo/.*\n'
719
759
            r'different rich-root support')
720
760
 
721
761
    def test_stack_checks_serializers_compatibility(self):
723
763
        if getattr(repo._format, 'supports_tree_reference', False):
724
764
            # can only stack on repositories that have compatible internal
725
765
            # metadata
726
 
            matching_format_name = 'pack-0.92-subtree'
 
766
            if repo._format.supports_chks:
 
767
                # No CHK subtree formats in bzr.dev, so this doesn't execute.
 
768
                matching_format_name = 'development6-subtree'
 
769
            else:
 
770
                matching_format_name = 'pack-0.92-subtree'
727
771
            mismatching_format_name = 'rich-root-pack'
728
772
        else:
729
773
            if repo.supports_rich_root():
741
785
            repo.add_fallback_repository, bad_repo)
742
786
        self.assertContainsRe(str(e),
743
787
            r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
744
 
            r'KnitPackRepository.*/repo/.*\n'
 
788
            r'.*Repository.*/repo/.*\n'
745
789
            r'different serializers')
746
790
 
747
791
    def test_adding_pack_does_not_record_pack_names_from_other_repositories(self):
757
801
        self.assertEqual(1, len(new_instance._pack_collection.all_packs()))
758
802
 
759
803
    def test_autopack_only_considers_main_repo_packs(self):
760
 
        base = self.make_branch_and_tree('base', format=self.get_format())
 
804
        format = self.get_format()
 
805
        base = self.make_branch_and_tree('base', format=format)
761
806
        base.commit('foo')
762
 
        tree = self.make_branch_and_tree('repo', format=self.get_format())
 
807
        tree = self.make_branch_and_tree('repo', format=format)
763
808
        tree.branch.repository.add_fallback_repository(base.branch.repository)
764
809
        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
765
810
        # This test could be a little cheaper by replacing the packs
780
825
        tree = tree.bzrdir.open_workingtree()
781
826
        check_result = tree.branch.repository.check(
782
827
            [tree.branch.last_revision()])
783
 
        # We should have 50 (10x5) files in the obsolete_packs directory.
 
828
        nb_files = 5 # .pack, .rix, .iix, .tix, .six
 
829
        if tree.branch.repository._format.supports_chks:
 
830
            nb_files += 1 # .cix
 
831
        # We should have 10 x nb_files files in the obsolete_packs directory.
784
832
        obsolete_files = list(trans.list_dir('obsolete_packs'))
785
833
        self.assertFalse('foo' in obsolete_files)
786
834
        self.assertFalse('bar' in obsolete_files)
787
 
        self.assertEqual(50, len(obsolete_files))
 
835
        self.assertEqual(10 * nb_files, len(obsolete_files))
788
836
        # XXX: Todo check packs obsoleted correctly - old packs and indices
789
837
        # in the obsolete_packs directory.
790
838
        large_pack_name = list(index.iter_all_entries())[0][1][0]
818
866
 
819
867
    def test_autopack_or_streaming_rpc_is_used_when_using_hpss(self):
820
868
        # Make local and remote repos
821
 
        tree = self.make_branch_and_tree('local', format=self.get_format())
822
 
        self.make_branch_and_tree('remote', format=self.get_format())
 
869
        format = self.get_format()
 
870
        tree = self.make_branch_and_tree('local', format=format)
 
871
        self.make_branch_and_tree('remote', format=format)
823
872
        remote_branch_url = self.smart_server.get_url() + 'remote'
824
873
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
825
874
        # Make 9 local revisions, and push them one at a time to the remote
879
928
                  "(bzr 1.9)\n",
880
929
              format_supports_external_lookups=True,
881
930
              index_class=BTreeGraphIndex),
882
 
         dict(format_name='development2',
883
 
              format_string="Bazaar development format 2 "
884
 
                  "(needs bzr.dev from before 1.8)\n",
885
 
              format_supports_external_lookups=True,
886
 
              index_class=BTreeGraphIndex),
887
 
         dict(format_name='development2-subtree',
888
 
              format_string="Bazaar development format 2 "
889
 
                  "with subtree support (needs bzr.dev from before 1.8)\n",
890
 
              format_supports_external_lookups=True,
 
931
         dict(format_name='development6-rich-root',
 
932
              format_string='Bazaar development format - group compression '
 
933
                  'and chk inventory (needs bzr.dev from 1.14)\n',
 
934
              format_supports_external_lookups=False,
891
935
              index_class=BTreeGraphIndex),
892
936
         ]
893
937
    # name of the scenario is the format name