Exemplo n.º 1
0
        //[Fact(Skip = "Outerloop")]
        public void RunBoundingTests()
        {
            var options = new DataflowBlockOptions()
            {
                BoundedCapacity = ITargetBlockTestHelper.BOUNDED_CAPACITY
            };
            var executionOptions = new ExecutionDataflowBlockOptions()
            {
                BoundedCapacity = ITargetBlockTestHelper.BOUNDED_CAPACITY
            };
            var greedyOptions = new GroupingDataflowBlockOptions()
            {
                BoundedCapacity = ITargetBlockTestHelper.BOUNDED_CAPACITY, Greedy = true
            };
            var nonGreedyOptions = new GroupingDataflowBlockOptions()
            {
                BoundedCapacity = ITargetBlockTestHelper.BOUNDED_CAPACITY, Greedy = false
            };

            // "Normal" target blocks
            Assert.True(ITargetBlockTestHelper.TestBoundingTarget <int, int>(new ActionBlock <int>((Action <int>)ITargetBlockTestHelper.BoundingAction, executionOptions), greedy: true));

            // BatchBlock
            Assert.True(ITargetBlockTestHelper.TestBoundingTarget <int, int[]>(new BatchBlock <int>(ITargetBlockTestHelper.BOUNDED_CAPACITY, greedyOptions), greedy: true));
            Assert.True(ITargetBlockTestHelper.TestBoundingTarget <int, int[]>(new BatchBlock <int>(ITargetBlockTestHelper.BOUNDED_CAPACITY, nonGreedyOptions), greedy: false));

            // JoinBlock
            Assert.True(ITargetBlockTestHelper.TestBoundingJoin2 <int>(new JoinBlock <int, int>(greedyOptions), greedy: true));
            Assert.True(ITargetBlockTestHelper.TestBoundingJoin3 <int>(new JoinBlock <int, int, int>(nonGreedyOptions), greedy: false));

            // JoinBlock.Target
            Assert.True(ITargetBlockTestHelper.TestBoundingGreedyJoinTarget2 <int>(new JoinBlock <int, int>(greedyOptions), testedTargetIndex: 1));
            Assert.True(ITargetBlockTestHelper.TestBoundingGreedyJoinTarget3 <int>(new JoinBlock <int, int, int>(greedyOptions), testedTargetIndex: 2));
        }
Exemplo n.º 2
0
 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)));
 }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
 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())));
 }
Exemplo n.º 5
0
        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.");
        }
Exemplo n.º 6
0
        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.");
        }
Exemplo n.º 7
0
 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)));
 }
Exemplo n.º 8
0
 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
     })));
 }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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
            })));
        }
Exemplo n.º 11
0
 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)));
 }