/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_repository.py

  • Committer: Andrew Bennetts
  • Date: 2008-10-27 06:14:45 UTC
  • mfrom: (3793 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3795.
  • Revision ID: andrew.bennetts@canonical.com-20081027061445-eqt9lz6uw1mbvq4g
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
also see this file.
23
23
"""
24
24
 
25
 
import md5
26
25
from stat import S_ISDIR
27
26
from StringIO import StringIO
28
27
 
33
32
                           UnsupportedFormatError,
34
33
                           )
35
34
from bzrlib import graph
 
35
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex
36
36
from bzrlib.index import GraphIndex, InMemoryGraphIndex
37
37
from bzrlib.repository import RepositoryFormat
38
38
from bzrlib.smart import server
52
52
    bzrdir,
53
53
    errors,
54
54
    inventory,
 
55
    osutils,
55
56
    progress,
56
57
    repository,
57
58
    revision as _mod_revision,
744
745
    def get_format(self):
745
746
        return bzrdir.format_registry.make_bzrdir('pack-0.92')
746
747
 
 
748
    def get_packs(self):
 
749
        format = self.get_format()
 
750
        repo = self.make_repository('.', format=format)
 
751
        return repo._pack_collection
 
752
 
747
753
    def test__max_pack_count(self):
748
754
        """The maximum pack count is a function of the number of revisions."""
749
 
        format = self.get_format()
750
 
        repo = self.make_repository('.', format=format)
751
 
        packs = repo._pack_collection
752
755
        # no revisions - one pack, so that we can have a revision free repo
753
756
        # without it blowing up
 
757
        packs = self.get_packs()
754
758
        self.assertEqual(1, packs._max_pack_count(0))
755
759
        # after that the sum of the digits, - check the first 1-9
756
760
        self.assertEqual(1, packs._max_pack_count(1))
772
776
        self.assertEqual(25, packs._max_pack_count(112894))
773
777
 
774
778
    def test_pack_distribution_zero(self):
775
 
        format = self.get_format()
776
 
        repo = self.make_repository('.', format=format)
777
 
        packs = repo._pack_collection
 
779
        packs = self.get_packs()
778
780
        self.assertEqual([0], packs.pack_distribution(0))
779
781
 
780
782
    def test_ensure_loaded_unlocked(self):
781
 
        format = self.get_format()
782
 
        repo = self.make_repository('.', format=format)
 
783
        packs = self.get_packs()
783
784
        self.assertRaises(errors.ObjectNotLocked,
784
 
                          repo._pack_collection.ensure_loaded)
 
785
                          packs.ensure_loaded)
785
786
 
786
787
    def test_pack_distribution_one_to_nine(self):
787
 
        format = self.get_format()
788
 
        repo = self.make_repository('.', format=format)
789
 
        packs = repo._pack_collection
 
788
        packs = self.get_packs()
790
789
        self.assertEqual([1],
791
790
            packs.pack_distribution(1))
792
791
        self.assertEqual([1, 1],
808
807
 
809
808
    def test_pack_distribution_stable_at_boundaries(self):
810
809
        """When there are multi-rev packs the counts are stable."""
811
 
        format = self.get_format()
812
 
        repo = self.make_repository('.', format=format)
813
 
        packs = repo._pack_collection
 
810
        packs = self.get_packs()
814
811
        # in 10s:
815
812
        self.assertEqual([10], packs.pack_distribution(10))
816
813
        self.assertEqual([10, 1], packs.pack_distribution(11))
825
822
        self.assertEqual([100, 100, 10, 1], packs.pack_distribution(211))
826
823
 
827
824
    def test_plan_pack_operations_2009_revisions_skip_all_packs(self):
828
 
        format = self.get_format()
829
 
        repo = self.make_repository('.', format=format)
830
 
        packs = repo._pack_collection
 
825
        packs = self.get_packs()
831
826
        existing_packs = [(2000, "big"), (9, "medium")]
832
827
        # rev count - 2009 -> 2x1000 + 9x1
833
828
        pack_operations = packs.plan_autopack_combinations(
835
830
        self.assertEqual([], pack_operations)
836
831
 
837
832
    def test_plan_pack_operations_2010_revisions_skip_all_packs(self):
838
 
        format = self.get_format()
839
 
        repo = self.make_repository('.', format=format)
840
 
        packs = repo._pack_collection
 
833
        packs = self.get_packs()
841
834
        existing_packs = [(2000, "big"), (9, "medium"), (1, "single")]
842
835
        # rev count - 2010 -> 2x1000 + 1x10
843
836
        pack_operations = packs.plan_autopack_combinations(
845
838
        self.assertEqual([], pack_operations)
846
839
 
847
840
    def test_plan_pack_operations_2010_combines_smallest_two(self):
848
 
        format = self.get_format()
849
 
        repo = self.make_repository('.', format=format)
850
 
        packs = repo._pack_collection
 
841
        packs = self.get_packs()
851
842
        existing_packs = [(1999, "big"), (9, "medium"), (1, "single2"),
852
843
            (1, "single1")]
853
844
        # rev count - 2010 -> 2x1000 + 1x10 (3)
854
845
        pack_operations = packs.plan_autopack_combinations(
855
846
            existing_packs, [1000, 1000, 10])
856
 
        self.assertEqual([[2, ["single2", "single1"]], [0, []]], pack_operations)
 
847
        self.assertEqual([[2, ["single2", "single1"]]], pack_operations)
 
848
 
 
849
    def test_plan_pack_operations_creates_a_single_op(self):
 
850
        packs = self.get_packs()
 
851
        existing_packs = [(50, 'a'), (40, 'b'), (30, 'c'), (10, 'd'),
 
852
                          (10, 'e'), (6, 'f'), (4, 'g')]
 
853
        # rev count 150 -> 1x100 and 5x10
 
854
        # The two size 10 packs do not need to be touched. The 50, 40, 30 would
 
855
        # be combined into a single 120 size pack, and the 6 & 4 would
 
856
        # becombined into a size 10 pack. However, if we have to rewrite them,
 
857
        # we save a pack file with no increased I/O by putting them into the
 
858
        # same file.
 
859
        distribution = packs.pack_distribution(150)
 
860
        pack_operations = packs.plan_autopack_combinations(existing_packs,
 
861
                                                           distribution)
 
862
        self.assertEqual([[130, ['a', 'b', 'c', 'f', 'g']]], pack_operations)
857
863
 
858
864
    def test_all_packs_none(self):
859
865
        format = self.get_format()
971
977
        index_transport = self.get_transport('index')
972
978
        upload_transport.mkdir('.')
973
979
        pack = pack_repo.NewPack(upload_transport, index_transport,
974
 
            pack_transport)
975
 
        self.assertIsInstance(pack.revision_index, InMemoryGraphIndex)
976
 
        self.assertIsInstance(pack.inventory_index, InMemoryGraphIndex)
977
 
        self.assertIsInstance(pack._hash, type(md5.new()))
 
980
            pack_transport, index_builder_class=BTreeBuilder,
 
981
            index_class=BTreeGraphIndex)
 
982
        self.assertIsInstance(pack.revision_index, BTreeBuilder)
 
983
        self.assertIsInstance(pack.inventory_index, BTreeBuilder)
 
984
        self.assertIsInstance(pack._hash, type(osutils.md5()))
978
985
        self.assertTrue(pack.upload_transport is upload_transport)
979
986
        self.assertTrue(pack.index_transport is index_transport)
980
987
        self.assertTrue(pack.pack_transport is pack_transport)
991
998
    # thus there are not yet any tests.
992
999
 
993
1000
 
 
1001
class TestOptimisingPacker(TestCaseWithTransport):
 
1002
    """Tests for the OptimisingPacker class."""
 
1003
 
 
1004
    def get_pack_collection(self):
 
1005
        repo = self.make_repository('.')
 
1006
        return repo._pack_collection
 
1007
 
 
1008
    def test_open_pack_will_optimise(self):
 
1009
        packer = pack_repo.OptimisingPacker(self.get_pack_collection(),
 
1010
                                            [], '.test')
 
1011
        new_pack = packer.open_pack()
 
1012
        self.assertIsInstance(new_pack, pack_repo.NewPack)
 
1013
        self.assertTrue(new_pack.revision_index._optimize_for_size)
 
1014
        self.assertTrue(new_pack.inventory_index._optimize_for_size)
 
1015
        self.assertTrue(new_pack.text_index._optimize_for_size)
 
1016
        self.assertTrue(new_pack.signature_index._optimize_for_size)
 
1017
 
 
1018
 
994
1019
class TestInterDifferingSerializer(TestCaseWithTransport):
995
1020
 
996
1021
    def test_progress_bar(self):