public Task InsertOrReplaceBatchAsync(IEnumerable <IAccountsStatReport> stats)
        {
            var tasks = BatchEntityInsertHelper.MakeBatchesByPartitionKey(stats.Select(m => AccountsStatReportEntity.Create(m)))
                        .Select(b => _tableStorage.InsertOrReplaceBatchAsync(b));

            return(Task.WhenAll(tasks));
        }
Beispiel #2
0
        public void Always_ShouldCorrectlyProcessEnd(int totalEntitiesCount,
                                                     int expectedBatchesCount, int expectedFirstBatchSize, int expectedSecondBatchSize)
        {
            //arrange
            var srcEntities = Enumerable.Range(0, totalEntitiesCount)
                              .Select(i => new TableEntity());

            //act
            var result = BatchEntityInsertHelper.MakeBatchesByPartitionKey(srcEntities);

            //assert
            var resultBatchesSizes = result.Select(b => b.Count).ToList();

            resultBatchesSizes.Should().HaveCount(expectedBatchesCount);
            resultBatchesSizes.FirstOrDefault().Should().Be(expectedFirstBatchSize);
            resultBatchesSizes.Skip(1).FirstOrDefault().Should().Be(expectedSecondBatchSize);
        }
Beispiel #3
0
        public void Always_ShouldCorrectlySplitToBatches()
        {
            //arrange
            string GetPartitionKey(int i)
            {
                if (i < 150)
                {
                    return("1"); // 2 batches
                }
                else if (i < 250)
                {
                    return("2"); // 1 batch
                }
                else if (i < 300)
                {
                    return("3"); // 1 batch
                }
                else
                {
                    return("4"); // 1 batch
                }
            }

            var srcEntities = Enumerable.Range(0, 400)
                              .Select(i => new TableEntity(GetPartitionKey(i), ""));

            //act
            var result = BatchEntityInsertHelper.MakeBatchesByPartitionKey(srcEntities);

            //assert
            var preparedResult = result.Select(b => b.Select(e => int.Parse(e.PartitionKey)).ToList()).ToList();

            preparedResult.Should().OnlyContain(b => b.Distinct().Count() == 1);
            preparedResult.Should().OnlyContain(b => b.Count <= 100);
            preparedResult.Should().HaveCount(5);
        }