| 1 |
# Copyright 2017 gRPC authors. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
import grpc |
| 16 |
from grpc_testing import _common |
| 17 |
from grpc_testing._channel import _invocation |
| 18 |
|
| 19 |
|
| 20 |
# All per-call credentials parameters are unused by this test infrastructure. |
| 21 |
# pylint: disable=unused-argument |
| 22 |
class UnaryUnary(grpc.UnaryUnaryMultiCallable): |
| 23 |
|
| 24 |
def __init__(self, method_full_rpc_name, channel_handler): |
| 25 |
self._method_full_rpc_name = method_full_rpc_name |
| 26 |
self._channel_handler = channel_handler |
| 27 |
|
| 28 |
def __call__(self, request, timeout=None, metadata=None, credentials=None): |
| 29 |
rpc_handler = self._channel_handler.invoke_rpc( |
| 30 |
self._method_full_rpc_name, _common.fuss_with_metadata(metadata), |
| 31 |
[request], True, timeout) |
| 32 |
return _invocation.blocking_unary_response(rpc_handler) |
| 33 |
|
| 34 |
def with_call(self, request, timeout=None, metadata=None, credentials=None): |
| 35 |
rpc_handler = self._channel_handler.invoke_rpc( |
| 36 |
self._method_full_rpc_name, _common.fuss_with_metadata(metadata), |
| 37 |
[request], True, timeout) |
| 38 |
return _invocation.blocking_unary_response_with_call(rpc_handler) |
| 39 |
|
| 40 |
def future(self, request, timeout=None, metadata=None, credentials=None): |
| 41 |
rpc_handler = self._channel_handler.invoke_rpc( |
| 42 |
self._method_full_rpc_name, _common.fuss_with_metadata(metadata), |
| 43 |
[request], True, timeout) |
| 44 |
return _invocation.future_call(rpc_handler) |
| 45 |
|
| 46 |
|
| 47 |
class UnaryStream(grpc.StreamStreamMultiCallable): |
| 48 |
|
| 49 |
def __init__(self, method_full_rpc_name, channel_handler): |
| 50 |
self._method_full_rpc_name = method_full_rpc_name |
| 51 |
self._channel_handler = channel_handler |
| 52 |
|
| 53 |
def __call__(self, request, timeout=None, metadata=None, credentials=None): |
| 54 |
rpc_handler = self._channel_handler.invoke_rpc( |
| 55 |
self._method_full_rpc_name, _common.fuss_with_metadata(metadata), |
| 56 |
[request], True, timeout) |
| 57 |
return _invocation.ResponseIteratorCall(rpc_handler) |
| 58 |
|
| 59 |
|
| 60 |
class StreamUnary(grpc.StreamUnaryMultiCallable): |
| 61 |
|
| 62 |
def __init__(self, method_full_rpc_name, channel_handler): |
| 63 |
self._method_full_rpc_name = method_full_rpc_name |
| 64 |
self._channel_handler = channel_handler |
| 65 |
|
| 66 |
def __call__(self, |
| 67 |
request_iterator, |
| 68 |
timeout=None, |
| 69 |
metadata=None, |
| 70 |
credentials=None): |
| 71 |
rpc_handler = self._channel_handler.invoke_rpc( |
| 72 |
self._method_full_rpc_name, _common.fuss_with_metadata(metadata), |
| 73 |
[], False, timeout) |
| 74 |
_invocation.consume_requests(request_iterator, rpc_handler) |
| 75 |
return _invocation.blocking_unary_response(rpc_handler) |
| 76 |
|
| 77 |
def with_call(self, |
| 78 |
request_iterator, |
| 79 |
timeout=None, |
| 80 |
metadata=None, |
| 81 |
credentials=None): |
| 82 |
rpc_handler = self._channel_handler.invoke_rpc( |
| 83 |
self._method_full_rpc_name, _common.fuss_with_metadata(metadata), |
| 84 |
[], False, timeout) |
| 85 |
_invocation.consume_requests(request_iterator, rpc_handler) |
| 86 |
return _invocation.blocking_unary_response_with_call(rpc_handler) |
| 87 |
|
| 88 |
def future(self, |
| 89 |
request_iterator, |
| 90 |
timeout=None, |
| 91 |
metadata=None, |
| 92 |
credentials=None): |
| 93 |
rpc_handler = self._channel_handler.invoke_rpc( |
| 94 |
self._method_full_rpc_name, _common.fuss_with_metadata(metadata), |
| 95 |
[], False, timeout) |
| 96 |
_invocation.consume_requests(request_iterator, rpc_handler) |
| 97 |
return _invocation.future_call(rpc_handler) |
| 98 |
|
| 99 |
|
| 100 |
class StreamStream(grpc.StreamStreamMultiCallable): |
| 101 |
|
| 102 |
def __init__(self, method_full_rpc_name, channel_handler): |
| 103 |
self._method_full_rpc_name = method_full_rpc_name |
| 104 |
self._channel_handler = channel_handler |
| 105 |
|
| 106 |
def __call__(self, |
| 107 |
request_iterator, |
| 108 |
timeout=None, |
| 109 |
metadata=None, |
| 110 |
credentials=None): |
| 111 |
rpc_handler = self._channel_handler.invoke_rpc( |
| 112 |
self._method_full_rpc_name, _common.fuss_with_metadata(metadata), |
| 113 |
[], False, timeout) |
| 114 |
_invocation.consume_requests(request_iterator, rpc_handler) |
| 115 |
return _invocation.ResponseIteratorCall(rpc_handler) |
| 116 |
|
| 117 |
|
| 118 |
# pylint: enable=unused-argument |