743
744
tarball_file.close()
745
def test_sprout_uses_tarball(self):
746
# RemoteRepository.sprout should try to use the
747
# tarball command rather than accessing all the files
748
transport_path = 'srcrepo'
749
expected_responses = [(('ok',), self.tarball_content),
751
expected_calls = [('call2', 'Repository.tarball', ('///srcrepo/', 'bz2',),),
753
remote_repo, client = self.setup_fake_client_and_repository(
754
expected_responses, transport_path)
755
# make a regular local repository to receive the results
756
dest_transport = MemoryTransport()
757
dest_transport.mkdir('destrepo')
758
bzrdir_format = bzrdir.format_registry.make_bzrdir('default')
759
dest_bzrdir = bzrdir_format.initialize_on_transport(dest_transport)
761
remote_repo.sprout(dest_bzrdir)
763
def test_backwards_compatibility(self):
764
"""If the server doesn't recognise this request, fallback to VFS.
766
This happens when a current client talks to an older server that
767
doesn't implement 'Repository.tarball'.
769
# Make a regular local repository to receive the results
770
dest_transport = MemoryTransport()
771
dest_transport.mkdir('destrepo')
772
bzrdir_format = bzrdir.format_registry.make_bzrdir('default')
773
dest_bzrdir = bzrdir_format.initialize_on_transport(dest_transport)
776
"Generic bzr smart protocol error: "
777
"bad request 'Repository.tarball'")
778
responses = [(('error', error_msg), '')]
779
remote_repo, client = self.setup_fake_client_and_repository(
781
mock_real_repo = MockRealRepository()
782
remote_repo._real_repository = mock_real_repo
785
remote_repo.sprout(dest_bzrdir)
787
self.assertEqual([('sprout', dest_bzrdir, None)], mock_real_repo.calls,
788
"RemoteRepository didn't fallback to the real repository correctly")
789
self.failIf(client.expecting_body,
790
"The protocol has been left in an unclean state that will cause "
791
"TooManyConcurrentRequests errors.")
794
class MockRealRepository(object):
795
"""Mock of a RemoteRepository's '_real_repository' attribute.
797
Used by TestRepositoryTarball.test_backwards_compatibility.
803
def sprout(self, to_bzrdir, revision_id=None):
804
self.calls.append(('sprout', to_bzrdir, revision_id))
807
747
class TestRemoteRepositoryCopyContent(tests.TestCaseWithTransport):
808
748
"""RemoteRepository.copy_content_into optimizations"""
821
761
self.assertFalse(isinstance(dest_repo, RemoteRepository))
822
762
self.assertTrue(isinstance(src_repo, RemoteRepository))
823
763
src_repo.copy_content_into(dest_repo)
766
class TestRepositoryStreamKnitData(TestRemoteRepository):
768
def make_pack_file(self, records):
769
pack_file = StringIO()
770
pack_writer = pack.ContainerWriter(pack_file.write)
772
for bytes, names in records:
773
pack_writer.add_bytes_record(bytes, names)
778
def test_bad_pack_from_server(self):
779
"""A response with invalid data (e.g. it has a record with multiple
780
names) triggers an exception.
782
Not all possible errors will be caught at this stage, but obviously
783
malformed data should be.
785
record = ('bytes', [('name1',), ('name2',)])
786
pack_file = self.make_pack_file([record])
787
responses = [(('ok',), pack_file.getvalue()), ]
788
transport_path = 'quack'
789
repo, client = self.setup_fake_client_and_repository(
790
responses, transport_path)
791
stream = repo.get_data_stream(['revid'])
792
self.assertRaises(errors.SmartProtocolError, list, stream)
794
def test_backwards_compatibility(self):
795
"""If the server doesn't recognise this request, fallback to VFS."""
797
"Generic bzr smart protocol error: "
798
"bad request 'Repository.stream_knit_data_for_revisions'")
800
(('error', error_msg), '')]
801
repo, client = self.setup_fake_client_and_repository(
803
self.mock_called = False
804
repo._real_repository = MockRealRepository(self)
805
repo.get_data_stream(['revid'])
806
self.assertTrue(self.mock_called)
807
self.failIf(client.expecting_body,
808
"The protocol has been left in an unclean state that will cause "
809
"TooManyConcurrentRequests errors.")
812
class MockRealRepository(object):
813
"""Helper class for TestRepositoryStreamKnitData.test_unknown_method."""
815
def __init__(self, test):
818
def get_data_stream(self, revision_ids):
819
self.test.assertEqual(['revid'], revision_ids)
820
self.test.mock_called = True