コード例 #1
0
        private Task RunCallContextTestCaseAsync(IRpcClient <AmpMessage> proxy, int threadIndex)
        {
            int errorCount = 0;
            int callCount  = 0;
            CallContextTestClient cctClient = new CallContextTestClient(proxy);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var req = new VoidReq();

            for (int i = 0; i < this._options.RunCount; i++)
            {
                var rsp = cctClient.TestAsync(req).Result;
                if (rsp.Status != 0)
                {
                    TOTAL_ERROR++;
                    errorCount++;
                }
                callCount++;
            }
            stopwatch.Stop();
            Console.WriteLine("--------------------- result {0}--------------------------------", threadIndex);
            Console.WriteLine("Call TestAsync {0} times,Error times: {1}", callCount, errorCount);
            Console.WriteLine("Elapsed time: {0}ms", stopwatch.ElapsedMilliseconds);
            Console.WriteLine("Ops per second: {0}", (int)((double)this._options.RunCount * 1000 / stopwatch.ElapsedMilliseconds));
            return(Task.CompletedTask);
        }
コード例 #2
0
        public override async Task <CommonRsp> TestAsync(VoidReq request)
        {
            var    rsp      = new CommonRsp();
            string randomId = Guid.NewGuid().ToString("D");

            _contextAccessor.CallContext.Set(contextKey, randomId);

            await Task.Factory.StartNew(() => {
                var objSet = _contextAccessor.CallContext.Get(contextKey);
                if (objSet == null)
                {
                    Logger.Warning("get value from context failed");
                    rsp.Status = -1;
                }
                else
                {
                    string v = objSet.ToString();
                    if (v != randomId)
                    {
                        Logger.Warning("get value from context ,but value changed, in new Task");
                    }
                    rsp.Status = v == randomId ? 0 : -1;
                }
            }
                                        );

            if (rsp.Status != 0)
            {
                return(rsp);
            }
            var objSetOut = _contextAccessor.CallContext.Get(contextKey);

            if (objSetOut == null)
            {
                rsp.Status = -1;
            }
            else
            {
                string v = objSetOut.ToString();
                if (v != randomId)
                {
                    Logger.Warning("get value from context ,but value changed");
                }
                rsp.Status = v == randomId ? 0 : -1;
                Logger.Debug("{0}={1}", v, randomId);
            }

            return(rsp);
        }
コード例 #3
0
//同步方法
        public CommonRsp Test(VoidReq request)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(50001, 1);

            message.Data = request.ToByteArray();
            var response = base.CallInvoker.BlockingCall(message);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            if (response.Data == null)
            {
                return(new CommonRsp());
            }
            return(CommonRsp.Parser.ParseFrom(response.Data));
        }
コード例 #4
0
        public async Task <CommonRsp> TestAsync(VoidReq request, int timeOut = 3000)
        {
            AmpMessage message = AmpMessage.CreateRequestMessage(50001, 1);

            message.Data = request.ToByteArray();
            var response = await base.CallInvoker.AsyncCall(message, timeOut);

            if (response == null)
            {
                throw new RpcException("error,response is null !");
            }
            if (response.Data == null)
            {
                return(new CommonRsp());
            }
            return(CommonRsp.Parser.ParseFrom(response.Data));
        }
コード例 #5
0
        //调用委托
        private async Task <AmpMessage> ProcessTestAsync(AmpMessage req)
        {
            VoidReq request = null;

            if (req.Data == null)
            {
                request = new VoidReq();
            }
            else
            {
                request = VoidReq.Parser.ParseFrom(req.Data);
            }
            var data = await TestAsync(request);

            var response = AmpMessage.CreateResponseMessage(req.ServiceId, req.MessageId);

            response.Sequence = req.Sequence;
            response.Data     = data.ToByteArray();
            return(response);
        }
コード例 #6
0
 //抽象方法
 public abstract Task <CommonRsp> TestAsync(VoidReq request);