744
744
def get_format(self):
745
745
return bzrdir.format_registry.make_bzrdir('pack-0.92')
748
format = self.get_format()
749
repo = self.make_repository('.', format=format)
750
return repo._pack_collection
747
752
def test__max_pack_count(self):
748
753
"""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
754
# no revisions - one pack, so that we can have a revision free repo
753
755
# without it blowing up
756
packs = self.get_packs()
754
757
self.assertEqual(1, packs._max_pack_count(0))
755
758
# after that the sum of the digits, - check the first 1-9
756
759
self.assertEqual(1, packs._max_pack_count(1))
772
775
self.assertEqual(25, packs._max_pack_count(112894))
774
777
def test_pack_distribution_zero(self):
775
format = self.get_format()
776
repo = self.make_repository('.', format=format)
777
packs = repo._pack_collection
778
packs = self.get_packs()
778
779
self.assertEqual([0], packs.pack_distribution(0))
780
781
def test_ensure_loaded_unlocked(self):
781
format = self.get_format()
782
repo = self.make_repository('.', format=format)
782
packs = self.get_packs()
783
783
self.assertRaises(errors.ObjectNotLocked,
784
repo._pack_collection.ensure_loaded)
786
786
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
787
packs = self.get_packs()
790
788
self.assertEqual([1],
791
789
packs.pack_distribution(1))
792
790
self.assertEqual([1, 1],
809
807
def test_pack_distribution_stable_at_boundaries(self):
810
808
"""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
809
packs = self.get_packs()
815
811
self.assertEqual([10], packs.pack_distribution(10))
816
812
self.assertEqual([10, 1], packs.pack_distribution(11))
825
821
self.assertEqual([100, 100, 10, 1], packs.pack_distribution(211))
827
823
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
824
packs = self.get_packs()
831
825
existing_packs = [(2000, "big"), (9, "medium")]
832
826
# rev count - 2009 -> 2x1000 + 9x1
833
827
pack_operations = packs.plan_autopack_combinations(
835
829
self.assertEqual([], pack_operations)
837
831
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
832
packs = self.get_packs()
841
833
existing_packs = [(2000, "big"), (9, "medium"), (1, "single")]
842
834
# rev count - 2010 -> 2x1000 + 1x10
843
835
pack_operations = packs.plan_autopack_combinations(
845
837
self.assertEqual([], pack_operations)
847
839
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
840
packs = self.get_packs()
851
841
existing_packs = [(1999, "big"), (9, "medium"), (1, "single2"),
853
843
# rev count - 2010 -> 2x1000 + 1x10 (3)
854
844
pack_operations = packs.plan_autopack_combinations(
855
845
existing_packs, [1000, 1000, 10])
856
self.assertEqual([[2, ["single2", "single1"]], [0, []]], pack_operations)
846
self.assertEqual([[2, ["single2", "single1"]]], pack_operations)
848
def test_plan_pack_operations_creates_a_single_op(self):
849
packs = self.get_packs()
850
existing_packs = [(50, 'a'), (40, 'b'), (30, 'c'), (10, 'd'),
851
(10, 'e'), (6, 'f'), (4, 'g')]
852
# rev count 150 -> 1x100 and 5x10
853
# The two size 10 packs do not need to be touched. The 50, 40, 30 would
854
# be combined into a single 120 size pack, and the 6 & 4 would
855
# becombined into a size 10 pack. However, if we have to rewrite them,
856
# we save a pack file with no increased I/O by putting them into the
858
distribution = packs.pack_distribution(150)
859
pack_operations = packs.plan_autopack_combinations(existing_packs,
861
self.assertEqual([[130, ['a', 'b', 'c', 'f', 'g']]], pack_operations)
858
863
def test_all_packs_none(self):
859
864
format = self.get_format()