public void TestToString()
 {
     // Test ToString() with the only custom configuration being NameFormat
     DataflowTestHelpers.TestToString(
         nameFormat => nameFormat != null ?
         new WriteOnceBlock <int>(i => i, new DataflowBlockOptions()
     {
         NameFormat = nameFormat
     }) :
         new WriteOnceBlock <int>(i => i));
 }
        public async Task TestOfferMessage3()
        {
            Func <ITargetBlock <int> > generator = () => {
                var b = new BatchedJoinBlock <int, int, int>(1);
                return(b.Target1);
            };

            DataflowTestHelpers.TestOfferMessage_ArgumentValidation(generator());
            DataflowTestHelpers.TestOfferMessage_AcceptsDataDirectly(generator());
            await DataflowTestHelpers.TestOfferMessage_AcceptsViaLinking(generator());
        }
예제 #3
0
        public async Task TestReserveReleaseConsume()
        {
            var bb = new BroadcastBlock <int>(i => i * 2);

            bb.Post(1);
            await DataflowTestHelpers.TestReserveAndRelease(bb, reservationIsTargetSpecific : false);

            bb = new BroadcastBlock <int>(i => i * 2);
            bb.Post(2);
            await DataflowTestHelpers.TestReserveAndConsume(bb, reservationIsTargetSpecific : false);
        }
        public async Task TestReserveReleaseConsume()
        {
            var wb = new WriteOnceBlock <int>(i => i * 2);

            wb.Post(1);
            await DataflowTestHelpers.TestReserveAndRelease(wb, reservationIsTargetSpecific : false);

            wb = new WriteOnceBlock <int>(i => i * 2);
            wb.Post(2);
            await DataflowTestHelpers.TestReserveAndConsume(wb, reservationIsTargetSpecific : false);
        }
예제 #5
0
        public async Task TestReserveReleaseConsume()
        {
            var bb = new BufferBlock <int>();

            bb.Post(1);
            await DataflowTestHelpers.TestReserveAndRelease(bb);

            bb = new BufferBlock <int>();
            bb.Post(2);
            await DataflowTestHelpers.TestReserveAndConsume(bb);
        }
예제 #6
0
        public async Task TestReserveReleaseConsume()
        {
            var tb = new TransformBlock <int, int>(i => i * 2);

            tb.Post(1);
            await DataflowTestHelpers.TestReserveAndRelease(tb);

            tb = new TransformBlock <int, int>(i => i * 2);
            tb.Post(2);
            await DataflowTestHelpers.TestReserveAndConsume(tb);
        }
예제 #7
0
        public async Task TestReserveReleaseConsume()
        {
            var bb = new BatchBlock <int>(2);

            bb.PostItems(1, 2);
            await DataflowTestHelpers.TestReserveAndRelease(bb);

            bb = new BatchBlock <int>(2);
            bb.PostItems(1, 2);
            await DataflowTestHelpers.TestReserveAndConsume(bb);
        }
예제 #8
0
        public void TestArgumentExceptions()
        {
            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.Throws <ArgumentNullException>(() => new JoinBlock <int, int>().Target1.Fault(null));
            Assert.Throws <ArgumentException>(() => new JoinBlock <int, int>().Target1.OfferMessage(default(DataflowMessageHeader), 1, null, false));
            Assert.Throws <ArgumentException>(() => new JoinBlock <int, int>().Target1.OfferMessage(new DataflowMessageHeader(1), 1, null, true));

            DataflowTestHelpers.TestArgumentsExceptions <Tuple <int, int> >(new JoinBlock <int, int>());
            DataflowTestHelpers.TestArgumentsExceptions <Tuple <int, int, int> >(new JoinBlock <int, int, int>());
        }
예제 #9
0
 public void TestToString()
 {
     DataflowTestHelpers.TestToString(
         nameFormat => nameFormat != null ?
         new JoinBlock <int, string>(new GroupingDataflowBlockOptions()
     {
         NameFormat = nameFormat
     }) :
         new JoinBlock <int, string>());
     DataflowTestHelpers.TestToString(
         nameFormat => nameFormat != null ?
         new JoinBlock <int, string, double>(new GroupingDataflowBlockOptions()
     {
         NameFormat = nameFormat
     }) :
         new JoinBlock <int, string, double>());
 }
예제 #10
0
 public void TestPost()
 {
     foreach (bool bounded in DataflowTestHelpers.BooleanValues)
     {
         foreach (var tb in new[] {
             new TransformManyBlock <int, int>(DataflowTestHelpers.ToEnumerable, new ExecutionDataflowBlockOptions {
                 BoundedCapacity = bounded ? 1 : -1
             }),
             new TransformManyBlock <int, int>(i => Task.Run(() => DataflowTestHelpers.ToEnumerable(i)), new ExecutionDataflowBlockOptions {
                 BoundedCapacity = bounded ? 1 : -1
             })
         })
         {
             Assert.True(tb.Post(0));
             tb.Complete();
             Assert.False(tb.Post(0));
         }
     }
 }
