예제 #1
0
 public virtual void TestVersionMismatch()
 {
     server = new RPC.Builder(conf).SetProtocol(typeof(TestRPCCompatibility.TestProtocol2
                                                       )).SetInstance(new TestRPCCompatibility.TestImpl2()).SetBindAddress(Address).SetPort
                  (0).SetNumHandlers(2).SetVerbose(false).Build();
     server.Start();
     addr = NetUtils.GetConnectAddress(server);
     TestRPCCompatibility.TestProtocol4 proxy = RPC.GetProxy <TestRPCCompatibility.TestProtocol4
                                                              >(TestRPCCompatibility.TestProtocol4.versionID, addr, conf);
     try
     {
         proxy.Echo(21);
         NUnit.Framework.Assert.Fail("The call must throw VersionMismatch exception");
     }
     catch (RemoteException ex)
     {
         Assert.Equal(typeof(RPC.VersionMismatch).FullName, ex.GetClassName
                          ());
         Assert.True(ex.GetErrorCode().Equals(RpcHeaderProtos.RpcResponseHeaderProto.RpcErrorCodeProto
                                              .ErrorRpcVersionMismatch));
     }
     catch (IOException ex)
     {
         NUnit.Framework.Assert.Fail("Expected version mismatch but got " + ex);
     }
 }
예제 #2
0
        public virtual void SetUp()
        {
            // Setup server for both protocols
            conf = new Configuration();
            conf.SetInt(CommonConfigurationKeys.IpcMaximumDataLength, 1024);
            // Set RPC engine to protobuf RPC engine
            RPC.SetProtocolEngine(conf, typeof(TestProtoBufRpc.TestRpcService), typeof(ProtobufRpcEngine
                                                                                       ));
            // Create server side implementation
            TestProtoBufRpc.PBServerImpl serverImpl = new TestProtoBufRpc.PBServerImpl();
            BlockingService service = TestRpcServiceProtos.TestProtobufRpcProto.NewReflectiveBlockingService
                                          (serverImpl);

            // Get RPC server for server side implementation
            server = new RPC.Builder(conf).SetProtocol(typeof(TestProtoBufRpc.TestRpcService)
                                                       ).SetInstance(service).SetBindAddress(Address).SetPort(Port).Build();
            addr = NetUtils.GetConnectAddress(server);
            // now the second protocol
            TestProtoBufRpc.PBServer2Impl server2Impl = new TestProtoBufRpc.PBServer2Impl();
            BlockingService service2 = TestRpcServiceProtos.TestProtobufRpc2Proto.NewReflectiveBlockingService
                                           (server2Impl);

            server.AddProtocol(RPC.RpcKind.RpcProtocolBuffer, typeof(TestProtoBufRpc.TestRpcService2
                                                                     ), service2);
            server.Start();
        }
예제 #3
0
 public virtual void TearDown()
 {
     if (proxy != null)
     {
         RPC.StopProxy(proxy.GetProxy());
         proxy = null;
     }
     if (server != null)
     {
         server.Stop();
         server = null;
     }
 }
예제 #4
0
 public virtual void TestVersion0ClientVersion1Server()
 {
     // old client vs new server
     // create a server with two handlers
     TestRPCCompatibility.TestImpl1 impl = new TestRPCCompatibility.TestImpl1();
     server = new RPC.Builder(conf).SetProtocol(typeof(TestRPCCompatibility.TestProtocol1
                                                       )).SetInstance(impl).SetBindAddress(Address).SetPort(0).SetNumHandlers(2).SetVerbose
                  (false).Build();
     server.AddProtocol(RPC.RpcKind.RpcWritable, typeof(TestRPCCompatibility.TestProtocol0
                                                        ), impl);
     server.Start();
     addr  = NetUtils.GetConnectAddress(server);
     proxy = RPC.GetProtocolProxy <TestRPCCompatibility.TestProtocol0>(TestRPCCompatibility.TestProtocol0
                                                                       .versionID, addr, conf);
     TestRPCCompatibility.TestProtocol0 proxy0 = (TestRPCCompatibility.TestProtocol0)proxy
                                                 .GetProxy();
     proxy0.Ping();
 }
