예제 #1
0
        public Task ConstructAndComplete()
        {
            var nagleBlock = new NagleBlock <ContentHash>();

            nagleBlock.Complete();
            return(nagleBlock.Completion);
        }
예제 #2
0
        private async Task SendAndCompleteAsync(
            IList <ContentHash> items, NagleBlock <ContentHash> nagleBlock, ActionBlock <ContentHash[]> actionBlock)
        {
            nagleBlock.LinkTo(actionBlock);
            foreach (var item in items)
            {
                await nagleBlock.SendAsync(item);
            }

            nagleBlock.Complete();
            await nagleBlock.Completion;

            actionBlock.Complete();
            await actionBlock.Completion;
        }
예제 #3
0
        public async Task PassItems(int itemCount)
        {
            var items   = Enumerable.Range(0, itemCount).Select(i => ContentHash.Random()).ToList();
            var results = new List <ContentHash>();

            var testActionBlock = new ActionBlock <ContentHash[]>(contentHashes =>
            {
                results.AddRange(contentHashes);
            });

            var nagleBlock = new NagleBlock <ContentHash>();

            await SendAndCompleteAsync(items, nagleBlock, testActionBlock);

            new HashSet <ContentHash>(items).SetEquals(results).Should().BeTrue();
        }
예제 #4
0
        public async Task ItemsPassedInBatches()
        {
            const int itemCount           = 2;
            var       results             = new List <List <ContentHash> >();
            var       randomContentHashes = Enumerable.Range(0, itemCount).Select(i => ContentHash.Random()).ToList();
            var       testActionBlock     = new ActionBlock <ContentHash[]>(contentHashes =>
            {
                results.Add(contentHashes.ToList());
            });

            var nagleBlock = new NagleBlock <ContentHash>(1);

            await SendAndCompleteAsync(randomContentHashes, nagleBlock, testActionBlock);

            results.Count.Should().Be(2);
            var mergedResults = results.SelectMany(x => x).ToList();

            mergedResults.Count.Should().Be(itemCount);
            new HashSet <ContentHash>(randomContentHashes).SetEquals(mergedResults).Should().BeTrue();
        }