예제 #11
0
 public async Task TestChainedSendReceive()
 {
     foreach (bool post in DataflowTestHelpers.BooleanValues)
     {
         const int Iters   = 10;
         var       network = DataflowTestHelpers.Chain <BufferBlock <int>, int>(4, () => new BufferBlock <int>());
         for (int i = 0; i < Iters; i++)
         {
             if (post)
             {
                 network.Post(i);
             }
             else
             {
                 await network.SendAsync(i);
             }
             Assert.Equal(expected: i, actual: await network.ReceiveAsync());
         }
     }
 }
예제 #12
0
        public async Task TestSendAllThenReceive()
        {
            foreach (bool post in DataflowTestHelpers.BooleanValues)
            {
                const int Iters   = 10;
                var       network = DataflowTestHelpers.Chain <BufferBlock <int>, int>(4, () => new BufferBlock <int>());

                if (post)
                {
                    network.PostRange(0, Iters);
                }
                else
                {
                    await Task.WhenAll(from i in Enumerable.Range(0, Iters) select network.SendAsync(i));
                }

                for (int i = 0; i < Iters; i++)
                {
                    Assert.Equal(expected: i, actual: await network.ReceiveAsync());
                }
            }
        }
예제 #13
0
        public async Task TestOfferMessage()
        {
            var generators = new Func <BufferBlock <int> >[]
            {
                () => new BufferBlock <int>(),
                () => new BufferBlock <int>(new DataflowBlockOptions {
                    BoundedCapacity = 10
                }),
                () => new BufferBlock <int>(new DataflowBlockOptions {
                    BoundedCapacity = 10, MaxMessagesPerTask = 1
                })
            };

            foreach (var generator in generators)
            {
                DataflowTestHelpers.TestOfferMessage_ArgumentValidation(generator());

                var target = generator();
                DataflowTestHelpers.TestOfferMessage_AcceptsDataDirectly(target);
                int ignored;
                while (target.TryReceive(out ignored))
                {
                    ;
                }
                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
                await target.Completion;

                target = generator();
                await DataflowTestHelpers.TestOfferMessage_AcceptsViaLinking(target);

                while (target.TryReceive(out ignored))
                {
                    ;
                }
                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
                await target.Completion;
            }
        }
예제 #14
0
        public async Task TestOfferMessage()
        {
            var generators = new Func <WriteOnceBlock <int> >[]
            {
                () => new WriteOnceBlock <int>(i => i),
                () => new WriteOnceBlock <int>(i => i, new DataflowBlockOptions {
                    BoundedCapacity = 10
                }),
                () => new WriteOnceBlock <int>(i => i, new DataflowBlockOptions {
                    BoundedCapacity = 10, MaxMessagesPerTask = 1
                })
            };

            foreach (var generator in generators)
            {
                DataflowTestHelpers.TestOfferMessage_ArgumentValidation(generator());

                var target = generator();
                DataflowTestHelpers.TestOfferMessage_AcceptsDataDirectly(target, messages: 1);
                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
                await target.Completion;

                target = generator();
                await DataflowTestHelpers.TestOfferMessage_AcceptsViaLinking(target, messages : 1);

                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
                await target.Completion;

                target = generator();
                Assert.Equal(
                    expected: DataflowMessageStatus.Accepted,
                    actual: ((ITargetBlock <int>)target).OfferMessage(new DataflowMessageHeader(1), 1, null, false));
                Assert.Equal(
                    expected: DataflowMessageStatus.DecliningPermanently,
                    actual: ((ITargetBlock <int>)target).OfferMessage(new DataflowMessageHeader(1), 1, null, false));
                await target.Completion;
            }
        }
        public void TestToString()
        {
            // Test ToString() with the only custom configuration being NameFormat
            DataflowTestHelpers.TestToString(
                nameFormat => nameFormat != null ?
                new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions()
            {
                NameFormat = nameFormat
            }) :
                new ActionBlock <int>(i => { }));

            // Test ToString() with other configuration
            DataflowTestHelpers.TestToString(
                nameFormat => nameFormat != null ?
                new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions()
            {
                NameFormat = nameFormat, SingleProducerConstrained = true
            }) :
                new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions()
            {
                SingleProducerConstrained = true
            }));
        }
