def testUnaryCall(self): import protoc_plugin_test_pb2 as test_pb2 # pylint: disable=g-import-not-at-top reload(test_pb2) with _CreateService(test_pb2) as (methods, stub): request = test_pb2.SimpleRequest(response_size=13) response = stub.UnaryCall(request, test_constants.LONG_TIMEOUT) expected_response = methods.UnaryCall(request, 'not a real context!') self.assertEqual(expected_response, response)
def testUnaryCallFutureFailed(self): import protoc_plugin_test_pb2 as test_pb2 # pylint: disable=g-import-not-at-top reload(test_pb2) request = test_pb2.SimpleRequest(response_size=13) with _CreateService(test_pb2) as (methods, stub): with methods.fail(): response_future = stub.UnaryCall.future( request, test_constants.LONG_TIMEOUT) self.assertIsNotNone(response_future.exception())
def testUnaryCallFutureCancelled(self): import protoc_plugin_test_pb2 as test_pb2 # pylint: disable=g-import-not-at-top reload(test_pb2) request = test_pb2.SimpleRequest(response_size=13) with _CreateService(test_pb2) as (methods, stub): with methods.pause(): response_future = stub.UnaryCall.future(request, 1) response_future.cancel() self.assertTrue(response_future.cancelled())
def testUnaryCallFutureExpired(self): import protoc_plugin_test_pb2 as test_pb2 # pylint: disable=g-import-not-at-top reload(test_pb2) with _CreateService(test_pb2) as (methods, stub): request = test_pb2.SimpleRequest(response_size=13) with methods.pause(): response_future = stub.UnaryCall.future( request, test_constants.SHORT_TIMEOUT) with self.assertRaises(face.ExpirationError): response_future.result()
def testIncompleteServicer(self): import protoc_plugin_test_pb2 as test_pb2 moves.reload_module(test_pb2) with _CreateIncompleteService(test_pb2) as (servicer, stub): request = test_pb2.SimpleRequest(response_size=13) try: response = stub.UnaryCall(request, test_constants.LONG_TIMEOUT) except face.AbortionError as error: self.assertEqual(interfaces.StatusCode.UNIMPLEMENTED, error.code)
def testUnaryCallFuture(self): import protoc_plugin_test_pb2 as test_pb2 # pylint: disable=g-import-not-at-top moves.reload_module(test_pb2) request = test_pb2.SimpleRequest(response_size=13) with _CreateService(test_pb2) as (methods, stub): # Check that the call does not block waiting for the server to respond. with methods.pause(): response_future = stub.UnaryCall.future( request, test_constants.LONG_TIMEOUT) response = response_future.result() expected_response = methods.UnaryCall(request, 'not a real RpcContext!') self.assertEqual(expected_response, response)
def testUpDown(self): import protoc_plugin_test_pb2 as test_pb2 reload(test_pb2) with _CreateService(test_pb2) as (servicer, stub): request = test_pb2.SimpleRequest(response_size=13)