Exemplo n.º 1
0
        static async void Test(int concurrent, int requests)
        {
            mCount = 0;
            IAmountService henry = client.Create <IAmountService>("henry");
            IAmountService ken   = client.Create <IAmountService>("ken");

            Console.WriteLine($"[C:{concurrent}|R:{requests}]Testing ");
            List <Task> tasks = new List <Task>();
            double      start = BeetleX.TimeWatch.GetElapsedMilliseconds();

            for (int i = 0; i < concurrent; i++)
            {
                var task = Task.Run(async() =>
                {
                    for (int k = 0; k < requests; k++)
                    {
                        await henry.Income(10);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
                task = Task.Run(async() =>
                {
                    for (int k = 0; k < requests; k++)
                    {
                        await henry.Payout(10);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
                task = Task.Run(async() =>
                {
                    for (int k = 0; k < requests; k++)
                    {
                        await ken.Income(10);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
                task = Task.Run(async() =>
                {
                    for (int k = 0; k < requests; k++)
                    {
                        await ken.Payout(10);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
            }
            await Task.WhenAll(tasks.ToArray());

            double useTime = BeetleX.TimeWatch.GetElapsedMilliseconds() - start;

            Console.WriteLine($"Completed count:{mCount}|use time:{useTime}|rps:{(mCount / useTime * 1000d):###.00} |henry:{await henry.Get()},ken:{await ken.Get()}");
        }
 public MainController(IAmountService amountService)
 {
     _amountService = amountService;
 }
 public GeneralController(IAmountService _amountService)
 {
     amountService = _amountService;
 }
 public TransactionBusinessService(IGraphSolver graphSolver, IAmountService amountService, ILogger <TransactionBusinessService> logger)
 {
     _graphSolver   = graphSolver;
     _amountService = amountService;
     _logger        = logger;
 }
 public AmountController(IAmountService service)
 {
     _service = service;
 }