def early_adopter_create_RouteGuide_server(servicer, port, root_certificates, key_chain_pairs): method_implementations = { "GetFeature": utilities.unary_unary_inline(servicer.GetFeature), "ListFeatures": utilities.unary_stream_inline(servicer.ListFeatures), "RecordRoute": utilities.stream_unary_inline(servicer.RecordRoute), "RouteChat": utilities.stream_stream_inline(servicer.RouteChat), } import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 request_deserializers = { "GetFeature": route_guide_pb2.Point.FromString, "ListFeatures": route_guide_pb2.Rectangle.FromString, "RecordRoute": route_guide_pb2.Point.FromString, "RouteChat": route_guide_pb2.RouteNote.FromString, } response_serializers = { "GetFeature": lambda x: x.SerializeToString(), "ListFeatures": lambda x: x.SerializeToString(), "RecordRoute": lambda x: x.SerializeToString(), "RouteChat": lambda x: x.SerializeToString(), } link = fore.activated_fore_link(port, request_deserializers, response_serializers, root_certificates, key_chain_pairs) return implementations.assemble_service(method_implementations, link)
def _start(self): with self._lock: if self._server is None: self._fore_link = _fore.activated_fore_link( self._port, self._breakdown.request_deserializers, self._breakdown.response_serializers, None, self._key_chain_pairs) self._server = _assembly_implementations.assemble_service( self._breakdown.implementations, self._fore_link) self._server.start() else: raise ValueError('Server currently running!')
def testStreamUnary(self): stream_length = 127 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) dynamic_stub = implementations.assemble_dynamic_inline_stub( _IMPLEMENTATIONS, pipe) with service, dynamic_stub: response_future = dynamic_stub.Sum. async ( (math_pb2.Num(num=index) for index in range(stream_length)), _TIMEOUT) self.assertEqual((stream_length * (stream_length - 1)) / 2, response_future.result().num)
def testStreamUnary(self): stream_length = 13 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) face_stub = implementations.assemble_face_stub(pipe) with service, face_stub: sync_async = face_stub.stream_unary_sync_async(SUM) response_future = sync_async. async ( (math_pb2.Num(num=index) for index in range(stream_length)), _TIMEOUT) self.assertEqual((stream_length * (stream_length - 1)) / 2, response_future.result().num)
def testUnaryStream(self): stream_length = 29 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) face_stub = implementations.assemble_face_stub(pipe) with service, face_stub: responses = list( face_stub.inline_value_in_stream_out( FIB, math_pb2.FibArgs(limit=stream_length), _TIMEOUT)) numbers = [response.num for response in responses] for early, middle, later in zip(numbers, numbers[1:], numbers[2:]): self.assertEqual(early + middle, later)
def early_adopter_create_Greeter_server(servicer, port, root_certificates, key_chain_pairs): method_implementations = { "SayHello": utilities.unary_unary_inline(servicer.SayHello), } import helloworld_pb2 request_deserializers = { "SayHello": helloworld_pb2.HelloRequest.FromString, } response_serializers = { "SayHello": lambda x: x.SerializeToString(), } link = fore.activated_fore_link(port, request_deserializers, response_serializers, root_certificates, key_chain_pairs) return implementations.assemble_service(method_implementations, link)
def testUnaryStream(self): stream_length = 43 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) dynamic_stub = implementations.assemble_dynamic_inline_stub( _IMPLEMENTATIONS, pipe) with service, dynamic_stub: response_iterator = dynamic_stub.Fib( math_pb2.FibArgs(limit=stream_length), _TIMEOUT) numbers = tuple(response.num for response in response_iterator) for early, middle, later in zip(numbers, numbers[:1], numbers[:2]): self.assertEqual(early + middle, later) self.assertEqual(stream_length, len(numbers))
def testStreamUnary(self): stream_length = 13 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) face_stub = implementations.assemble_face_stub(pipe) with service, face_stub: sync_async = face_stub.stream_unary_sync_async(SUM) response_future = sync_async.async( (math_pb2.Num(num=index) for index in range(stream_length)), _TIMEOUT) self.assertEqual( (stream_length * (stream_length - 1)) / 2, response_future.result().num)
def testStreamUnary(self): stream_length = 127 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) dynamic_stub = implementations.assemble_dynamic_inline_stub( _IMPLEMENTATIONS, pipe) with service, dynamic_stub: response_future = dynamic_stub.Sum.async( (math_pb2.Num(num=index) for index in range(stream_length)), _TIMEOUT) self.assertEqual( (stream_length * (stream_length - 1)) / 2, response_future.result().num)
def testUnaryUnary(self): divisor = 59 dividend = 973 expected_quotient = dividend / divisor expected_remainder = dividend % divisor pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) dynamic_stub = implementations.assemble_dynamic_inline_stub( _IMPLEMENTATIONS, pipe) service.start() with dynamic_stub: response = dynamic_stub.Div( math_pb2.DivArgs(divisor=divisor, dividend=dividend), _TIMEOUT) self.assertEqual(expected_quotient, response.quotient) self.assertEqual(expected_remainder, response.remainder) service.stop()
def testUnaryUnary(self): divisor = 7 dividend = 13 expected_quotient = 1 expected_remainder = 6 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) face_stub = implementations.assemble_face_stub(pipe) service.start() try: with face_stub: response = face_stub.blocking_value_in_value_out( DIV, math_pb2.DivArgs(divisor=divisor, dividend=dividend), _TIMEOUT) self.assertEqual(expected_quotient, response.quotient) self.assertEqual(expected_remainder, response.remainder) finally: service.stop()
def testStreamStream(self): stream_length = 17 divisor_offset = 7 dividend_offset = 17 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) face_stub = implementations.assemble_face_stub(pipe) with service, face_stub: response_iterator = face_stub.inline_stream_in_stream_out( DIV_MANY, (math_pb2.DivArgs(divisor=divisor_offset + index, dividend=dividend_offset + index) for index in range(stream_length)), _TIMEOUT) for index, response in enumerate(response_iterator): self.assertEqual( (dividend_offset + index) / (divisor_offset + index), response.quotient) self.assertEqual( (dividend_offset + index) % (divisor_offset + index), response.remainder) self.assertEqual(stream_length, index + 1)
def testStreamStream(self): stream_length = 179 divisor_offset = 71 dividend_offset = 1763 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) dynamic_stub = implementations.assemble_dynamic_inline_stub( _IMPLEMENTATIONS, pipe) with service, dynamic_stub: response_iterator = dynamic_stub.DivMany( (math_pb2.DivArgs(divisor=divisor_offset + index, dividend=dividend_offset + index) for index in range(stream_length)), _TIMEOUT) for index, response in enumerate(response_iterator): self.assertEqual( (dividend_offset + index) / (divisor_offset + index), response.quotient) self.assertEqual( (dividend_offset + index) % (divisor_offset + index), response.remainder) self.assertEqual(stream_length, index + 1)
def testStreamStream(self): stream_length = 179 divisor_offset = 71 dividend_offset = 1763 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) dynamic_stub = implementations.assemble_dynamic_inline_stub( _IMPLEMENTATIONS, pipe) with service, dynamic_stub: response_iterator = dynamic_stub.DivMany( (math_pb2.DivArgs( divisor=divisor_offset + index, dividend=dividend_offset + index) for index in range(stream_length)), _TIMEOUT) for index, response in enumerate(response_iterator): self.assertEqual( (dividend_offset + index) / (divisor_offset + index), response.quotient) self.assertEqual( (dividend_offset + index) % (divisor_offset + index), response.remainder) self.assertEqual(stream_length, index + 1)
def testStreamStream(self): stream_length = 17 divisor_offset = 7 dividend_offset = 17 pipe = PipeLink() service = implementations.assemble_service(_IMPLEMENTATIONS, pipe) face_stub = implementations.assemble_face_stub(pipe) with service, face_stub: response_iterator = face_stub.inline_stream_in_stream_out( DIV_MANY, (math_pb2.DivArgs( divisor=divisor_offset + index, dividend=dividend_offset + index) for index in range(stream_length)), _TIMEOUT) for index, response in enumerate(response_iterator): self.assertEqual( (dividend_offset + index) / (divisor_offset + index), response.quotient) self.assertEqual( (dividend_offset + index) % (divisor_offset + index), response.remainder) self.assertEqual(stream_length, index + 1)