예제 #5
0
        public virtual void TestIsMethodSupported()
        {
            server = new RPC.Builder(conf).SetProtocol(typeof(TestRPCCompatibility.TestProtocol2
                                                              )).SetInstance(new TestRPCCompatibility.TestImpl2()).SetBindAddress(Address).SetPort
                         (0).SetNumHandlers(2).SetVerbose(false).Build();
            server.Start();
            addr = NetUtils.GetConnectAddress(server);
            TestRPCCompatibility.TestProtocol2 proxy = RPC.GetProxy <TestRPCCompatibility.TestProtocol2
                                                                     >(TestRPCCompatibility.TestProtocol2.versionID, addr, conf);
            bool supported = RpcClientUtil.IsMethodSupported(proxy, typeof(TestRPCCompatibility.TestProtocol2
                                                                           ), RPC.RpcKind.RpcWritable, RPC.GetProtocolVersion(typeof(TestRPCCompatibility.TestProtocol2
                                                                                                                                     )), "echo");

            Assert.True(supported);
            supported = RpcClientUtil.IsMethodSupported(proxy, typeof(TestRPCCompatibility.TestProtocol2
                                                                      ), RPC.RpcKind.RpcProtocolBuffer, RPC.GetProtocolVersion(typeof(TestRPCCompatibility.TestProtocol2
                                                                                                                                      )), "echo");
            NUnit.Framework.Assert.IsFalse(supported);
        }
예제 #6
0
 public virtual void TestVersion2ClientVersion2Server()
 {
     // equal version client and server
     // create a server with two handlers
     TestRPCCompatibility.TestImpl2 impl = new TestRPCCompatibility.TestImpl2();
     server = new RPC.Builder(conf).SetProtocol(typeof(TestRPCCompatibility.TestProtocol2
                                                       )).SetInstance(impl).SetBindAddress(Address).SetPort(0).SetNumHandlers(2).SetVerbose
                  (false).Build();
     server.AddProtocol(RPC.RpcKind.RpcWritable, typeof(TestRPCCompatibility.TestProtocol0
                                                        ), impl);
     server.Start();
     addr = NetUtils.GetConnectAddress(server);
     TestRPCCompatibility.Version2Client client = new TestRPCCompatibility.Version2Client
                                                      (this);
     client.Ping();
     Assert.Equal("hello", client.Echo("hello"));
     // now that echo(int) is supported by the server, echo(int) should return -3
     Assert.Equal(-3, client.Echo(3));
 }
예제 #7
0
 public virtual void TestVersion2ClientVersion1Server()
 {
     // Compatible new client & old server
     // create a server with two handlers
     TestRPCCompatibility.TestImpl1 impl = new TestRPCCompatibility.TestImpl1();
     server = new RPC.Builder(conf).SetProtocol(typeof(TestRPCCompatibility.TestProtocol1
                                                       )).SetInstance(impl).SetBindAddress(Address).SetPort(0).SetNumHandlers(2).SetVerbose
                  (false).Build();
     server.AddProtocol(RPC.RpcKind.RpcWritable, typeof(TestRPCCompatibility.TestProtocol0
                                                        ), impl);
     server.Start();
     addr = NetUtils.GetConnectAddress(server);
     TestRPCCompatibility.Version2Client client = new TestRPCCompatibility.Version2Client
                                                      (this);
     client.Ping();
     Assert.Equal("hello", client.Echo("hello"));
     // echo(int) is not supported by server, so returning 3
     // This verifies that echo(int) and echo(String)'s hash codes are different
     Assert.Equal(3, client.Echo(3));
 }
