Beispiel #1
0
        /// <exception cref="System.IO.IOException"/>
        private void DoRPCs(Configuration conf, bool expectFailure)
        {
            Server server = new RPC.Builder(conf).SetProtocol(typeof(TestRPC.TestProtocol)).SetInstance
                                (new TestRPC.TestImpl()).SetBindAddress(Address).SetPort(0).SetNumHandlers(5).SetVerbose
                                (true).Build();

            server.RefreshServiceAcl(conf, new TestRPC.TestPolicyProvider());
            TestRPC.TestProtocol proxy = null;
            server.Start();
            IPEndPoint addr = NetUtils.GetConnectAddress(server);

            try
            {
                proxy = RPC.GetProxy <TestRPC.TestProtocol>(TestRPC.TestProtocol.versionID, addr,
                                                            conf);
                proxy.Ping();
                if (expectFailure)
                {
                    NUnit.Framework.Assert.Fail("Expect RPC.getProxy to fail with AuthorizationException!"
                                                );
                }
            }
            catch (RemoteException e)
            {
                if (expectFailure)
                {
                    Assert.True(e.UnwrapRemoteException() is AuthorizationException
                                );
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                server.Stop();
                if (proxy != null)
                {
                    RPC.StopProxy(proxy);
                }
                MetricsRecordBuilder rb = MetricsAsserts.GetMetrics(server.rpcMetrics.Name());
                if (expectFailure)
                {
                    MetricsAsserts.AssertCounter("RpcAuthorizationFailures", 1L, rb);
                }
                else
                {
                    MetricsAsserts.AssertCounter("RpcAuthorizationSuccesses", 1L, rb);
                }
                //since we don't have authentication turned ON, we should see
                // 0 for the authentication successes and 0 for failure
                MetricsAsserts.AssertCounter("RpcAuthenticationFailures", 0L, rb);
                MetricsAsserts.AssertCounter("RpcAuthenticationSuccesses", 0L, rb);
            }
        }