Beispiel #1
0
        public virtual void TestRpcMetrics()
        {
            Configuration configuration = new Configuration();
            int           interval      = 1;

            configuration.SetBoolean(CommonConfigurationKeys.RpcMetricsQuantileEnable, true);
            configuration.Set(CommonConfigurationKeys.RpcMetricsPercentilesIntervalsKey, string.Empty
                              + interval);
            Server server = new RPC.Builder(configuration).SetProtocol(typeof(TestRPC.TestProtocol
                                                                              )).SetInstance(new TestRPC.TestImpl()).SetBindAddress(Address).SetPort(0).SetNumHandlers
                                (5).SetVerbose(true).Build();

            server.Start();
            TestRPC.TestProtocol proxy = RPC.GetProxy <TestRPC.TestProtocol>(TestRPC.TestProtocol
                                                                             .versionID, server.GetListenerAddress(), configuration);
            try
            {
                for (int i = 0; i < 1000; i++)
                {
                    proxy.Ping();
                    proxy.Echo(string.Empty + i);
                }
                MetricsRecordBuilder rpcMetrics = MetricsAsserts.GetMetrics(server.GetRpcMetrics(
                                                                                ).Name());
                Assert.True("Expected non-zero rpc queue time", MetricsAsserts.GetLongCounter
                                ("RpcQueueTimeNumOps", rpcMetrics) > 0);
                Assert.True("Expected non-zero rpc processing time", MetricsAsserts.GetLongCounter
                                ("RpcProcessingTimeNumOps", rpcMetrics) > 0);
                MetricsAsserts.AssertQuantileGauges("RpcQueueTime" + interval + "s", rpcMetrics);
                MetricsAsserts.AssertQuantileGauges("RpcProcessingTime" + interval + "s", rpcMetrics
                                                    );
            }
            finally
            {
                if (proxy != null)
                {
                    RPC.StopProxy(proxy);
                }
                server.Stop();
            }
        }