public void Run(string uri) { // Declaration of all the pipeline blocks GetTopStoriesBlock getTopStories = new GetTopStoriesBlock(); FilterTopStoriesBlock filterTopStories = new FilterTopStoriesBlock(); TraverseTopStoriesCommentsBlock traverseTopStoriesComments = new TraverseTopStoriesCommentsBlock(); ComputeTopCommentsPerStoryBlock computeTopCommentsPerStory = new ComputeTopCommentsPerStoryBlock(); // Links and interactions betwen each block getTopStories.block.LinkTo(filterTopStories.block, this.linkOptions); filterTopStories.bufferBlock.LinkTo(traverseTopStoriesComments.block, linkOptions); traverseTopStoriesComments.bufferBlock.LinkTo(computeTopCommentsPerStory.block, linkOptions); // Triggering the start of the pipeline getTopStories.block.Post(uri); getTopStories.block.Complete(); // Buffer at the end of the pipeline var receiveAllStories = Task.Run(() => { for (int i = 0; i <= Constants.NBSTORIES; i++) { this.topStories.Add(computeTopCommentsPerStory.bufferBlock.Receive()); // Wait for all the Top Story objects to arrive } }); Task.WaitAll(receiveAllStories); computeTopCommentsPerStory.bufferBlock.Complete(); //End of the pipeline commentsRegistry = traverseTopStoriesComments.commentsRegistry; printResults(); }
public void FilterTopStoriesBlock() { Queue <string> ids = new Queue <string>(); ids.Enqueue("21018236"); ids.Enqueue("21020682"); ids.Enqueue("21020682"); FilterTopStoriesBlock filterTopStoriesBlock = new FilterTopStoriesBlock(); filterTopStoriesBlock.block.Post(ids); List <Item> results = new List <Item>(); for (int i = 0; i < ids.Count; i++) { var item = filterTopStoriesBlock.bufferBlock.ReceiveAsync().Result; results.Add(item); } Assert.AreEqual(results.Count, ids.Count); }