Beispiel #1
0
        /// <exception cref="System.Exception"/>
        private static void VerifyGroupMetrics(long groups)
        {
            MetricsRecordBuilder rb = MetricsAsserts.GetMetrics("UgiMetrics");

            if (groups > 0)
            {
                MetricsAsserts.AssertCounterGt("GetGroupsNumOps", groups - 1, rb);
                double avg = MetricsAsserts.GetDoubleGauge("GetGroupsAvgTime", rb);
                Assert.True(avg >= 0.0);
                // Sleep for an interval+slop to let the percentiles rollover
                Thread.Sleep((PercentilesInterval + 1) * 1000);
                // Check that the percentiles were updated
                MetricsAsserts.AssertQuantileGauges("GetGroups1s", rb);
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
        /// <exception cref="System.IO.IOException"/>
        private void TestCallsInternal(Configuration conf)
        {
            Server server = new RPC.Builder(conf).SetProtocol(typeof(TestRPC.TestProtocol)).SetInstance
                                (new TestRPC.TestImpl()).SetBindAddress(Address).SetPort(0).Build();

            TestRPC.TestProtocol proxy = null;
            try
            {
                server.Start();
                IPEndPoint addr = NetUtils.GetConnectAddress(server);
                proxy = RPC.GetProxy <TestRPC.TestProtocol>(TestRPC.TestProtocol.versionID, addr,
                                                            conf);
                proxy.Ping();
                string stringResult = proxy.Echo("foo");
                Assert.Equal(stringResult, "foo");
                stringResult = proxy.Echo((string)null);
                Assert.Equal(stringResult, null);
                // Check rpcMetrics
                MetricsRecordBuilder rb = MetricsAsserts.GetMetrics(server.rpcMetrics.Name());
                MetricsAsserts.AssertCounter("RpcProcessingTimeNumOps", 3L, rb);
                MetricsAsserts.AssertCounterGt("SentBytes", 0L, rb);
                MetricsAsserts.AssertCounterGt("ReceivedBytes", 0L, rb);
                // Number of calls to echo method should be 2
                rb = MetricsAsserts.GetMetrics(server.rpcDetailedMetrics.Name());
                MetricsAsserts.AssertCounter("EchoNumOps", 2L, rb);
                // Number of calls to ping method should be 1
                MetricsAsserts.AssertCounter("PingNumOps", 1L, rb);
                string[] stringResults = proxy.Echo(new string[] { "foo", "bar" });
                Assert.True(Arrays.Equals(stringResults, new string[] { "foo",
                                                                        "bar" }));
                stringResults = proxy.Echo((string[])null);
                Assert.True(Arrays.Equals(stringResults, null));
                UTF8 utf8Result = (UTF8)proxy.Echo(new UTF8("hello world"));
                Assert.Equal(new UTF8("hello world"), utf8Result);
                utf8Result = (UTF8)proxy.Echo((UTF8)null);
                Assert.Equal(null, utf8Result);
                int intResult = proxy.Add(1, 2);
                Assert.Equal(intResult, 3);
                intResult = proxy.Add(new int[] { 1, 2 });
                Assert.Equal(intResult, 3);
                // Test protobufs
                DescriptorProtos.EnumDescriptorProto sendProto = ((DescriptorProtos.EnumDescriptorProto
                                                                   )DescriptorProtos.EnumDescriptorProto.NewBuilder().SetName("test").Build());
                DescriptorProtos.EnumDescriptorProto retProto = proxy.ExchangeProto(sendProto);
                Assert.Equal(sendProto, retProto);
                NUnit.Framework.Assert.AreNotSame(sendProto, retProto);
                bool caught = false;
                try
                {
                    proxy.Error();
                }
                catch (IOException e)
                {
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Caught " + e);
                    }
                    caught = true;
                }
                Assert.True(caught);
                rb = MetricsAsserts.GetMetrics(server.rpcDetailedMetrics.Name());
                MetricsAsserts.AssertCounter("IOExceptionNumOps", 1L, rb);
                proxy.TestServerGet();
                // create multiple threads and make them do large data transfers
                System.Console.Out.WriteLine("Starting multi-threaded RPC test...");
                server.SetSocketSendBufSize(1024);
                Thread[] threadId = new Thread[numThreads];
                for (int i = 0; i < numThreads; i++)
                {
                    TestRPC.Transactions trans = new TestRPC.Transactions(proxy, datasize);
                    threadId[i] = new Thread(trans, "TransactionThread-" + i);
                    threadId[i].Start();
                }
                // wait for all transactions to get over
                System.Console.Out.WriteLine("Waiting for all threads to finish RPCs...");
                for (int i_1 = 0; i_1 < numThreads; i_1++)
                {
                    try
                    {
                        threadId[i_1].Join();
                    }
                    catch (Exception)
                    {
                        i_1--;
                    }
                }
            }
            finally
            {
                // retry
                server.Stop();
                if (proxy != null)
                {
                    RPC.StopProxy(proxy);
                }
            }
        }