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 TestBatchInvalidArgumentValidation() { Assert.Throws <ArgumentOutOfRangeException>(() => new BatchBlock <int>(-1)); Assert.Throws <ArgumentNullException>(() => new BatchBlock <int>(2, null)); Assert.True(ITargetBlockTestHelper.TestArgumentsExceptions <int>(new BatchBlock <int>(1))); Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <int[]>(new BatchBlock <int>(1))); }
public void TestTransformBlockInvalidArgumentValidation() { Assert.Throws <ArgumentNullException>(() => new TransformBlock <int, string>((Func <int, string>)null)); Assert.Throws <ArgumentNullException>(() => new TransformBlock <int, string>((Func <int, Task <string> >)null)); Assert.Throws <ArgumentNullException>(() => new TransformBlock <int, string>(i => i.ToString(), null)); Assert.Throws <ArgumentNullException>(() => new TransformBlock <int, string>(i => Task.Run(() => i.ToString()), null)); Assert.True(ITargetBlockTestHelper.TestArgumentsExceptions <int>(new TransformBlock <int, string>(i => i.ToString()))); Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <string>(new TransformBlock <int, string>(i => i.ToString()))); }
public void TestWriteOnceInvalidArgumentValidation() { bool passed = true; Assert.Throws <ArgumentNullException>(() => new WriteOnceBlock <int>(i => i, null)); passed &= ITargetBlockTestHelper.TestArgumentsExceptions <int>(new WriteOnceBlock <int>(i => i)); passed &= ISourceBlockTestHelper.TestArgumentsExceptions <int>(new WriteOnceBlock <int>(i => i)); Assert.True(passed, "Argument Validation failed."); }
public void TestJoinInvalidArgumentValidation() { Assert.Throws <ArgumentNullException>(() => new JoinBlock <int, int>(null)); Assert.Throws <ArgumentNullException>(() => new JoinBlock <int, int, int>(null)); Assert.Throws <NotSupportedException>(() => { var ignored = new JoinBlock <int, int>().Target1.Completion; }); Assert.Throws <NotSupportedException>(() => { var ignored = new JoinBlock <int, int, int>().Target3.Completion; }); Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <Tuple <int, int> >(new JoinBlock <int, int>())); Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <Tuple <int, int, int> >(new JoinBlock <int, int, int>())); }
public void TestTransformManyBlockInvalidArgumentValidation() { bool passed = true; Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, string>((Func <int, IEnumerable <string> >)null)); Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, string>((Func <int, Task <IEnumerable <string> > >)null)); Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, string>(i => new[] { i.ToString() }, null)); Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, string>(i => Task.Run(() => (IEnumerable <string>) new[] { i.ToString() }), null)); passed &= ITargetBlockTestHelper.TestArgumentsExceptions <int>(new TransformManyBlock <int, int>(i => new int[] { i })); passed &= ISourceBlockTestHelper.TestArgumentsExceptions <int>(new TransformManyBlock <int, int>(i => new int[] { i })); Assert.True(passed, "Test failed."); }
public void RunBroadcastBlockTests() { Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new BroadcastBlock <int>(null, new DataflowBlockOptions() { NameFormat = nameFormat }) : new BroadcastBlock <int>(null))); Assert.True(ISourceBlockTestHelper.TestLinkTo <int>(ConstructBroadcastNewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestReserveMessageAndReleaseReservation <int>(ConstructBroadcastNewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestConsumeMessage <int>(ConstructBroadcastNewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestTryReceiveWithFilter <int>(ConstructBroadcastNewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestTargetOrder <int>(new BroadcastBlock <int>(i => i), 1)); Assert.True(ITargetBlockTestHelper.TestPost <int>(new BroadcastBlock <int>(i => i))); Assert.True(ITargetBlockTestHelper.TestCompletionTask <int>(new BroadcastBlock <int>(i => i))); }
public void RunBatchedJoinBlockTests() { // BatchedJoinBlock`2 Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new BatchedJoinBlock <int, int>(1, new GroupingDataflowBlockOptions() { NameFormat = nameFormat }) : new BatchedJoinBlock <int, int>(1))); Assert.True(ISourceBlockTestHelper.TestLinkTo <Tuple <IList <int>, IList <int> > >(ConstructBatchedJoin2NewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestReserveMessageAndReleaseReservation <Tuple <IList <int>, IList <int> > >(ConstructBatchedJoin2NewWithNMessages(1))); //Assert.True(ISourceBlockTestHelper.TestReleaseReservation<Tuple<IList<int>, IList<int>>>(ConstructBatchedJoin2NewWithNMessages(1))); // BatchedJoinBlock`3 Assert.True(ISourceBlockTestHelper.TestConsumeMessage <Tuple <IList <int>, IList <int>, IList <int> > >(ConstructBatchedJoin3NewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestTryReceiveWithFilter <Tuple <IList <int>, IList <int>, IList <int> > >(ConstructBatchedJoin3NewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestTryReceiveAll <Tuple <IList <int>, IList <int>, IList <int> > >(ConstructBatchedJoin3NewWithNMessages(1), 1)); }
public void TestBatchedJoinInvalidArgumentValidation() { Assert.Throws <ArgumentOutOfRangeException>(() => new BatchedJoinBlock <int, int>(0)); Assert.Throws <ArgumentNullException>(() => new BatchedJoinBlock <int, int>(1, null)); Assert.Throws <ArgumentException>(() => new BatchedJoinBlock <int, int>(1, new GroupingDataflowBlockOptions { Greedy = false })); Assert.Throws <NotSupportedException>(() => { var ignored = new BatchedJoinBlock <int, int>(2).Target1.Completion; }); Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <Tuple <IList <int>, IList <int> > >(new BatchedJoinBlock <int, int>(2))); Assert.Throws <ArgumentOutOfRangeException>(() => new BatchedJoinBlock <int, int, int>(0)); Assert.Throws <ArgumentNullException>(() => new BatchedJoinBlock <int, int, int>(1, null)); Assert.Throws <ArgumentException>(() => new BatchedJoinBlock <int, int, int>(1, new GroupingDataflowBlockOptions { Greedy = false })); Assert.Throws <NotSupportedException>(() => { var ignored = new BatchedJoinBlock <int, int, int>(2).Target3.Completion; }); Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <Tuple <IList <int>, IList <int>, IList <int> > >(new BatchedJoinBlock <int, int, int>(2))); }
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 RunJoinBlockTests() { Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new JoinBlock <int, int>(new GroupingDataflowBlockOptions() { NameFormat = nameFormat }) : new JoinBlock <int, int>())); Assert.True(IDataflowBlockTestHelper.TestToString(nameFormat => nameFormat != null ? new JoinBlock <int, int, int>(new GroupingDataflowBlockOptions() { NameFormat = nameFormat }) : new JoinBlock <int, int, int>())); Assert.True(ISourceBlockTestHelper.TestLinkTo <Tuple <int, int> >(ConstructJoinNewWithNMessages(2), 1)); Assert.True(ISourceBlockTestHelper.TestReserveMessageAndReleaseReservation <Tuple <int, int> >(ConstructJoinNewWithNMessages(1))); //Assert.True(ISourceBlockTestHelper.TestReleaseReservation<Tuple<int, int>>(ConstructJoinNewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestConsumeMessage <Tuple <int, int> >(ConstructJoinNewWithNMessages(1))); Assert.True(ISourceBlockTestHelper.TestTryReceiveWithFilter <Tuple <int, int> >(ConstructJoinNewWithNMessages(1), 1)); Assert.True(ISourceBlockTestHelper.TestTryReceiveAll <Tuple <int, int> >(ConstructJoinNewWithNMessages(1), 1)); Assert.True(TestJoinMaxNumberOfGroups(greedy: true, sync: true)); Assert.True(TestJoinMaxNumberOfGroups(greedy: true, sync: false)); // {non-greedy sync} is intentioanlly skipped because it is not supported by the block Assert.True(TestJoinMaxNumberOfGroups(greedy: false, sync: false)); }
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 TestBroadcastBlockInvalidArgumentValidation() { Assert.Throws <ArgumentNullException>(() => new BroadcastBlock <int>(i => i, null)); Assert.True(ITargetBlockTestHelper.TestArgumentsExceptions <int>(new BroadcastBlock <int>(i => i))); Assert.True(ISourceBlockTestHelper.TestArgumentsExceptions <int>(new BroadcastBlock <int>(i => i))); }
public void RunConcurrentTests() { int[] item1; Assert.True(TestConcurrently("BatchBlock", "TryReceive", s => s.TryReceive(out item1), ConstructBatchNewWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as IReceivableSourceBlock <int[]>, true)); Tuple <IList <int>, IList <int> > item2; Assert.True(TestConcurrently("BatchedJoinBlock", "TryReceive", s => s.TryReceive(out item2), ConstructBatchedJoin2NewWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as IReceivableSourceBlock <Tuple <IList <int>, IList <int> > >, true)); int item3; Assert.True(TestConcurrently("BroadcastBlock", "TryReceive", s => s.TryReceive(out item3), ConstructBroadcastNewWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as IReceivableSourceBlock <int>, true)); int item4; Assert.True(TestConcurrently("BufferBlock", "TryReceive", s => s.TryReceive(out item4), ConstructBufferNewWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as IReceivableSourceBlock <int>, true)); Tuple <int, int> item5; Assert.True(TestConcurrently("JoinBlock", "TryReceive", s => s.TryReceive(out item5), ConstructJoinNewWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as IReceivableSourceBlock <Tuple <int, int> >, true)); string item6; Assert.True(TestConcurrently("TransformBlock", "TryReceive", s => s.TryReceive(out item6), ConstructTransformWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as IReceivableSourceBlock <string>, true)); int item7; Assert.True(TestConcurrently("TransformManyBlock", "TryReceive", s => s.TryReceive(out item7), ConstructTransformManyWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as IReceivableSourceBlock <int>, true)); int item8; Assert.True(TestConcurrently("WriteOnceBlock", "TryReceive", s => s.TryReceive(out item8), ConstructWriteOnceNewWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as IReceivableSourceBlock <int>, true)); Assert.True(TestConcurrently("BatchBlock", "OfferMessage", t => t.OfferMessage(new DataflowMessageHeader(1), default(int), null, false), // Message ID doesn't matter because consumeTosAccept:false new BatchBlock <int>(1) as ITargetBlock <int>, DataflowMessageStatus.Accepted)); Assert.True(TestConcurrently("BatchBlock", "Post", t => t.Post(default(int)), new BatchBlock <int>(1), true)); Assert.True(TestConcurrently("ActionBlock", "OfferMessage", t => t.OfferMessage(new DataflowMessageHeader(1), default(int), null, false), // Message ID doesn't matter because consumeTosAccept:false new ActionBlock <int>(i => { }) as ITargetBlock <int>, DataflowMessageStatus.Accepted)); Assert.True(TestConcurrently("ActionBlock", "Post", t => t.Post(default(int)), new ActionBlock <int>(i => { }), true)); Assert.True(TestConcurrently("TransformBlock", "OfferMessage", t => t.OfferMessage(new DataflowMessageHeader(1), default(int), null, false), // Message ID doesn't matter because consumeTosAccept:false new TransformBlock <int, string>(i => i.ToString()) as ITargetBlock <int>, DataflowMessageStatus.Accepted)); Assert.True(TestConcurrently("TransformBlock", "Post", t => t.Post(default(int)), new TransformBlock <int, string>(i => i.ToString()), true)); Assert.True(TestConcurrently("BroadcastBlock", "OfferMessage", t => t.OfferMessage(new DataflowMessageHeader(1), default(int), null, false), // Message ID doesn't matter because consumeTosAccept:false new BroadcastBlock <int>(i => i) as ITargetBlock <int>, DataflowMessageStatus.Accepted)); Assert.True(TestConcurrently("BroadcastBlock", "Post", t => t.Post(default(int)), new BroadcastBlock <int>(i => i), true)); Assert.True(TestConcurrently("BufferBlock", "OfferMessage", t => t.OfferMessage(new DataflowMessageHeader(1), default(int), null, false), // Message ID doesn't matter because consumeTosAccept:false new BufferBlock <int>() as ITargetBlock <int>, DataflowMessageStatus.Accepted)); Assert.True(TestConcurrently("BufferBlock", "Post", t => t.Post(default(int)), new BufferBlock <int>(), true)); Assert.True(TestConcurrently("TransformManyBlock", "OfferMessage", t => t.OfferMessage(new DataflowMessageHeader(1), default(int), null, false), // Message ID doesn't matter because consumeTosAccept:false new TransformManyBlock <int, int>(i => new int[] { i }) as ITargetBlock <int>, DataflowMessageStatus.Accepted)); Assert.True(TestConcurrently("TransformManyBlock", "Post", t => t.Post(default(int)), new TransformManyBlock <int, int>(i => new int[] { i }), true)); // Intentionally skipping testing OfferMessage and Post concurrently. Assert.True(TestConcurrently("WriteOnceBlock", "ConsumeMessage", s => ISourceBlockTestHelper.TestConsumeMessage(s), ConstructWriteOnceNewWithNMessages(Parallelism.ActualDegreeOfParallelism * s_iterationCount) as ISourceBlock <int>, true)); }