1107
1107
self.assertFalse(isinstance(dest_repo, RemoteRepository))
1108
1108
self.assertTrue(isinstance(src_repo, RemoteRepository))
1109
1109
src_repo.copy_content_into(dest_repo)
1112
class TestRepositoryStreamKnitData(TestRemoteRepository):
1114
def make_pack_file(self, records):
1115
pack_file = StringIO()
1116
pack_writer = pack.ContainerWriter(pack_file.write)
1118
for bytes, names in records:
1119
pack_writer.add_bytes_record(bytes, names)
1124
def make_pack_stream(self, records):
1125
pack_serialiser = pack.ContainerSerialiser()
1126
yield pack_serialiser.begin()
1127
for bytes, names in records:
1128
yield pack_serialiser.bytes_record(bytes, names)
1129
yield pack_serialiser.end()
1131
def test_bad_pack_from_server(self):
1132
"""A response with invalid data (e.g. it has a record with multiple
1133
names) triggers an exception.
1135
Not all possible errors will be caught at this stage, but obviously
1136
malformed data should be.
1138
record = ('bytes', [('name1',), ('name2',)])
1139
pack_stream = self.make_pack_stream([record])
1140
responses = [(('ok',), pack_stream), ]
1141
transport_path = 'quack'
1142
repo, client = self.setup_fake_client_and_repository(
1143
responses, transport_path)
1144
search = graph.SearchResult(set(['revid']), set(), 1, set(['revid']))
1145
stream = repo.get_data_stream_for_search(search)
1146
self.assertRaises(errors.SmartProtocolError, list, stream)
1148
def test_backwards_compatibility(self):
1149
"""If the server doesn't recognise this request, fallback to VFS."""
1151
(('unknown verb', 'Repository.stream_revisions_chunked'), '')]
1152
repo, client = self.setup_fake_client_and_repository(
1154
self.mock_called = False
1155
repo._real_repository = MockRealRepository(self)
1156
search = graph.SearchResult(set(['revid']), set(), 1, set(['revid']))
1157
repo.get_data_stream_for_search(search)
1158
self.assertTrue(self.mock_called)
1159
self.failIf(client.expecting_body,
1160
"The protocol has been left in an unclean state that will cause "
1161
"TooManyConcurrentRequests errors.")
1164
class MockRealRepository(object):
1165
"""Helper class for TestRepositoryStreamKnitData.test_unknown_method."""
1167
def __init__(self, test):
1170
def get_data_stream_for_search(self, search):
1171
self.test.assertEqual(set(['revid']), search.get_keys())
1172
self.test.mock_called = True