Ejemplo n.º 1
0
 public IEnumerable <Task <int> > CountNextBatches(int batchSize)
 {
     NextBatch += batchSize;
     return(TasksFactory.CreateTasks(
                Enumerable.Repeat(0, batchSize).ToArray()
                ));
 }
Ejemplo n.º 2
0
        public async Task BatchProcessing_when_all_succeed_within_timeout_boundaries()
        {
            // Arrange
            var batchTimeoutInMilliseconds = 1000;
            var tasks   = TasksFactory.CreateTasks(500, 500, 500);
            var counter = new Counter();

            // Act
            await EnumerableExt.BatchProcessing(
                self : tasks,
                batchTimeoutInMilliseconds : batchTimeoutInMilliseconds,
                onSuccess : counter.CountSucceeded,
                onFail : counter.CountFailed,
                nextBatch : counter.CountNextBatches);

            // Assert
            counter.Succeeded.Should().Be(tasks.Count);
            counter.Failed.Should().Be(0);
            counter.NextBatch.Should().Be(0);
        }
Ejemplo n.º 3
0
        public async Task BatchProcessing_execution_time_of_one_task_bigger_than_timeout()
        {
            // Arrange
            var batchTimeoutInMilliseconds = 1000;
            var tasks   = TasksFactory.CreateTasks(500, 1200, 500);
            var counter = new Counter();

            // Act
            await EnumerableExt.BatchProcessing(
                self : tasks,
                batchTimeoutInMilliseconds : batchTimeoutInMilliseconds,
                onSuccess : counter.CountSucceeded,
                onFail : counter.CountFailed,
                nextBatch : counter.CountNextBatches);

            // Assert
            counter.Succeeded.Should().Be(5);
            counter.Failed.Should().Be(0);
            counter.NextBatch.Should().Be(tasks.Count - 1);
        }