24 _SERIALIZE_REQUEST =
lambda bytestring: bytestring * 2
25 _DESERIALIZE_REQUEST =
lambda bytestring: bytestring[
len(bytestring) // 2:]
26 _SERIALIZE_RESPONSE =
lambda bytestring: bytestring * 3
27 _DESERIALIZE_RESPONSE =
lambda bytestring: bytestring[:
len(bytestring) // 3]
29 _UNARY_UNARY =
'/test/UnaryUnary'
30 _UNARY_STREAM =
'/test/UnaryStream'
31 _STREAM_UNARY =
'/test/StreamUnary'
32 _STREAM_STREAM =
'/test/StreamStream'
33 _DEFECTIVE_GENERIC_RPC_HANDLER =
'/test/DefectiveGenericRpcHandler'
43 if servicer_context
is not None:
44 servicer_context.set_trailing_metadata(((
51 for _
in range(test_constants.STREAM_LENGTH):
55 if servicer_context
is not None:
56 servicer_context.set_trailing_metadata(((
62 if servicer_context
is not None:
63 servicer_context.invocation_metadata()
65 response_elements = []
66 for request
in request_iterator:
68 response_elements.append(request)
70 if servicer_context
is not None:
71 servicer_context.set_trailing_metadata(((
75 return b
''.join(response_elements)
79 if servicer_context
is not None:
80 servicer_context.set_trailing_metadata(((
84 for request
in request_iterator:
90 raise test_control.Defect()
95 def __init__(self, request_streaming, response_streaming,
96 request_deserializer, response_serializer, unary_unary,
97 unary_stream, stream_unary, stream_stream):
114 if handler_call_details.method == _UNARY_UNARY:
116 self.
_handler.handle_unary_unary,
None,
None,
118 elif handler_call_details.method == _UNARY_STREAM:
120 _SERIALIZE_RESPONSE,
None,
121 self.
_handler.handle_unary_stream,
None,
None)
122 elif handler_call_details.method == _STREAM_UNARY:
124 _SERIALIZE_RESPONSE,
None,
None,
125 self.
_handler.handle_stream_unary,
None)
126 elif handler_call_details.method == _STREAM_STREAM:
129 elif handler_call_details.method == _DEFECTIVE_GENERIC_RPC_HANDLER:
130 return self.
_handler.defective_generic_rpc_handler()
147 raise test_control.Defect()
156 return channel.unary_unary(_UNARY_UNARY)
160 return channel.unary_stream(_UNARY_STREAM,
161 request_serializer=_SERIALIZE_REQUEST,
162 response_deserializer=_DESERIALIZE_RESPONSE)
166 return channel.stream_unary(_STREAM_UNARY,
167 request_serializer=_SERIALIZE_REQUEST,
168 response_deserializer=_DESERIALIZE_RESPONSE)
172 return channel.stream_stream(_STREAM_STREAM)
176 return channel.unary_unary(_DEFECTIVE_GENERIC_RPC_HANDLER)
180 """Tests the handling of exception-raising user code on the client-side."""
187 port = self.
_server.add_insecure_port(
'[::]:0')
205 'IterableStreamRequestBlockingUnaryResponse'),))
207 self.assertIs(grpc.StatusCode.UNKNOWN,
208 exception_context.exception.code())
213 response_future = multi_callable.future(
215 metadata=((
'test',
'IterableStreamRequestFutureUnaryResponse'),))
218 response_future.result()
220 self.assertIs(grpc.StatusCode.UNKNOWN,
221 exception_context.exception.code())
228 metadata=((
'test',
'IterableStreamRequestStreamResponse'),))
231 next(response_iterator)
233 self.assertIs(grpc.StatusCode.UNKNOWN,
234 exception_context.exception.code())
238 test_constants.STREAM_LENGTH // 2, b
'\x07\x08')
242 metadata=((
'test',
'IteratorStreamRequestStreamResponse'),))
245 for _
in range(test_constants.STREAM_LENGTH // 2 + 1):
246 next(response_iterator)
248 self.assertIs(grpc.StatusCode.UNKNOWN,
249 exception_context.exception.code())
252 request = b
'\x07\x08'
258 'DefectiveGenericRpcHandlerUnary'),))
260 self.assertIs(grpc.StatusCode.UNKNOWN,
261 exception_context.exception.code())
264 if __name__ ==
'__main__':
265 logging.basicConfig()
266 unittest.main(verbosity=2)