public virtual void testParserNonProtocol()
        {
            string           url    = "127.0.0.1:1111?_TIMEOUT=3000&_SERIALIZETYPE=hessian2";
            RpcAddressParser parser = new RpcAddressParser();
            Url btUrl = parser.parse(url);

            Assert.Equal(IPAddress.Parse("127.0.0.1"), btUrl.Ip);
            Assert.Equal(1111, btUrl.Port);
            Assert.Null(btUrl.getProperty(RpcConfigs.URL_PROTOCOL));

            url   = "127.0.0.1:1111";
            btUrl = parser.parse(url);
            Assert.Equal(IPAddress.Parse("127.0.0.1"), btUrl.Ip);
            Assert.Equal(1111, btUrl.Port);
            Assert.Null(btUrl.getProperty(RpcConfigs.URL_PROTOCOL));
        }
Ejemplo n.º 2
0
        public virtual void testUrlArgsEquals()
        {
            RpcAddressParser parser = new RpcAddressParser();

            string urlA    = "localhost:3333?key1=value1";
            Url    urlObjA = parser.parse(urlA);
            string urlB    = "localhost:3333?key1=value1";
            Url    urlObjB = parser.parse(urlB);
            string urlC    = "localhost:3333?key1=value2";
            Url    urlObjC = parser.parse(urlC);

            Assert.Equal(urlObjA, urlObjB);
            Assert.Equal(urlObjA.GetHashCode(), urlObjB.GetHashCode());
            Assert.False(urlObjA.Equals(urlObjC));
            Assert.False(urlObjA.GetHashCode() == urlObjC.GetHashCode());
        }
        /// <summary>
        /// url: url with different args
        /// invokeTimes: rpc invoke times
        /// expectConnTimes: expect connection times for client and server
        /// expectMaxFirstInvokeTimeDuration: expect first invoke time cost, if assign -1, then will not do check
        /// </summary>
        /// <param name="url"> </param>
        /// <param name="invokeTimes"> </param>
        /// <param name="expectConnTimes"> </param>
        /// <param name="expectMaxFirstInvokeTimeDuration"> </param>
        private void doTest(string url, RequestBody.InvokeType type, int invokeTimes, int expectConnTimes, int expectMaxFirstInvokeTimeDuration)
        {
            try
            {
                RpcAddressParser parser = new RpcAddressParser();
                //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
                //ORIGINAL LINE: final com.alipay.remoting.Url addr = parser.parse(url);
                Url addr = parser.parse(url);
                for (int i = 0; i < invokeTimes; i++)
                {
                    long   start = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
                    string ret   = (string)doInvoke(type, url);
                    long   end   = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
                    logger.LogWarning("WITH WARMUP, first invoke cost ->" + (end - start));
                    if ((end - start) > expectMaxFirstInvokeTimeDuration && expectMaxFirstInvokeTimeDuration != -1)
                    {
                        Assert.Null("Should not reach here, First invoke cost too much time [" + (end - start) + "ms], expect limit in [" + expectMaxFirstInvokeTimeDuration + "ms]!");
                    }
                    if (!type.Equals(RequestBody.InvokeType.ONEWAY))
                    {
                        Assert.Equal(ret, RequestBody.DEFAULT_SERVER_RETURN_STR);
                    }
                }

                if (addr.ConnWarmup)
                {
                    Thread.Sleep(200); // must wait, to wait event finish
                    Assert.Equal(expectConnTimes, serverConnectProcessor.ConnectTimes);
                    Assert.Equal(expectConnTimes, clientConnectProcessor.ConnectTimes);

                    client.closeConnection(addr);
                    Thread.Sleep(200); // must wait, to wait event finish
                    Assert.Equal(expectConnTimes, serverDisConnectProcessor.DisConnectTimes);
                    Assert.Equal(expectConnTimes, clientDisConnectProcessor.DisConnectTimes);
                }
                else
                {
                    Thread.Sleep(200); // must wait, to wait event finish
                    Assert.True(serverConnectProcessor.ConnectTimes >= expectConnTimes);
                    Assert.True(clientConnectProcessor.ConnectTimes >= expectConnTimes);

                    client.closeConnection(addr);
                    Thread.Sleep(200); // must wait, to wait event finish
                    Assert.True(serverDisConnectProcessor.DisConnectTimes >= expectConnTimes);
                    Assert.True(clientDisConnectProcessor.DisConnectTimes >= expectConnTimes);
                }
            }
            catch (RemotingException e)
            {
                logger.LogError("Exception caught in sync!", e);
                Assert.Null("Should not reach here!");
            }
            catch (ThreadInterruptedException e)
            {
                logger.LogError("ThreadInterruptedException in sync", e);
                Assert.Null("Should not reach here!");
            }
        }
        public virtual void testParserConnectTimeout()
        {
            string           url    = "127.0.0.1:1111?_CONNECTTIMEOUT=2000&_TIMEOUT=3000&_SERIALIZETYPE=hessian2&_PROTOCOL=1";
            RpcAddressParser parser = new RpcAddressParser();
            Url btUrl = parser.parse(url);

            Assert.Equal(IPAddress.Parse("127.0.0.1"), btUrl.Ip);
            Assert.Equal(1111, btUrl.Port);
            Assert.Equal("1", btUrl.getProperty(RpcConfigs.URL_PROTOCOL));
            Assert.Equal("2000", btUrl.getProperty(RpcConfigs.CONNECT_TIMEOUT_KEY));
        }
        public virtual void testArgsIllegal()
        {
            Url btUrl;

            try
            {
                string           url    = "127.0.0.1:1111?_CONNECTTIMEOUT=-1&_TIMEOUT=3000&_SERIALIZETYPE=hessian2&_PROTOCOL=1";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                parser.initUrlArgs(btUrl);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL ARGS ILLEAGL!", e);
            }

            try
            {
                string           url    = "127.0.0.1:1111?_CONNECTTIMEOUT=1000&_TIMEOUT=3000&_SERIALIZETYPE=hessian2&_PROTOCOL=-11";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                parser.initUrlArgs(btUrl);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL ARGS ILLEAGL!", e);
            }

            try
            {
                string           url    = "127.0.0.1:1111?_CONNECTTIMEOUT=1000&_TIMEOUT=3000&_SERIALIZETYPE=hessian2&_CONNECTIONNUM=-11";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                parser.initUrlArgs(btUrl);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL ARGS ILLEAGL!", e);
            }
        }
