613
614
self.assertRaises(Exception, repo.abort_write_group)
614
615
if token is not None:
615
616
repo.leave_lock_in_place()
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())
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()
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()
651
[], same_repo._pack_collection._upload_transport.list_dir(''))
653
[], same_repo._pack_collection._pack_transport.list_dir(''))
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)
670
'../../../../repo/.bzr/repository/upload/' + wg_tokens[0])
672
errors.UnresumableWriteGroup,
673
new_repo.resume_write_group, [hacked_wg_token])
618
676
class TestPackRepositoryStacking(TestCaseWithTransport):