예제 #1
0
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,)
예제 #2
0
 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