41
41
SmartClientHTTPMediumRequest,
42
42
SmartRequestHandler,
44
from bzrlib.transport.smart import medium, protocol
44
from bzrlib.transport.smart import medium, protocol, vfs
47
47
class StringIOSSHVendor(object):
1070
1070
self.smart_server_request = smart.SmartServerRequestHandler(None)
1072
1072
def assertOffsetSerialisation(self, expected_offsets, expected_serialised,
1073
client, smart_server_request):
1074
1074
"""Check that smart (de)serialises offsets as expected.
1076
1076
We check both serialisation and deserialisation at the same time
1080
1080
:param expected_offsets: a readv offset list.
1081
1081
:param expected_seralised: an expected serial form of the offsets.
1082
:param smart_server_request: a SmartServerRequestHandler instance.
1084
# XXX: 'smart_server_request' should be a SmartServerRequestProtocol in
1086
offsets = smart_server_request._deserialise_offsets(expected_serialised)
1083
# XXX: '_deserialise_offsets' should be a method of the
1084
# SmartServerRequestProtocol in future.
1085
readv_cmd = vfs.ReadvCommand(None)
1086
offsets = readv_cmd._deserialise_offsets(expected_serialised)
1087
1087
self.assertEqual(expected_offsets, offsets)
1088
1088
serialised = client._serialise_offsets(offsets)
1089
1089
self.assertEqual(expected_serialised, serialised)
1128
1128
one with the order of reads not increasing (an out of order read), and
1129
1129
one that should coalesce.
1131
self.assertOffsetSerialisation([], '',
1132
self.client_protocol, self.smart_server_request)
1133
self.assertOffsetSerialisation([(1,2)], '1,2',
1134
self.client_protocol, self.smart_server_request)
1131
self.assertOffsetSerialisation([], '', self.client_protocol)
1132
self.assertOffsetSerialisation([(1,2)], '1,2', self.client_protocol)
1135
1133
self.assertOffsetSerialisation([(10,40), (0,5)], '10,40\n0,5',
1136
self.client_protocol, self.smart_server_request)
1134
self.client_protocol)
1137
1135
self.assertOffsetSerialisation([(1,2), (3,4), (100, 200)],
1138
'1,2\n3,4\n100,200', self.client_protocol, self.smart_server_request)
1136
'1,2\n3,4\n100,200', self.client_protocol)
1140
1138
def test_accept_bytes_of_bad_request_to_protocol(self):
1141
1139
out_stream = StringIO()