1180
1182
self.assertFalse(isinstance(dest_repo, RemoteRepository))
1181
1183
self.assertTrue(isinstance(src_repo, RemoteRepository))
1182
1184
src_repo.copy_content_into(dest_repo)
1185
class TestRepositoryStreamKnitData(TestRemoteRepository):
1187
def make_pack_file(self, records):
1188
pack_file = StringIO()
1189
pack_writer = pack.ContainerWriter(pack_file.write)
1191
for bytes, names in records:
1192
pack_writer.add_bytes_record(bytes, names)
1197
def make_pack_stream(self, records):
1198
pack_serialiser = pack.ContainerSerialiser()
1199
yield pack_serialiser.begin()
1200
for bytes, names in records:
1201
yield pack_serialiser.bytes_record(bytes, names)
1202
yield pack_serialiser.end()
1204
def test_bad_pack_from_server(self):
1205
"""A response with invalid data (e.g. it has a record with multiple
1206
names) triggers an exception.
1208
Not all possible errors will be caught at this stage, but obviously
1209
malformed data should be.
1211
record = ('bytes', [('name1',), ('name2',)])
1212
pack_stream = self.make_pack_stream([record])
1213
transport_path = 'quack'
1214
repo, client = self.setup_fake_client_and_repository(transport_path)
1215
client.add_success_response_with_body(pack_stream, 'ok')
1216
search = graph.SearchResult(set(['revid']), set(), 1, set(['revid']))
1217
stream = repo.get_data_stream_for_search(search)
1218
self.assertRaises(errors.SmartProtocolError, list, stream)
1220
def test_backwards_compatibility(self):
1221
"""If the server doesn't recognise this request, fallback to VFS."""
1222
repo, client = self.setup_fake_client_and_repository('path')
1223
client.add_unknown_method_response(
1224
'Repository.stream_revisions_chunked')
1225
self.mock_called = False
1226
repo._real_repository = MockRealRepository(self)
1227
search = graph.SearchResult(set(['revid']), set(), 1, set(['revid']))
1228
repo.get_data_stream_for_search(search)
1229
self.assertTrue(self.mock_called)
1230
self.failIf(client.expecting_body,
1231
"The protocol has been left in an unclean state that will cause "
1232
"TooManyConcurrentRequests errors.")
1235
class MockRealRepository(object):
1236
"""Helper class for TestRepositoryStreamKnitData.test_unknown_method."""
1238
def __init__(self, test):
1241
def get_data_stream_for_search(self, search):
1242
self.test.assertEqual(set(['revid']), search.get_keys())
1243
self.test.mock_called = True