예제 #8
0
 /// <exception cref="Org.Apache.Hadoop.Ipc.RpcServerException"/>
 private static RPC.Server.ProtoClassProtoImpl GetProtocolImpl(RPC.Server server,
                                                               string protoName, long clientVersion)
 {
     RPC.Server.ProtoNameVer pv = new RPC.Server.ProtoNameVer(protoName, clientVersion
                                                              );
     RPC.Server.ProtoClassProtoImpl impl = server.GetProtocolImplMap(RPC.RpcKind.RpcProtocolBuffer
                                                                     )[pv];
     if (impl == null)
     {
         // no match for Protocol AND Version
         RPC.Server.VerProtocolImpl highest = server.GetHighestSupportedProtocol(RPC.RpcKind
                                                                                 .RpcProtocolBuffer, protoName);
         if (highest == null)
         {
             throw new RpcNoSuchProtocolException("Unknown protocol: " + protoName);
         }
         // protocol supported but not the version that client wants
         throw new RPC.VersionMismatch(protoName, clientVersion, highest.version);
     }
     return(impl);
 }
예제 #9
0
        public virtual void TestProtocolMetaInfoSSTranslatorPB()
        {
            TestRPCCompatibility.TestImpl1 impl = new TestRPCCompatibility.TestImpl1();
            server = new RPC.Builder(conf).SetProtocol(typeof(TestRPCCompatibility.TestProtocol1
                                                              )).SetInstance(impl).SetBindAddress(Address).SetPort(0).SetNumHandlers(2).SetVerbose
                         (false).Build();
            server.AddProtocol(RPC.RpcKind.RpcWritable, typeof(TestRPCCompatibility.TestProtocol0
                                                               ), impl);
            server.Start();
            ProtocolMetaInfoServerSideTranslatorPB xlator = new ProtocolMetaInfoServerSideTranslatorPB
                                                                (server);

            ProtocolInfoProtos.GetProtocolSignatureResponseProto resp = xlator.GetProtocolSignature
                                                                            (null, CreateGetProtocolSigRequestProto(typeof(TestRPCCompatibility.TestProtocol1
                                                                                                                           ), RPC.RpcKind.RpcProtocolBuffer));
            //No signatures should be found
            Assert.Equal(0, resp.GetProtocolSignatureCount());
            resp = xlator.GetProtocolSignature(null, CreateGetProtocolSigRequestProto(typeof(
                                                                                          TestRPCCompatibility.TestProtocol1), RPC.RpcKind.RpcWritable));
            Assert.Equal(1, resp.GetProtocolSignatureCount());
            ProtocolInfoProtos.ProtocolSignatureProto sig = resp.GetProtocolSignatureList()[0
                                                            ];
            Assert.Equal(TestRPCCompatibility.TestProtocol1.versionID, sig
                         .GetVersion());
            bool found    = false;
            int  expected = ProtocolSignature.GetFingerprint(typeof(TestRPCCompatibility.TestProtocol1
                                                                    ).GetMethod("echo", typeof(string)));

            foreach (int m in sig.GetMethodsList())
            {
                if (expected == m)
                {
                    found = true;
                    break;
                }
            }
            Assert.True(found);
        }
