Esempio n. 1
0
 void AppendCurrentIteration(IterationView iteration, List<int> projects, Func<CardView, bool> cardFilter)
 {
     var tasks = new Task<List<CardView>>[projects.Count];
     for(var i = 0; i != projects.Count; ++i) {
         tasks[i] = CardsForCurrentIteration(projects[i]);
     }
     iteration.AddRange(tasks.SelectMany(x => x.Result).Where(cardFilter), x => x.CurrentState);
 }
        public void SendAsyncShouldHandleHighVolumeOfMessages(int amount, int maxAsync)
        {
            using (var router = new BrokerRouter(new KafkaOptions(IntegrationConfig.IntegrationUri)))
            using (var producer = new Producer(router, maxAsync) { BatchSize = amount / 2 })
            {
                var tasks = new Task<List<ProduceResponse>>[amount];

                for (var i = 0; i < amount; i++)
                {
                    tasks[i] = producer.SendMessageAsync(IntegrationConfig.IntegrationTopic, new[] { new Message(Guid.NewGuid().ToString()) });
                }

                var results = tasks.SelectMany(x => x.Result).ToList();

                //Because of how responses are batched up and sent to servers, we will usually get multiple responses per requested message batch
                //So this assertion will never pass
                //Assert.That(results.Count, Is.EqualTo(amount));

                Assert.That(results.Any(x => x.Error != 0), Is.False, "Should not have received any results as failures.");
            }
        }
        private List<MedicineRaw> GetMedicines()
        {
            string page1 = this.GetResponseTextWithCache(1);
            var document1 = new HtmlDocument();
            document1.LoadHtml(page1);
            HtmlNode linkFim = document1.DocumentNode.SelectSingleNode("//a[contains(text(), 'Fim')]");
            string hrefLinkFim = linkFim.GetAttributeValue("href", "");
            int regexCountPages = int.Parse(Regex.Match(hrefLinkFim, @"(?<=&pagina=)\d+").Value);

            var listTasks = new Task<List<MedicineRaw>>[regexCountPages];
            for (int pagina = 0; pagina < regexCountPages; pagina++)
                listTasks[pagina] = new Task<List<MedicineRaw>>(this.GetItems, pagina + 1);

            foreach (var eachTask in listTasks)
                eachTask.Start();

            Task.WaitAll(listTasks.OfType<Task>().ToArray());

            List<MedicineRaw> medicines = listTasks.SelectMany(t => t.Result).ToList();

            return medicines;
        }
Esempio n. 4
0
        public void SendAsyncShouldHandleHighVolumeOfMessages(int amount, int maxAsync)
        {
            var tasks = new Task<List<ProduceResponse>>[amount];
            var producer = new Producer(_router, maxAsync);

            for (var i = 0; i < amount; i++)
            {
                tasks[i] = producer.SendMessageAsync("LoadTest", new Message[] { new Message { Value = Guid.NewGuid().ToString() } });
            }

            var results = tasks.SelectMany(x => x.Result).ToList();

            Assert.That(results.Count, Is.EqualTo(amount));
            Assert.That(results.Any(x => x.Error != 0), Is.False);
        }
Esempio n. 5
0
        private static void Run(Uri uriAddress, int runCount, int parallelCount)
        {
            var tasks = new Task<IEnumerable<HttpResult>>[parallelCount];

            var stopwatch = Stopwatch.StartNew();
            for (var i = 0; i < parallelCount; i++)
            {
                tasks[i] = Task.Factory.StartNew(() => HttpGet(uriAddress, runCount));
            }
            Task.WaitAll(tasks);

            var totalTime = stopwatch.Elapsed;

            PrintResults(totalTime, parallelCount, tasks.SelectMany(t => t.Result).ToArray());
        }
Esempio n. 6
0
        public void is_thread_safe()
        {
            var tasks = new Task<List<int>>[] {startThread(), startThread(), startThread(), startThread(), startThread(), startThread()};

            Task.WaitAll(tasks);

            var all = tasks.SelectMany(x => x.Result).ToArray();

            all.GroupBy(x => x).Any(x => x.Count() > 1).ShouldBeFalse();

            all.Distinct().Count().ShouldBe(tasks.Length * 1000);
        }