예제 #16
0
        public void TestArgumentExceptions()
        {
            Assert.Throws <ArgumentOutOfRangeException>(() => new BatchedJoinBlock <int, string>(-1));
            Assert.Throws <ArgumentNullException>(() => new BatchedJoinBlock <int, string>(2, null));
            Assert.Throws <ArgumentException>(() => new BatchedJoinBlock <int, string>(2, new GroupingDataflowBlockOptions {
                Greedy = false
            }));
            Assert.Throws <ArgumentException>(() => new BatchedJoinBlock <int, string>(2, new GroupingDataflowBlockOptions {
                BoundedCapacity = 2
            }));

            Assert.Throws <ArgumentOutOfRangeException>(() => new BatchedJoinBlock <int, string, double>(-1));
            Assert.Throws <ArgumentNullException>(() => new BatchedJoinBlock <int, string, double>(2, null));
            Assert.Throws <ArgumentException>(() => new BatchedJoinBlock <int, string, double>(2, new GroupingDataflowBlockOptions {
                Greedy = false
            }));
            Assert.Throws <ArgumentException>(() => new BatchedJoinBlock <int, string, double>(2, new GroupingDataflowBlockOptions {
                BoundedCapacity = 2
            }));

            DataflowTestHelpers.TestArgumentsExceptions(new BatchedJoinBlock <int, string>(1));
            DataflowTestHelpers.TestArgumentsExceptions(new BatchedJoinBlock <int, string, double>(1));
        }
예제 #17
0
        public async Task TestCtor()
        {
            var blocks = new[] {
                new TransformManyBlock <int, int>(DataflowTestHelpers.ToEnumerable),
                new TransformManyBlock <int, int>(DataflowTestHelpers.ToEnumerable, new ExecutionDataflowBlockOptions {
                    MaxMessagesPerTask = 1
                }),
                new TransformManyBlock <int, int>(i => Task.Run(() => DataflowTestHelpers.ToEnumerable(i)), new ExecutionDataflowBlockOptions {
                    MaxMessagesPerTask = 1
                })
            };

            foreach (var block in blocks)
            {
                Assert.Equal(expected: 0, actual: block.InputCount);
                Assert.Equal(expected: 0, actual: block.OutputCount);
                Assert.False(block.Completion.IsCompleted);
            }

            blocks = new[] {
                new TransformManyBlock <int, int>(DataflowTestHelpers.ToEnumerable,
                                                  new ExecutionDataflowBlockOptions {
                    CancellationToken = new CancellationToken(true)
                }),
                new TransformManyBlock <int, int>(i => Task.Run(() => DataflowTestHelpers.ToEnumerable(i)),
                                                  new ExecutionDataflowBlockOptions {
                    CancellationToken = new CancellationToken(true)
                })
            };
            foreach (var block in blocks)
            {
                Assert.Equal(expected: 0, actual: block.InputCount);
                Assert.Equal(expected: 0, actual: block.OutputCount);
                await Assert.ThrowsAnyAsync <OperationCanceledException>(() => block.Completion);
            }
        }
예제 #18
0
 public void TestArgumentExceptions()
 {
     Assert.Throws <ArgumentNullException>(() => new WriteOnceBlock <int>(i => i, null));
     DataflowTestHelpers.TestArgumentsExceptions(new WriteOnceBlock <int>(i => i));
     Assert.Throws <ArgumentNullException>(() => ((ITargetBlock <int>) new WriteOnceBlock <int>(null)).Fault(null));
 }
예제 #19
0
 public async Task TestCompletionTask()
 {
     await DataflowTestHelpers.TestCompletionTask(() => new WriteOnceBlock <int>(i => i));
 }
예제 #20
0
        public void TestArgumentExceptions()
        {
            Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, int>((Func <int, IEnumerable <int> >)null));
            Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, int>((Func <int, Task <IEnumerable <int> > >)null));
            Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, int>(DataflowTestHelpers.ToEnumerable, null));
            Assert.Throws <ArgumentNullException>(() => new TransformManyBlock <int, int>(i => Task.Run(() => DataflowTestHelpers.ToEnumerable(i)), null));

            DataflowTestHelpers.TestArgumentsExceptions(new TransformManyBlock <int, int>(DataflowTestHelpers.ToEnumerable));
        }
 public async Task TestCompletionTask()
 {
     await DataflowTestHelpers.TestCompletionTask(() => new ActionBlock <int>(i => { }));
 }
 public Task TestCompletionTaskAsyncEnumerable()
 {
     return(DataflowTestHelpers.TestCompletionTask(() => new TransformManyBlock <int, int>(DataflowTestHelpers.ToAsyncEnumerable)));
 }
예제 #23
0
 public void TestArgumentExceptions()
 {
     Assert.Throws <ArgumentNullException>(() => new BufferBlock <int>(null));
     DataflowTestHelpers.TestArgumentsExceptions(new BufferBlock <int>());
 }
예제 #24
0
 public Task TestCompletionTask()
 {
     return(DataflowTestHelpers.TestCompletionTask(() => new BufferBlock <int>()));
 }
예제 #25
0
 public Task TestCompletionTask()
 {
     return(DataflowTestHelpers.TestCompletionTask(() => new TransformBlock <int, int>(i => i)));
 }