~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Mark Hammond
  • Date: 2008-12-28 05:21:23 UTC
  • mfrom: (3920 +trunk)
  • mto: (3932.1.1 prepare-1.11)
  • mto: This revision was merged to the branch mainline in revision 3937.
  • Revision ID: mhammond@skippinet.com.au-20081228052123-f78xs5sbdkotshwf
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
758
758
        repo = self.make_repository('.', format=format)
759
759
        return repo._pack_collection
760
760
 
 
761
    def make_packs_and_alt_repo(self, write_lock=False):
 
762
        """Create a pack repo with 3 packs, and access it via a second repo."""
 
763
        tree = self.make_branch_and_tree('.')
 
764
        tree.lock_write()
 
765
        self.addCleanup(tree.unlock)
 
766
        rev1 = tree.commit('one')
 
767
        rev2 = tree.commit('two')
 
768
        rev3 = tree.commit('three')
 
769
        r = repository.Repository.open('.')
 
770
        if write_lock:
 
771
            r.lock_write()
 
772
        else:
 
773
            r.lock_read()
 
774
        self.addCleanup(r.unlock)
 
775
        packs = r._pack_collection
 
776
        packs.ensure_loaded()
 
777
        return tree, r, packs, [rev1, rev2, rev3]
 
778
 
761
779
    def test__max_pack_count(self):
762
780
        """The maximum pack count is a function of the number of revisions."""
763
781
        # no revisions - one pack, so that we can have a revision free repo
926
944
        self.assertTrue(pack_1 is packs.get_pack_by_name(name))
927
945
 
928
946
    def test_reload_pack_names_new_entry(self):
929
 
        tree = self.make_branch_and_tree('.')
930
 
        tree.lock_write()
931
 
        self.addCleanup(tree.unlock)
932
 
        rev1 = tree.commit('one')
933
 
        rev2 = tree.commit('two')
934
 
        r = repository.Repository.open('.')
935
 
        r.lock_read()
936
 
        self.addCleanup(r.unlock)
937
 
        packs = r._pack_collection
938
 
        packs.ensure_loaded()
 
947
        tree, r, packs, revs = self.make_packs_and_alt_repo()
939
948
        names = packs.names()
940
949
        # Add a new pack file into the repository
941
 
        rev3 = tree.commit('three')
 
950
        rev4 = tree.commit('four')
942
951
        new_names = tree.branch.repository._pack_collection.names()
943
952
        new_name = set(new_names).difference(names)
944
953
        self.assertEqual(1, len(new_name))
948
957
        self.assertTrue(packs.reload_pack_names())
949
958
        self.assertEqual(new_names, packs.names())
950
959
        # And the repository can access the new revision
951
 
        self.assertEqual({rev3:(rev2,)}, r.get_parent_map([rev3]))
 
960
        self.assertEqual({rev4:(revs[-1],)}, r.get_parent_map([rev4]))
952
961
        self.assertFalse(packs.reload_pack_names())
953
962
 
954
963
    def test_reload_pack_names_added_and_removed(self):
955
 
        tree = self.make_branch_and_tree('.')
956
 
        tree.lock_write()
957
 
        self.addCleanup(tree.unlock)
958
 
        rev1 = tree.commit('one')
959
 
        rev2 = tree.commit('two')
960
 
        r = repository.Repository.open('.')
961
 
        r.lock_read()
962
 
        self.addCleanup(r.unlock)
963
 
        packs = r._pack_collection
964
 
        packs.ensure_loaded()
 
964
        tree, r, packs, revs = self.make_packs_and_alt_repo()
965
965
        names = packs.names()
966
966
        # Now repack the whole thing
967
967
        tree.branch.repository.pack()
970
970
        self.assertEqual(names, packs.names())
971
971
        self.assertTrue(packs.reload_pack_names())
972
972
        self.assertEqual(new_names, packs.names())
973
 
        self.assertEqual({rev2:(rev1,)}, r.get_parent_map([rev2]))
 
973
        self.assertEqual({revs[-1]:(revs[-2],)}, r.get_parent_map([revs[-1]]))
974
974
        self.assertFalse(packs.reload_pack_names())
975
975
 
 
976
    def test_autopack_reloads_and_stops(self):
 
977
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
978
        # After we have determined what needs to be autopacked, trigger a
 
979
        # full-pack via the other repo which will cause us to re-evaluate and
 
980
        # decide we don't need to do anything
 
981
        orig_execute = packs._execute_pack_operations
 
982
        def _munged_execute_pack_ops(*args, **kwargs):
 
983
            tree.branch.repository.pack()
 
984
            return orig_execute(*args, **kwargs)
 
985
        packs._execute_pack_operations = _munged_execute_pack_ops
 
986
        packs._max_pack_count = lambda x: 1
 
987
        packs.pack_distribution = lambda x: [10]
 
988
        self.assertFalse(packs.autopack())
 
989
        self.assertEqual(1, len(packs.names()))
 
990
        self.assertEqual(tree.branch.repository._pack_collection.names(),
 
991
                         packs.names())
 
992
 
976
993
 
977
994
class TestPack(TestCaseWithTransport):
978
995
    """Tests for the Pack object."""