|
|
|
@ -29,28 +29,34 @@ def _implementation(descriptors_to_servicers, method_descriptor): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _unary_unary_service(request): |
|
|
|
|
|
|
|
|
|
def service(implementation, rpc, servicer_context): |
|
|
|
|
_service.unary_unary( |
|
|
|
|
implementation, rpc, request, servicer_context) |
|
|
|
|
_service.unary_unary(implementation, rpc, request, servicer_context) |
|
|
|
|
|
|
|
|
|
return service |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _unary_stream_service(request): |
|
|
|
|
|
|
|
|
|
def service(implementation, rpc, servicer_context): |
|
|
|
|
_service.unary_stream( |
|
|
|
|
implementation, rpc, request, servicer_context) |
|
|
|
|
_service.unary_stream(implementation, rpc, request, servicer_context) |
|
|
|
|
|
|
|
|
|
return service |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _stream_unary_service(handler): |
|
|
|
|
|
|
|
|
|
def service(implementation, rpc, servicer_context): |
|
|
|
|
_service.stream_unary(implementation, rpc, handler, servicer_context) |
|
|
|
|
|
|
|
|
|
return service |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _stream_stream_service(handler): |
|
|
|
|
|
|
|
|
|
def service(implementation, rpc, servicer_context): |
|
|
|
|
_service.stream_stream(implementation, rpc, handler, servicer_context) |
|
|
|
|
|
|
|
|
|
return service |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -60,11 +66,10 @@ class _Serverish(_common.Serverish): |
|
|
|
|
self._descriptors_to_servicers = descriptors_to_servicers |
|
|
|
|
self._time = time |
|
|
|
|
|
|
|
|
|
def _invoke( |
|
|
|
|
self, service_behavior, method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline): |
|
|
|
|
implementation = _implementation( |
|
|
|
|
self._descriptors_to_servicers, method_descriptor) |
|
|
|
|
def _invoke(self, service_behavior, method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline): |
|
|
|
|
implementation = _implementation(self._descriptors_to_servicers, |
|
|
|
|
method_descriptor) |
|
|
|
|
rpc = _rpc.Rpc(handler, invocation_metadata) |
|
|
|
|
if handler.add_termination_callback(rpc.extrinsic_abort): |
|
|
|
|
servicer_context = _servicer_context.ServicerContext( |
|
|
|
@ -74,28 +79,26 @@ class _Serverish(_common.Serverish): |
|
|
|
|
args=(implementation, rpc, servicer_context,)) |
|
|
|
|
service_thread.start() |
|
|
|
|
|
|
|
|
|
def invoke_unary_unary( |
|
|
|
|
self, method_descriptor, handler, invocation_metadata, request, |
|
|
|
|
deadline): |
|
|
|
|
def invoke_unary_unary(self, method_descriptor, handler, |
|
|
|
|
invocation_metadata, request, deadline): |
|
|
|
|
self._invoke( |
|
|
|
|
_unary_unary_service(request), method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline) |
|
|
|
|
|
|
|
|
|
def invoke_unary_stream( |
|
|
|
|
self, method_descriptor, handler, invocation_metadata, request, |
|
|
|
|
deadline): |
|
|
|
|
def invoke_unary_stream(self, method_descriptor, handler, |
|
|
|
|
invocation_metadata, request, deadline): |
|
|
|
|
self._invoke( |
|
|
|
|
_unary_stream_service(request), method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline) |
|
|
|
|
|
|
|
|
|
def invoke_stream_unary( |
|
|
|
|
self, method_descriptor, handler, invocation_metadata, deadline): |
|
|
|
|
def invoke_stream_unary(self, method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline): |
|
|
|
|
self._invoke( |
|
|
|
|
_stream_unary_service(handler), method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline) |
|
|
|
|
|
|
|
|
|
def invoke_stream_stream( |
|
|
|
|
self, method_descriptor, handler, invocation_metadata, deadline): |
|
|
|
|
def invoke_stream_stream(self, method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline): |
|
|
|
|
self._invoke( |
|
|
|
|
_stream_stream_service(handler), method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline) |
|
|
|
@ -106,7 +109,8 @@ def _deadline_and_handler(requests_closed, time, timeout): |
|
|
|
|
return None, _handler.handler_without_deadline(requests_closed) |
|
|
|
|
else: |
|
|
|
|
deadline = time.time() + timeout |
|
|
|
|
handler = _handler.handler_with_deadline(requests_closed, time, deadline) |
|
|
|
|
handler = _handler.handler_with_deadline(requests_closed, time, |
|
|
|
|
deadline) |
|
|
|
|
return deadline, handler |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -116,32 +120,32 @@ class _Server(grpc_testing.Server): |
|
|
|
|
self._serverish = serverish |
|
|
|
|
self._time = time |
|
|
|
|
|
|
|
|
|
def invoke_unary_unary( |
|
|
|
|
self, method_descriptor, invocation_metadata, request, timeout): |
|
|
|
|
def invoke_unary_unary(self, method_descriptor, invocation_metadata, |
|
|
|
|
request, timeout): |
|
|
|
|
deadline, handler = _deadline_and_handler(True, self._time, timeout) |
|
|
|
|
self._serverish.invoke_unary_unary( |
|
|
|
|
method_descriptor, handler, invocation_metadata, request, deadline) |
|
|
|
|
return _server_rpc.UnaryUnaryServerRpc(handler) |
|
|
|
|
|
|
|
|
|
def invoke_unary_stream( |
|
|
|
|
self, method_descriptor, invocation_metadata, request, timeout): |
|
|
|
|
def invoke_unary_stream(self, method_descriptor, invocation_metadata, |
|
|
|
|
request, timeout): |
|
|
|
|
deadline, handler = _deadline_and_handler(True, self._time, timeout) |
|
|
|
|
self._serverish.invoke_unary_stream( |
|
|
|
|
method_descriptor, handler, invocation_metadata, request, deadline) |
|
|
|
|
return _server_rpc.UnaryStreamServerRpc(handler) |
|
|
|
|
|
|
|
|
|
def invoke_stream_unary( |
|
|
|
|
self, method_descriptor, invocation_metadata, timeout): |
|
|
|
|
def invoke_stream_unary(self, method_descriptor, invocation_metadata, |
|
|
|
|
timeout): |
|
|
|
|
deadline, handler = _deadline_and_handler(False, self._time, timeout) |
|
|
|
|
self._serverish.invoke_stream_unary( |
|
|
|
|
method_descriptor, handler, invocation_metadata, deadline) |
|
|
|
|
self._serverish.invoke_stream_unary(method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline) |
|
|
|
|
return _server_rpc.StreamUnaryServerRpc(handler) |
|
|
|
|
|
|
|
|
|
def invoke_stream_stream( |
|
|
|
|
self, method_descriptor, invocation_metadata, timeout): |
|
|
|
|
def invoke_stream_stream(self, method_descriptor, invocation_metadata, |
|
|
|
|
timeout): |
|
|
|
|
deadline, handler = _deadline_and_handler(False, self._time, timeout) |
|
|
|
|
self._serverish.invoke_stream_stream( |
|
|
|
|
method_descriptor, handler, invocation_metadata, deadline) |
|
|
|
|
self._serverish.invoke_stream_stream(method_descriptor, handler, |
|
|
|
|
invocation_metadata, deadline) |
|
|
|
|
return _server_rpc.StreamStreamServerRpc(handler) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|