コード例 #1
0
 // 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));
     }
 }
コード例 #2
0
 /// <exception cref="System.Exception"/>
 public string DoEcho(string msg)
 {
     TestProtos.EchoRequestProto req = ((TestProtos.EchoRequestProto)TestProtos.EchoRequestProto
                                        .NewBuilder().SetMessage(msg).Build());
     TestProtos.EchoResponseProto responseProto = proxy.Echo(null, req);
     return(responseProto.GetMessage());
 }
コード例 #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestExtraLongRpc()
        {
            TestProtoBufRpc.TestRpcService2 client = GetClient2();
            string shortString = StringUtils.Repeat("X", 4);

            TestProtos.EchoRequestProto echoRequest = ((TestProtos.EchoRequestProto)TestProtos.EchoRequestProto
                                                       .NewBuilder().SetMessage(shortString).Build());
            // short message goes through
            TestProtos.EchoResponseProto echoResponse = client.Echo2(null, echoRequest);
            Assert.Equal(shortString, echoResponse.GetMessage());
            string longString = StringUtils.Repeat("X", 4096);

            echoRequest = ((TestProtos.EchoRequestProto)TestProtos.EchoRequestProto.NewBuilder
                               ().SetMessage(longString).Build());
            try
            {
                echoResponse = client.Echo2(null, echoRequest);
                NUnit.Framework.Assert.Fail("expected extra-long RPC to fail");
            }
            catch (ServiceException)
            {
            }
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
 /// <exception cref="Com.Google.Protobuf.ServiceException"/>
 public virtual TestProtos.EchoResponseProto Echo2(RpcController unused, TestProtos.EchoRequestProto
                                                   request)
 {
     return((TestProtos.EchoResponseProto)TestProtos.EchoResponseProto.NewBuilder().SetMessage
                (request.GetMessage()).Build());
 }