~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

Merge with annotate

Show diffs side-by-side

added added

removed removed

Lines of Context:
641
641
            def set_last_revision_info(self, revno, revision_id):
642
642
                self.calls.append(
643
643
                    ('set_last_revision_info', revno, revision_id))
 
644
            def _clear_cached_state(self):
 
645
                pass
644
646
        real_branch = StubRealBranch()
645
647
        branch._real_branch = real_branch
646
648
        self.lock_remote_branch(branch)
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)
1183
 
 
1184
 
 
1185
 
class TestRepositoryStreamKnitData(TestRemoteRepository):
1186
 
 
1187
 
    def make_pack_file(self, records):
1188
 
        pack_file = StringIO()
1189
 
        pack_writer = pack.ContainerWriter(pack_file.write)
1190
 
        pack_writer.begin()
1191
 
        for bytes, names in records:
1192
 
            pack_writer.add_bytes_record(bytes, names)
1193
 
        pack_writer.end()
1194
 
        pack_file.seek(0)
1195
 
        return pack_file
1196
 
 
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()
1203
 
 
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.
1207
 
        
1208
 
        Not all possible errors will be caught at this stage, but obviously
1209
 
        malformed data should be.
1210
 
        """
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)
1219
 
    
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.")
1233
 
 
1234
 
 
1235
 
class MockRealRepository(object):
1236
 
    """Helper class for TestRepositoryStreamKnitData.test_unknown_method."""
1237
 
 
1238
 
    def __init__(self, test):
1239
 
        self.test = test
1240
 
 
1241
 
    def get_data_stream_for_search(self, search):
1242
 
        self.test.assertEqual(set(['revid']), search.get_keys())
1243
 
        self.test.mock_called = True
1244
 
 
1245