~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

Split smart server VFS logic out into a new file, and start using the command pattern in the SmartServerRequestHandler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        SmartClientHTTPMediumRequest,
42
42
        SmartRequestHandler,
43
43
        )
44
 
from bzrlib.transport.smart import medium, protocol
 
44
from bzrlib.transport.smart import medium, protocol, vfs
45
45
 
46
46
 
47
47
class StringIOSSHVendor(object):
1070
1070
        self.smart_server_request = smart.SmartServerRequestHandler(None)
1071
1071
 
1072
1072
    def assertOffsetSerialisation(self, expected_offsets, expected_serialised,
1073
 
        client, smart_server_request):
 
1073
        client):
1074
1074
        """Check that smart (de)serialises offsets as expected.
1075
1075
        
1076
1076
        We check both serialisation and deserialisation at the same time
1079
1079
        
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.
1083
1082
        """
1084
 
        # XXX: 'smart_server_request' should be a SmartServerRequestProtocol in
1085
 
        # future.
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.
1130
1130
        """
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)
1139
1137
 
1140
1138
    def test_accept_bytes_of_bad_request_to_protocol(self):
1141
1139
        out_stream = StringIO()