public void RunBatchBlockTests() { Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new BatchBlock <int>(1, new GroupingDataflowBlockOptions() { NameFormat = nameFormat }) : new BatchBlock <int>(1))); Assert.True(ISourceBlockTestHelper.TestLinkTo <int[]>(ConstructBatchNewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestReserveMessageAndReleaseReservation <int[]>(ConstructBatchNewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestConsumeMessage <int[]>(ConstructBatchNewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestTryReceiveWithFilter <int[]>(ConstructBatchNewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestTryReceiveAll <int[]>(ConstructBatchNewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestCancelWhileReserve(ct => new BatchBlock <int>(1, new GroupingDataflowBlockOptions { CancellationToken = ct }), source => (source as BatchBlock <int>).Post(0), source => (source as BatchBlock <int>).OutputCount)); Assert.True(ITargetBlockTestHelper.TestOfferMessage <int>(new BatchBlock <int>(1))); Assert.True(ITargetBlockTestHelper.TestPost <int>(new BatchBlock <int>(1))); Assert.True(ITargetBlockTestHelper.TestComplete <int>(new BatchBlock <int>(1))); Assert.True(ITargetBlockTestHelper.TestCompletionTask <int>(new BatchBlock <int>(1))); Assert.True(ITargetBlockTestHelper.TestNonGreedyPost(new BatchBlock <int>(1, new GroupingDataflowBlockOptions { Greedy = false }))); Assert.True(TestReleaseOnReserveException(linkBadFirst: true)); Assert.True(TestReleaseOnReserveException(linkBadFirst: false)); Assert.True(TestMaxNumberOfGroups(greedy: true, sync: true)); Assert.True(TestMaxNumberOfGroups(greedy: true, sync: false)); // {non-greedy sync} is intentioanlly skipped because it is not supported by the block Assert.True(TestMaxNumberOfGroups(greedy: false, sync: false)); Assert.True(TestTriggerBatch(boundedCapacity: DataflowBlockOptions.Unbounded)); Assert.True(TestTriggerBatchRacingWithSendAsync(greedy: true)); Assert.True(TestTriggerBatchRacingWithSendAsync(greedy: false)); Assert.True(TestTriggerBatchRacingWithComplete(greedy: true)); Assert.True(TestTriggerBatchRacingWithComplete(greedy: false)); }
public void RunBufferBlockTests() { Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new BufferBlock <int>(new DataflowBlockOptions() { NameFormat = nameFormat }) : new BufferBlock <int>())); Assert.True(ISourceBlockTestHelper.TestLinkTo <int>(ConstructBufferNewWithNMessages(2), 1)); Assert.True(ISourceBlockTestHelper.TestReserveMessageAndReleaseReservation <int>(ConstructBufferNewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestConsumeMessage <int>(ConstructBufferNewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestTryReceiveWithFilter <int>(ConstructBufferNewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestTryReceiveAll <int>(ConstructBufferNewWithNMessages(1), 1)); Assert.True(ITargetBlockTestHelper.TestOfferMessage <int>(new BufferBlock <int>())); Assert.True(ITargetBlockTestHelper.TestPost <int>(new BufferBlock <int>())); Assert.True(ITargetBlockTestHelper.TestComplete <int>(new BufferBlock <int>())); Assert.True(ITargetBlockTestHelper.TestCompletionTask <int>(new BufferBlock <int>())); }
public void RunTransformManyBlockTests() { Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new TransformManyBlock <int, int>(x => new int[] { x }, new ExecutionDataflowBlockOptions() { NameFormat = nameFormat }) : new TransformManyBlock <int, int>(x => new int[] { x }))); Assert.True(ISourceBlockTestHelper.TestLinkTo <int>(ConstructTransformManyWithNMessages(2), 1)); Assert.True(ISourceBlockTestHelper.TestReserveMessageAndReleaseReservation <int>(ConstructTransformManyWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestConsumeMessage <int>(ConstructTransformManyWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestTryReceiveWithFilter <int>(ConstructTransformManyWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestTryReceiveAll <int>(ConstructTransformManyWithNMessages(1), 1)); Assert.True(ITargetBlockTestHelper.TestOfferMessage <int>(new TransformManyBlock <int, int>(i => new int[] { i }))); Assert.True(ITargetBlockTestHelper.TestPost <int>(new TransformManyBlock <int, int>(i => new int[] { i }))); Assert.True(ITargetBlockTestHelper.TestComplete <int>(new TransformManyBlock <int, int>(i => new int[] { i }))); Assert.True(ITargetBlockTestHelper.TestCompletionTask <int>(new TransformManyBlock <int, int>(i => new int[] { i }))); Assert.True(ITargetBlockTestHelper.TestNonGreedyPost(new TransformManyBlock <int, int>(x => { Task.Delay(500).Wait(); return(new int[] { x }); }, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 }))); }
public void RunTransformBlockTests() { Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new TransformBlock <int, int>(x => x, new ExecutionDataflowBlockOptions() { NameFormat = nameFormat }) : new TransformBlock <int, int>(x => x))); Assert.True(ISourceBlockTestHelper.TestLinkTo <string>(ConstructTransformWithNMessages(2), 1)); Assert.True(ISourceBlockTestHelper.TestReserveMessageAndReleaseReservation <string>(ConstructTransformWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestConsumeMessage <string>(ConstructTransformWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestTryReceiveWithFilter <string>(ConstructTransformWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestTryReceiveAll <string>(ConstructTransformWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestTargetOrder <int>(new TransformBlock <int, int>(x => x), 2)); Assert.True(ITargetBlockTestHelper.TestOfferMessage <int>(new TransformBlock <int, string>(i => i.ToString()))); Assert.True(ITargetBlockTestHelper.TestPost <int>(new TransformBlock <int, string>(i => i.ToString()))); Assert.True(ITargetBlockTestHelper.TestComplete <int>(new TransformBlock <int, string>(i => i.ToString()))); Assert.True(ITargetBlockTestHelper.TestCompletionTask <int>(new TransformBlock <int, string>(i => i.ToString()))); Assert.True(ITargetBlockTestHelper.TestNonGreedyPost(new TransformBlock <int, int>(x => { Task.Delay(5).Wait(); return(x); }, new ExecutionDataflowBlockOptions { BoundedCapacity = 1 }))); Assert.True(TestQuickStop(testThrow: false)); Assert.True(TestQuickStop(testThrow: true)); }
public void RunActionBlockTests() { Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new ActionBlock <int>(x => { }, new ExecutionDataflowBlockOptions() { NameFormat = nameFormat }) : new ActionBlock <int>(x => { }))); Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new ActionBlock <int>(x => { }, new ExecutionDataflowBlockOptions() { NameFormat = nameFormat, SingleProducerConstrained = true }) : new ActionBlock <int>(x => { }, new ExecutionDataflowBlockOptions() { SingleProducerConstrained = true }))); Assert.True(ITargetBlockTestHelper.TestArgumentsExceptions <int>(new ActionBlock <int>(i => { }))); Assert.True(ITargetBlockTestHelper.TestOfferMessage <int>(new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions { SingleProducerConstrained = true }))); Assert.True(ITargetBlockTestHelper.TestPost <int>(new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions { SingleProducerConstrained = true }))); Assert.True(ITargetBlockTestHelper.TestComplete <int>(new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions { SingleProducerConstrained = true }))); Assert.True(ITargetBlockTestHelper.TestCompletionTask <int>(new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions { SingleProducerConstrained = true }))); Assert.True(ITargetBlockTestHelper.TestNonGreedyPost(new ActionBlock <int>(x => { Task.Delay(1); }, new ExecutionDataflowBlockOptions() { BoundedCapacity = 1 }))); }