class BidirectionallyStreamingScenario(ProtoScenario): """A scenario that transmits no protocol buffers in either direction.""" _STREAM_LENGTH = 200 _REQUESTS = tuple( math_pb2.DivArgs(dividend=59 + index, divisor=7 + index) for index in range(_STREAM_LENGTH)) def __init__(self): self._lock = threading.Lock() self._responses = [] def method(self): return 'DivMany' def serialize_request(self, request): return request.SerializeToString() def deserialize_request(self, request_bytestring): return math_pb2.DivArgs.FromString(request_bytestring) def serialize_response(self, response): return response.SerializeToString() def deserialize_response(self, response_bytestring): return math_pb2.DivReply.FromString(response_bytestring) def requests(self): return self._REQUESTS def response_for_request(self, request): quotient, remainder = divmod(request.dividend, request.divisor) response = math_pb2.DivReply(quotient=quotient, remainder=remainder) with self._lock: self._responses.append(response) return response def verify_requests(self, experimental_requests): return tuple(experimental_requests) == self._REQUESTS def verify_responses(self, experimental_responses): with self._lock: return tuple(experimental_responses) == tuple(self._responses)
class BidirectionallyUnaryScenario(ProtoScenario): """A scenario that transmits no protocol buffers in either direction.""" _DIVIDEND = 59 _DIVISOR = 7 _QUOTIENT = 8 _REMAINDER = 3 _REQUEST = math_pb2.DivArgs(dividend=_DIVIDEND, divisor=_DIVISOR) _RESPONSE = math_pb2.DivReply(quotient=_QUOTIENT, remainder=_REMAINDER) def group_and_method(self): return 'math.Math', 'Div' def serialize_request(self, request): return request.SerializeToString() def deserialize_request(self, request_bytestring): return math_pb2.DivArgs.FromString(request_bytestring) def serialize_response(self, response): return response.SerializeToString() def deserialize_response(self, response_bytestring): return math_pb2.DivReply.FromString(response_bytestring) def requests(self): return [self._REQUEST] def response_for_request(self, request): return self._RESPONSE def verify_requests(self, experimental_requests): return tuple(experimental_requests) == (self._REQUEST,) def verify_responses(self, experimental_responses): return tuple(experimental_responses) == (self._RESPONSE,)