Пример #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 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();
 }
Пример #4
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);
        }
Пример #5
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));
 }
Пример #6
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));
 }
Пример #7
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);
        }
Пример #8
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);
        }