// separated test out so that other tests can call it. /// <exception cref="System.Exception"/> public static void TestProtoBufRpc(TestProtoBufRpc.TestRpcService client) { // Test ping method TestProtos.EmptyRequestProto emptyRequest = ((TestProtos.EmptyRequestProto)TestProtos.EmptyRequestProto .NewBuilder().Build()); client.Ping(null, emptyRequest); // Test echo method TestProtos.EchoRequestProto echoRequest = ((TestProtos.EchoRequestProto)TestProtos.EchoRequestProto .NewBuilder().SetMessage("hello").Build()); TestProtos.EchoResponseProto echoResponse = client.Echo(null, echoRequest); Assert.Equal(echoResponse.GetMessage(), "hello"); // Test error method - error should be thrown as RemoteException try { client.Error(null, emptyRequest); NUnit.Framework.Assert.Fail("Expected exception is not thrown"); } catch (ServiceException e) { RemoteException re = (RemoteException)e.InnerException; RpcServerException rse = (RpcServerException)re.UnwrapRemoteException(typeof(RpcServerException )); NUnit.Framework.Assert.IsNotNull(rse); Assert.True(re.GetErrorCode().Equals(RpcHeaderProtos.RpcResponseHeaderProto.RpcErrorCodeProto .ErrorRpcServer)); } }
/// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual TestProtos.EmptyResponseProto Ping(RpcController unused, TestProtos.EmptyRequestProto request) { // Ensure clientId is received byte[] clientId = Server.GetClientId(); NUnit.Framework.Assert.IsNotNull(Server.GetClientId()); Assert.Equal(16, clientId.Length); return((TestProtos.EmptyResponseProto)TestProtos.EmptyResponseProto.NewBuilder() .Build()); }
/// <exception cref="System.Exception"/> public virtual void TestProtoBufRandomException() { TestProtoBufRpc.TestRpcService client = GetClient(); TestProtos.EmptyRequestProto emptyRequest = ((TestProtos.EmptyRequestProto)TestProtos.EmptyRequestProto .NewBuilder().Build()); try { client.Error2(null, emptyRequest); } catch (ServiceException se) { Assert.True(se.InnerException is RemoteException); RemoteException re = (RemoteException)se.InnerException; Assert.True(re.GetClassName().Equals(typeof(URISyntaxException) .FullName)); Assert.True(re.Message.Contains("testException")); Assert.True(re.GetErrorCode().Equals(RpcHeaderProtos.RpcResponseHeaderProto.RpcErrorCodeProto .ErrorApplication)); } }
/// <exception cref="System.Exception"/> public virtual void TestProtoBufRpc2() { TestProtoBufRpc.TestRpcService2 client = GetClient2(); // Test ping method TestProtos.EmptyRequestProto emptyRequest = ((TestProtos.EmptyRequestProto)TestProtos.EmptyRequestProto .NewBuilder().Build()); client.Ping2(null, emptyRequest); // Test echo method TestProtos.EchoRequestProto echoRequest = ((TestProtos.EchoRequestProto)TestProtos.EchoRequestProto .NewBuilder().SetMessage("hello").Build()); TestProtos.EchoResponseProto echoResponse = client.Echo2(null, echoRequest); Assert.Equal(echoResponse.GetMessage(), "hello"); // Ensure RPC metrics are updated MetricsRecordBuilder rpcMetrics = MetricsAsserts.GetMetrics(server.GetRpcMetrics( ).Name()); MetricsAsserts.AssertCounterGt("RpcQueueTimeNumOps", 0L, rpcMetrics); MetricsAsserts.AssertCounterGt("RpcProcessingTimeNumOps", 0L, rpcMetrics); MetricsRecordBuilder rpcDetailedMetrics = MetricsAsserts.GetMetrics(server.GetRpcDetailedMetrics ().Name()); MetricsAsserts.AssertCounterGt("Echo2NumOps", 0L, rpcDetailedMetrics); }
/// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual TestProtos.EmptyResponseProto Ping2(RpcController unused, TestProtos.EmptyRequestProto request) { return((TestProtos.EmptyResponseProto)TestProtos.EmptyResponseProto.NewBuilder() .Build()); }
/// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual TestProtos.EmptyResponseProto Error2(RpcController unused, TestProtos.EmptyRequestProto request) { throw new ServiceException("error", new URISyntaxException(string.Empty, "testException" )); }
/// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual TestProtos.EmptyResponseProto Error(RpcController unused, TestProtos.EmptyRequestProto request) { throw new ServiceException("error", new RpcServerException("error")); }