예제 #10
0
 public virtual void TestVersion1ClientVersion0Server()
 {
     // old client vs new server
     // create a server with two handlers
     server = new RPC.Builder(conf).SetProtocol(typeof(TestRPCCompatibility.TestProtocol0
                                                       )).SetInstance(new TestRPCCompatibility.TestImpl0()).SetBindAddress(Address).SetPort
                  (0).SetNumHandlers(2).SetVerbose(false).Build();
     server.Start();
     addr  = NetUtils.GetConnectAddress(server);
     proxy = RPC.GetProtocolProxy <TestRPCCompatibility.TestProtocol1>(TestRPCCompatibility.TestProtocol1
                                                                       .versionID, addr, conf);
     TestRPCCompatibility.TestProtocol1 proxy1 = (TestRPCCompatibility.TestProtocol1)proxy
                                                 .GetProxy();
     proxy1.Ping();
     try
     {
         proxy1.Echo("hello");
         NUnit.Framework.Assert.Fail("Echo should fail");
     }
     catch (IOException)
     {
     }
 }
        public virtual void SetUp()
        {
            // create a server with two handlers
            server = new RPC.Builder(conf).SetProtocol(typeof(TestMultipleProtocolServer.Foo0
                                                              )).SetInstance(new TestMultipleProtocolServer.Foo0Impl(this)).SetBindAddress(Address
                                                                                                                                           ).SetPort(0).SetNumHandlers(2).SetVerbose(false).Build();
            server.AddProtocol(RPC.RpcKind.RpcWritable, typeof(TestMultipleProtocolServer.Foo1
                                                               ), new TestMultipleProtocolServer.Foo1Impl(this));
            server.AddProtocol(RPC.RpcKind.RpcWritable, typeof(TestMultipleProtocolServer.Bar
                                                               ), new TestMultipleProtocolServer.BarImpl(this));
            server.AddProtocol(RPC.RpcKind.RpcWritable, typeof(TestMultipleProtocolServer.Mixin
                                                               ), new TestMultipleProtocolServer.BarImpl(this));
            // Add Protobuf server
            // Create server side implementation
            TestProtoBufRpc.PBServerImpl pbServerImpl = new TestProtoBufRpc.PBServerImpl();
            BlockingService service = TestRpcServiceProtos.TestProtobufRpcProto.NewReflectiveBlockingService
                                          (pbServerImpl);

            server.AddProtocol(RPC.RpcKind.RpcProtocolBuffer, typeof(TestProtoBufRpc.TestRpcService
                                                                     ), service);
            server.Start();
            addr = NetUtils.GetConnectAddress(server);
        }
예제 #12
0
                /// <exception cref="System.Exception"/>
                public virtual IWritable Call(RPC.Server server, string protocol, IWritable writableRequest
                                              , long receiveTime)
                {
                    ProtobufRpcEngine.RpcRequestWrapper request = (ProtobufRpcEngine.RpcRequestWrapper
                                                                   )writableRequest;
                    ProtobufRpcEngineProtos.RequestHeaderProto rpcRequest = request.requestHeader;
                    string methodName    = rpcRequest.GetMethodName();
                    string protoName     = rpcRequest.GetDeclaringClassProtocolName();
                    long   clientVersion = rpcRequest.GetClientProtocolVersion();

                    if (server.verbose)
                    {
                        Log.Info("Call: protocol=" + protocol + ", method=" + methodName);
                    }
                    RPC.Server.ProtoClassProtoImpl protocolImpl = GetProtocolImpl(server, protoName,
                                                                                  clientVersion);
                    BlockingService service = (BlockingService)protocolImpl.protocolImpl;

                    Descriptors.MethodDescriptor methodDescriptor = service.GetDescriptorForType().FindMethodByName
                                                                        (methodName);
                    if (methodDescriptor == null)
                    {
                        string msg = "Unknown method " + methodName + " called on " + protocol + " protocol.";
                        Log.Warn(msg);
                        throw new RpcNoSuchMethodException(msg);
                    }
                    Message prototype = service.GetRequestPrototype(methodDescriptor);
                    Message param     = prototype.NewBuilderForType().MergeFrom(request.theRequestRead).Build
                                            ();
                    Message   result;
                    long      startTime = Time.Now();
                    int       qTime     = (int)(startTime - receiveTime);
                    Exception exception = null;

                    try
                    {
                        server.rpcDetailedMetrics.Init(protocolImpl.protocolClass);
                        result = service.CallBlockingMethod(methodDescriptor, null, param);
                    }
                    catch (ServiceException e)
                    {
                        exception = (Exception)e.InnerException;
                        throw (Exception)e.InnerException;
                    }
                    catch (Exception e)
                    {
                        exception = e;
                        throw;
                    }
                    finally
                    {
                        int processingTime = (int)(Time.Now() - startTime);
                        if (Log.IsDebugEnabled())
                        {
                            string msg = "Served: " + methodName + " queueTime= " + qTime + " procesingTime= "
                                         + processingTime;
                            if (exception != null)
                            {
                                msg += " exception= " + exception.GetType().Name;
                            }
                            Log.Debug(msg);
                        }
                        string detailedMetricsName = (exception == null) ? methodName : exception.GetType
                                                         ().Name;
                        server.rpcMetrics.AddRpcQueueTime(qTime);
                        server.rpcMetrics.AddRpcProcessingTime(processingTime);
                        server.rpcDetailedMetrics.AddProcessingTime(detailedMetricsName, processingTime);
                    }
                    return(new ProtobufRpcEngine.RpcResponseWrapper(result));
                }