Ejemplo n.º 6
0
        public virtual void testParserNonProtocol()
        {
            string           url    = "127.0.0.1:1111?_TIMEOUT=3000&_SERIALIZETYPE=hessian2";
            RpcAddressParser parser = new RpcAddressParser();
            int MAX = 1000000;

            printMemory();
            long start1 = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();

            for (int i = 0; i < MAX; ++i)
            {
                Url btUrl = parser.parse(url);
                Assert.Equal("127.0.0.1:1111", btUrl.UniqueKey);
            }
            long end1  = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
            long time1 = end1 - start1;

            testOutputHelper.WriteLine("time1:" + time1);
            printMemory();
        }
        public virtual void testUrlIllegal()
        {
            Url btUrl = null;

            try
            {
                string           url    = "127.0.0.1";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL FORMAT ERROR!", e);
                Assert.Null(btUrl);
            }

            btUrl = null;
            try
            {
                string           url    = "127.0.0.1:";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL FORMAT ERROR!", e);
                Assert.Null(btUrl);
            }

            btUrl = null;
            try
            {
                string           url    = "127.0.0.1:1111?_CONNECTTIMEOUT";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL FORMAT ERROR!", e);
                Assert.Null(btUrl);
            }

            btUrl = null;
            try
            {
                string           url    = "127.0.0.1:100?";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL FORMAT ERROR!", e);
                Assert.Null(btUrl);
            }

            btUrl = null;
            try
            {
                string           url    = "127.0.1:100?A=B&";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL FORMAT ERROR!", e);
                Assert.Null(btUrl);
            }

            btUrl = null;
            try
            {
                string           url    = "127.0.1:100?A=B&C";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL FORMAT ERROR!", e);
                Assert.Null(btUrl);
            }

            btUrl = null;
            try
            {
                string           url    = "127.0.1:100?A=B&C=";
                RpcAddressParser parser = new RpcAddressParser();
                btUrl = parser.parse(url);
                Assert.Null("Should not reach here!");
            }
            catch (System.ArgumentException e)
            {
                logger.LogError("URL FORMAT ERROR!", e);
                Assert.Null(btUrl);
            }
        }