Beispiel #1
0
 def test_mutating_stream_stream(self):
     rpc = self._real_time_server.invoke_stream_stream(
         _application_testing_common.FIRST_SERVICE_STRESTRE, (), None)
     rpc.send_request(_application_common.STREAM_STREAM_MUTATING_REQUEST)
     initial_metadata = rpc.initial_metadata()
     responses = [
         rpc.take_response()
         for _ in range(_application_common.STREAM_STREAM_MUTATING_COUNT)
     ]
     rpc.send_request(_application_common.STREAM_STREAM_MUTATING_REQUEST)
     responses.extend([
         rpc.take_response()
         for _ in range(_application_common.STREAM_STREAM_MUTATING_COUNT)
     ])
     rpc.requests_closed()
     _, _, _ = rpc.termination()
     expected_responses = (
         services_pb2.Bottom(first_bottom_field=0),
         services_pb2.Bottom(first_bottom_field=1),
         services_pb2.Bottom(first_bottom_field=0),
         services_pb2.Bottom(first_bottom_field=1),
     )
     self.assertSequenceEqual(expected_responses, responses)
Beispiel #2
0
 def StreStre(self, request_iterator, context):
     valid_requests = (_application_common.STREAM_STREAM_REQUEST,
                       _application_common.STREAM_STREAM_MUTATING_REQUEST)
     for request in request_iterator:
         if request not in valid_requests:
             context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
             context.set_details('Something is wrong with your request!')
             return
         elif not context.is_active():
             return
         elif request == _application_common.STREAM_STREAM_REQUEST:
             yield _application_common.STREAM_STREAM_RESPONSE
             yield _application_common.STREAM_STREAM_RESPONSE
         elif request == _application_common.STREAM_STREAM_MUTATING_REQUEST:
             response = services_pb2.Bottom()
             for i in range(
                     _application_common.STREAM_STREAM_MUTATING_COUNT):
                 response.first_bottom_field = i
                 yield response
"""An example gRPC Python-using application's common code elements."""

from tests.testing.proto import requests_pb2
from tests.testing.proto import services_pb2

SERVICE_NAME = 'tests_of_grpc_testing.FirstService'
UNARY_UNARY_METHOD_NAME = 'UnUn'
UNARY_STREAM_METHOD_NAME = 'UnStre'
STREAM_UNARY_METHOD_NAME = 'StreUn'
STREAM_STREAM_METHOD_NAME = 'StreStre'

UNARY_UNARY_REQUEST = requests_pb2.Up(first_up_field=2)
ERRONEOUS_UNARY_UNARY_REQUEST = requests_pb2.Up(first_up_field=3)
UNARY_UNARY_RESPONSE = services_pb2.Down(first_down_field=5)
ERRONEOUS_UNARY_UNARY_RESPONSE = services_pb2.Down(first_down_field=7)
UNARY_STREAM_REQUEST = requests_pb2.Charm(first_charm_field=11)
STREAM_UNARY_REQUEST = requests_pb2.Charm(first_charm_field=13)
STREAM_UNARY_RESPONSE = services_pb2.Strange(first_strange_field=17)
STREAM_STREAM_REQUEST = requests_pb2.Top(first_top_field=19)
STREAM_STREAM_RESPONSE = services_pb2.Bottom(first_bottom_field=23)
TWO_STREAM_STREAM_RESPONSES = (STREAM_STREAM_RESPONSE, ) * 2
ABORT_REQUEST = requests_pb2.Up(first_up_field=42)
ABORT_SUCCESS_QUERY = requests_pb2.Up(first_up_field=43)
ABORT_NO_STATUS_RESPONSE = services_pb2.Down(first_down_field=50)
ABORT_SUCCESS_RESPONSE = services_pb2.Down(first_down_field=51)
ABORT_FAILURE_RESPONSE = services_pb2.Down(first_down_field=52)
STREAM_STREAM_MUTATING_REQUEST = requests_pb2.Top(first_top_field=24601)
STREAM_STREAM_MUTATING_COUNT = 2

INFINITE_REQUEST_STREAM_TIMEOUT = 0.2