Exemplo n.º 1
0
        public void Perform()
        {
            var scenarioFileContent = File.ReadAllText("overallReportScenario.json");
            var scenario            = scenarioFileContent.Split('|');
            var options             = new ParallelOptions {
                MaxDegreeOfParallelism = settings.Threads == 0 ? 1 : settings.Threads
            };

            var overallTimer = Stopwatch.StartNew();

            Parallel.ForEach(scenario, options, element =>
            {
                var scenarioTimer = Stopwatch.StartNew();
                var scenarioId    = Guid.NewGuid().ToString();

                var scenarioPartTimer = Stopwatch.StartNew();
                var token             = sessionRequester.GetToken("analyst", scenarioId);
                logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='overallReport token' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                scenarioPartTimer.Restart();
                Report(element, scenarioId);
                logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='overallReport report' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                scenarioPartTimer.Restart();
                sessionRequester.Logout(token, scenarioId);
                logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='overallReport logout' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='overallReport scenario' Processing='{scenarioTimer.ElapsedMilliseconds}'");
            });

            logger.Information($"Service='Requester' Method='overallReport overall' Processing='{overallTimer.ElapsedMilliseconds}'");
        }
        public void Perform()
        {
            var scenarioFileContent = File.ReadAllText("business.json");
            var scenarios           = JsonConvert.DeserializeObject <BusinessUserScenarioElement[]>(scenarioFileContent);
            var groups      = scenarios.GroupBy(s => s.Group);
            var groupsCount = groups.Count();
            var options     = new ParallelOptions {
                MaxDegreeOfParallelism = groupsCount
            };

            var overallTimer = Stopwatch.StartNew();

            Parallel.ForEach(groups, options, group =>
            {
                foreach (var element in group)
                {
                    var scenarioTimer = Stopwatch.StartNew();
                    var scenarioId    = Guid.NewGuid().ToString();

                    var scenarioPartTimer = Stopwatch.StartNew();
                    var token             = sessionRequester.GetToken(element.User, scenarioId);
                    logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='business token' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                    //todo check account balance
                    scenarioPartTimer.Restart();
                    Panel(element.UserId, scenarioId);
                    logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='business panel' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                    foreach (var transaction in element.Transactions)
                    {
                        scenarioPartTimer.Restart();
                        Transfer(transaction, scenarioId);
                        logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='business transfer' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");
                    }

                    scenarioPartTimer.Restart();
                    sessionRequester.Logout(token, scenarioId);
                    logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='business logout' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                    logger.Information($"Service='Requester' ScenarioId='{scenarioId}' Method='business scenario' Processing='{scenarioTimer.ElapsedMilliseconds}'");
                }
            });

            logger.Information($"Service='Requester' Method='business overall' Processing='{overallTimer.ElapsedMilliseconds}'");
        }
        public void Perform()
        {
            var scenarioFileContent = File.ReadAllText("individual.json");
            var scenarios           = JsonConvert.DeserializeObject <IndividualUserScenarioElement[]>(scenarioFileContent);
            var groups      = scenarios.GroupBy(s => s.Group);
            var groupsCount = groups.Count();
            var options     = new ParallelOptions {
                MaxDegreeOfParallelism = groupsCount
            };

            var overallTimer = Stopwatch.StartNew();

            Parallel.ForEach(groups, options, group =>
            {
                var index = 0;
                foreach (var element in group)
                {
                    var scenarioNo    = $"{group.Key}_{index}";
                    var scenarioTimer = Stopwatch.StartNew();
                    var scenarioId    = Guid.NewGuid().ToString();

                    var scenarioPartTimer = Stopwatch.StartNew();
                    var token             = sessionRequester.GetToken(element.User, scenarioId);
                    logger.Information($"Service='Requester' ScenarioNo='{scenarioNo}' ScenarioId='{scenarioId}' Method='individual token' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                    scenarioPartTimer.Restart();
                    Balance(element.AccountId, scenarioId);
                    logger.Information($"Service='Requester' ScenarioNo='{scenarioNo}' ScenarioId='{scenarioId}' Method='individual balance' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                    scenarioPartTimer.Restart();
                    Transfer(element, scenarioId);
                    logger.Information($"Service='Requester' ScenarioNo='{scenarioNo}' ScenarioId='{scenarioId}' Method='individual transfer' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                    scenarioPartTimer.Restart();
                    sessionRequester.Logout(token, scenarioId);
                    logger.Information($"Service='Requester' ScenarioNo='{scenarioNo}' ScenarioId='{scenarioId}' Method='individual logout' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                    logger.Information($"Service='Requester' ScenarioNo='{scenarioNo}' ScenarioId='{scenarioId}' Method='individual scenario' Processing='{scenarioTimer.ElapsedMilliseconds}'");
                    index++;
                }
            });

            logger.Information($"Service='Requester' Method='individual overall' Processing='{overallTimer.ElapsedMilliseconds}'");
        }
Exemplo n.º 4
0
        private void Perform(int index)
        {
            var currentTime = automatSettings.StartTime;

            while (currentTime < automatSettings.EndTime)
            {
                var scenarioTimer = Stopwatch.StartNew();
                var scenarioId    = Guid.NewGuid().ToString();

                var scenarioPartTimer = Stopwatch.StartNew();
                var token             = sessionRequester.GetToken("automat", scenarioId);
                logger.Information($"Service='Automat' ScenarioId='{scenarioId}' Method='automat token' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                scenarioPartTimer.Restart();
                var data = GetData(index, scenarioId, currentTime);
                logger.Information($"Service='Automat' ScenarioId='{scenarioId}' Method='automat getbatch' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                var toPay = data.Payments.Where(p => p.LatestProcessingTimestamp + p.Interval < DateTime.UtcNow);

                var balancesDict = data.Balances.ToDictionary(k => k.Id, v => v);
                var loansDict    = data.Loans.ToDictionary(k => k.PaymentId, v => v);

                var withSufficientBalance = toPay.Where(p =>
                {
                    if (p.Amount <= balancesDict[p.AccountId].Amount)
                    {
                        balancesDict[p.AccountId].Amount -= p.Amount;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    };
                }).ToArray();
                var withInsufficientBalance = toPay.Except(withSufficientBalance);
                var paidIds = withSufficientBalance.Select(p => p.Id).ToHashSet();

                var transfers         = withSufficientBalance.Select(p => CreateTransfer(p, loansDict.ContainsKey(p.Id) ? loansDict[p.Id] : null)).ToArray();
                var messages          = withInsufficientBalance.Select(p => CreateMessage(p, balancesDict[p.AccountId])).ToArray();
                var repaidInstalments = data.Loans.Where(l => paidIds.Contains(l.PaymentId)).Select(l => l.Id).ToArray();
                var processedIds      = toPay.Select(p => p.Id).ToArray();

                var batchProcess = new BatchProcess {
                    ProcessingTimestamp = currentTime, Transfers = transfers, Messages = messages, RepaidInstalmentsIds = repaidInstalments, ProcessedPaymentsIds = processedIds
                };

                scenarioPartTimer.Restart();
                SendData(batchProcess, scenarioId);
                logger.Information($"Service='Automat' ScenarioId='{scenarioId}' Method='automat processbatch' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                scenarioPartTimer.Restart();
                sessionRequester.Logout(token, scenarioId);
                logger.Information($"Service='Automat' ScenarioId='{scenarioId}' Method='automat logout' Processing='{scenarioPartTimer.ElapsedMilliseconds}'");

                logger.Information($"Service='Automat' ScenarioId='{scenarioId}' Method='automat scenario' Processing='{scenarioTimer.ElapsedMilliseconds}'");

                //Thread.Sleep(automatSettings.SleepTime);
                //currentTime += scenarioTimer.Elapsed;
                currentTime += TimeSpan.FromMinutes(5);
            }
        }