예제 #13
0
                /// <exception cref="System.IO.IOException"/>
                /// <exception cref="Org.Apache.Hadoop.Ipc.RPC.VersionMismatch"/>
                public virtual IWritable Call(RPC.Server server, string protocolName, IWritable rpcRequest
                                              , long receivedTime)
                {
                    WritableRpcEngine.Invocation call = (WritableRpcEngine.Invocation)rpcRequest;
                    if (server.verbose)
                    {
                        Log("Call: " + call);
                    }
                    // Verify writable rpc version
                    if (call.GetRpcVersion() != writableRpcVersion)
                    {
                        // Client is using a different version of WritableRpc
                        throw new RpcServerException("WritableRpc version mismatch, client side version="
                                                     + call.GetRpcVersion() + ", server side version=" + writableRpcVersion);
                    }
                    long   clientVersion = call.GetProtocolVersion();
                    string protoName;

                    RPC.Server.ProtoClassProtoImpl protocolImpl;
                    if (call.declaringClassProtocolName.Equals(typeof(VersionedProtocol).FullName))
                    {
                        // VersionProtocol methods are often used by client to figure out
                        // which version of protocol to use.
                        //
                        // Versioned protocol methods should go the protocolName protocol
                        // rather than the declaring class of the method since the
                        // the declaring class is VersionedProtocol which is not
                        // registered directly.
                        // Send the call to the highest  protocol version
                        RPC.Server.VerProtocolImpl highest = server.GetHighestSupportedProtocol(RPC.RpcKind
                                                                                                .RpcWritable, protocolName);
                        if (highest == null)
                        {
                            throw new RpcServerException("Unknown protocol: " + protocolName);
                        }
                        protocolImpl = highest.protocolTarget;
                    }
                    else
                    {
                        protoName = call.declaringClassProtocolName;
                        // Find the right impl for the protocol based on client version.
                        RPC.Server.ProtoNameVer pv = new RPC.Server.ProtoNameVer(call.declaringClassProtocolName
                                                                                 , clientVersion);
                        protocolImpl = server.GetProtocolImplMap(RPC.RpcKind.RpcWritable)[pv];
                        if (protocolImpl == null)
                        {
                            // no match for Protocol AND Version
                            RPC.Server.VerProtocolImpl highest = server.GetHighestSupportedProtocol(RPC.RpcKind
                                                                                                    .RpcWritable, protoName);
                            if (highest == null)
                            {
                                throw new RpcServerException("Unknown protocol: " + protoName);
                            }
                            else
                            {
                                // protocol supported but not the version that client wants
                                throw new RPC.VersionMismatch(protoName, clientVersion, highest.version);
                            }
                        }
                    }
                    // Invoke the protocol method
                    long      startTime = Time.Now();
                    int       qTime     = (int)(startTime - receivedTime);
                    Exception exception = null;

                    try
                    {
                        MethodInfo method = protocolImpl.protocolClass.GetMethod(call.GetMethodName(), call
                                                                                 .GetParameterClasses());
                        server.rpcDetailedMetrics.Init(protocolImpl.protocolClass);
                        object value = method.Invoke(protocolImpl.protocolImpl, call.GetParameters());
                        if (server.verbose)
                        {
                            Log("Return: " + value);
                        }
                        return(new ObjectWritable(method.ReturnType, value));
                    }
                    catch (TargetInvocationException e)
                    {
                        Exception target = e.InnerException;
                        if (target is IOException)
                        {
                            exception = (IOException)target;
                            throw (IOException)target;
                        }
                        else
                        {
                            IOException ioe = new IOException(target.ToString());
                            ioe.SetStackTrace(target.GetStackTrace());
                            exception = ioe;
                            throw ioe;
                        }
                    }
                    catch (Exception e)
                    {
                        if (!(e is IOException))
                        {
                            Log.Error("Unexpected throwable object ", e);
                        }
                        IOException ioe = new IOException(e.ToString());
                        ioe.SetStackTrace(e.GetStackTrace());
                        exception = ioe;
                        throw ioe;
                    }
                    finally
                    {
                        int processingTime = (int)(Time.Now() - startTime);
                        if (Log.IsDebugEnabled())
                        {
                            string msg = "Served: " + call.GetMethodName() + " queueTime= " + qTime + " procesingTime= "
                                         + processingTime;
                            if (exception != null)
                            {
                                msg += " exception= " + exception.GetType().Name;
                            }
                            Log.Debug(msg);
                        }
                        string detailedMetricsName = (exception == null) ? call.GetMethodName() : exception
                                                     .GetType().Name;
                        server.rpcMetrics.AddRpcQueueTime(qTime);
                        server.rpcMetrics.AddRpcProcessingTime(processingTime);
                        server.rpcDetailedMetrics.AddProcessingTime(detailedMetricsName, processingTime);
                    }
                }
