~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_pack_repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-20 10:08:54 UTC
  • mfrom: (4002.1.14 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090220100854-p9g7snhipls2cj0z
(robertc) Add the ability to suspend and resume write groups,
        for use by smart server streaming push. (Andrew Bennetts,
        Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    bzrdir,
29
29
    errors,
30
30
    inventory,
 
31
    osutils,
31
32
    progress,
32
33
    repository,
33
34
    revision as _mod_revision,
613
614
        self.assertRaises(Exception, repo.abort_write_group)
614
615
        if token is not None:
615
616
            repo.leave_lock_in_place()
616
 
        
 
617
 
 
618
    def test_suspend_write_group(self):
 
619
        self.vfs_transport_factory = memory.MemoryServer
 
620
        repo = self.make_repository('repo')
 
621
        token = repo.lock_write()
 
622
        self.addCleanup(repo.unlock)
 
623
        repo.start_write_group()
 
624
        repo.texts.add_lines(('file-id', 'revid'), (), ['lines'])
 
625
        wg_tokens = repo.suspend_write_group()
 
626
        expected_pack_name = wg_tokens[0] + '.pack'
 
627
        upload_transport = repo._pack_collection._upload_transport
 
628
        limbo_files = upload_transport.list_dir('')
 
629
        self.assertTrue(expected_pack_name in limbo_files, limbo_files)
 
630
        md5 = osutils.md5(upload_transport.get_bytes(expected_pack_name))
 
631
        self.assertEqual(wg_tokens[0], md5.hexdigest())
 
632
 
 
633
    def test_resume_write_group_then_abort(self):
 
634
        # Create a repo, start a write group, insert some data, suspend.
 
635
        self.vfs_transport_factory = memory.MemoryServer
 
636
        repo = self.make_repository('repo')
 
637
        token = repo.lock_write()
 
638
        self.addCleanup(repo.unlock)
 
639
        repo.start_write_group()
 
640
        text_key = ('file-id', 'revid')
 
641
        repo.texts.add_lines(text_key, (), ['lines'])
 
642
        wg_tokens = repo.suspend_write_group()
 
643
        # Get a fresh repository object for the repo on the filesystem.
 
644
        same_repo = repo.bzrdir.open_repository()
 
645
        # Resume
 
646
        same_repo.lock_write()
 
647
        self.addCleanup(same_repo.unlock)
 
648
        same_repo.resume_write_group(wg_tokens)
 
649
        same_repo.abort_write_group()
 
650
        self.assertEqual(
 
651
            [], same_repo._pack_collection._upload_transport.list_dir(''))
 
652
        self.assertEqual(
 
653
            [], same_repo._pack_collection._pack_transport.list_dir(''))
 
654
 
 
655
    def test_resume_malformed_token(self):
 
656
        self.vfs_transport_factory = memory.MemoryServer
 
657
        # Make a repository with a suspended write group
 
658
        repo = self.make_repository('repo')
 
659
        token = repo.lock_write()
 
660
        self.addCleanup(repo.unlock)
 
661
        repo.start_write_group()
 
662
        text_key = ('file-id', 'revid')
 
663
        repo.texts.add_lines(text_key, (), ['lines'])
 
664
        wg_tokens = repo.suspend_write_group()
 
665
        # Make a new repository
 
666
        new_repo = self.make_repository('new_repo')
 
667
        token = new_repo.lock_write()
 
668
        self.addCleanup(new_repo.unlock)
 
669
        hacked_wg_token = (
 
670
            '../../../../repo/.bzr/repository/upload/' + wg_tokens[0])
 
671
        self.assertRaises(
 
672
            errors.UnresumableWriteGroup,
 
673
            new_repo.resume_write_group, [hacked_wg_token])
 
674
 
617
675
 
618
676
class TestPackRepositoryStacking(TestCaseWithTransport):
619
677