def testUnaryCallFutureFailed(self): service = _CreateService() request = request_pb2.SimpleRequest(response_size=13) with service.servicer_methods.fail(): response_future = service.stub.UnaryCall.future(request) self.assertIsNotNone(response_future.exception()) self.assertIs(response_future.code(), grpc.StatusCode.UNKNOWN)
def testIncompleteServicer(self): service = _CreateIncompleteService() request = request_pb2.SimpleRequest(response_size=13) with self.assertRaises(grpc.RpcError) as exception_context: service.stub.UnaryCall(request) self.assertIs(exception_context.exception.code(), grpc.StatusCode.UNIMPLEMENTED)
def testUnaryCall(self): service = _CreateService() request = request_pb2.SimpleRequest(response_size=13) response = service.stub.UnaryCall(request) expected_response = service.servicer_methods.UnaryCall( request, 'not a real context!') self.assertEqual(expected_response, response)
def testUnaryCallFutureFailed(self): with _CreateService() as (methods, stub): request = request_pb2.SimpleRequest(response_size=13) with methods.fail(): response_future = stub.UnaryCall.future( request, test_constants.LONG_TIMEOUT) self.assertIsNotNone(response_future.exception())
def testIncompleteServicer(self): with _CreateIncompleteService() as (_, stub): request = request_pb2.SimpleRequest(response_size=13) try: stub.UnaryCall(request, test_constants.LONG_TIMEOUT) except face.AbortionError as error: self.assertEqual(interfaces.StatusCode.UNIMPLEMENTED, error.code)
def testUnaryCallFutureCancelled(self): with _CreateService() as (methods, stub): request = request_pb2.SimpleRequest(response_size=13) with methods.pause(): response_future = stub.UnaryCall.future(request, 1) response_future.cancel() self.assertTrue(response_future.cancelled())
def testUnaryCallFutureCancelled(self): service = _CreateService() request = request_pb2.SimpleRequest(response_size=13) with service.servicer_methods.pause(): response_future = service.stub.UnaryCall.future(request) response_future.cancel() self.assertTrue(response_future.cancelled()) self.assertIs(response_future.code(), grpc.StatusCode.CANCELLED)
def testUnaryCallFutureExpired(self): with _CreateService() as (methods, stub): request = request_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 testUnaryCallInsecureSugar(self): request = request_pb2.SimpleRequest(response_size=13) response = service_pb2_grpc.TestService.UnaryCall(request, self._target, insecure=True, wait_for_ready=True) expected_response = self.servicer_methods.UnaryCall( request, 'not a real context!') self.assertEqual(expected_response, response)
def testUnaryCallFuture(self): service = _CreateService() request = request_pb2.SimpleRequest(response_size=13) # Check that the call does not block waiting for the server to respond. with service.servicer_methods.pause(): response_future = service.stub.UnaryCall.future(request) response = response_future.result() expected_response = service.servicer_methods.UnaryCall( request, 'not a real RpcContext!') self.assertEqual(expected_response, response)
def testUnaryCallFuture(self): with _CreateService() as (methods, stub): request = request_pb2.SimpleRequest(response_size=13) # 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 testUnaryCall(self): request = request_pb2.SimpleRequest(response_size=13) response = service_pb2_grpc.TestService.UnaryCall( request, self._target, channel_credentials=grpc.experimental.insecure_channel_credentials( ), wait_for_ready=True) expected_response = self.servicer_methods.UnaryCall( request, 'not a real context!') self.assertEqual(expected_response, response)
def testUnaryCallFutureExpired(self): service = _CreateService() request = request_pb2.SimpleRequest(response_size=13) with service.servicer_methods.pause(): response_future = service.stub.UnaryCall.future( request, timeout=test_constants.SHORT_TIMEOUT) with self.assertRaises(grpc.RpcError) as exception_context: response_future.result() self.assertIs(exception_context.exception.code(), grpc.StatusCode.DEADLINE_EXCEEDED) self.assertIs(response_future.code(), grpc.StatusCode.DEADLINE_EXCEEDED)
def testUnaryCall(self): with _CreateService() as (methods, stub): request = request_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 testUpDown(self): with _CreateService(): request_pb2.SimpleRequest(response_size=13)