예제 #14
0
 /// <exception cref="System.Exception"/>
 public virtual int Run(string[] args)
 {
     RPCCallBenchmark.MyOptions opts = new RPCCallBenchmark.MyOptions(args);
     if (opts.failed)
     {
         return(-1);
     }
     // Set RPC engine to the configured RPC engine
     RPC.SetProtocolEngine(conf, typeof(TestProtoBufRpc.TestRpcService), opts.rpcEngine
                           );
     RPC.Server server = StartServer(opts);
     try
     {
         MultithreadedTestUtil.TestContext ctx = SetupClientTestContext(opts);
         if (ctx != null)
         {
             long totalCalls = 0;
             ctx.StartThreads();
             long veryStart = Runtime.NanoTime();
             // Loop printing results every second until the specified
             // time has elapsed
             for (int i = 0; i < opts.secondsToRun; i++)
             {
                 long st = Runtime.NanoTime();
                 ctx.WaitFor(1000);
                 long et = Runtime.NanoTime();
                 long ct = callCount.GetAndSet(0);
                 totalCalls += ct;
                 double callsPerSec = (ct * 1000000000) / (et - st);
                 System.Console.Out.WriteLine("Calls per second: " + callsPerSec);
             }
             // Print results
             if (totalCalls > 0)
             {
                 long   veryEnd        = Runtime.NanoTime();
                 double callsPerSec    = (totalCalls * 1000000000) / (veryEnd - veryStart);
                 long   cpuNanosClient = GetTotalCpuTime(ctx.GetTestThreads());
                 long   cpuNanosServer = -1;
                 if (server != null)
                 {
                     cpuNanosServer = GetTotalCpuTime(server.GetHandlers());
                 }
                 System.Console.Out.WriteLine("====== Results ======");
                 System.Console.Out.WriteLine("Options:\n" + opts);
                 System.Console.Out.WriteLine("Total calls per second: " + callsPerSec);
                 System.Console.Out.WriteLine("CPU time per call on client: " + (cpuNanosClient /
                                                                                 totalCalls) + " ns");
                 if (server != null)
                 {
                     System.Console.Out.WriteLine("CPU time per call on server: " + (cpuNanosServer /
                                                                                     totalCalls) + " ns");
                 }
             }
             else
             {
                 System.Console.Out.WriteLine("No calls!");
             }
             ctx.Stop();
         }
         else
         {
             while (true)
             {
                 Thread.Sleep(10000);
             }
         }
     }
     finally
     {
         if (server != null)
         {
             server.Stop();
         }
     }
     return(0);
 }
예제 #15
0
 public ProtocolMetaInfoServerSideTranslatorPB(RPC.Server server)
 {
     this.server = server;
 }