Esempio n. 1
0
        public async Task TestOfferMessage()
        {
            var generators = new Func <TransformBlock <int, int> >[]
            {
                () => new TransformBlock <int, int>(i => i),
                () => new TransformBlock <int, int>(i => i, new ExecutionDataflowBlockOptions {
                    BoundedCapacity = 10
                }),
                () => new TransformBlock <int, int>(i => Task.Run(() => i), new ExecutionDataflowBlockOptions {
                    BoundedCapacity = 10, MaxMessagesPerTask = 1
                })
            };

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

                var target = generator();
                DataflowTestHelpers.TestOfferMessage_AcceptsDataDirectly(target);
                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);

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

                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
            }
        }
Esempio n. 2
0
        public async Task TestOfferMessage()
        {
            var generators = new Func <BatchBlock <int> >[]
            {
                () => new BatchBlock <int>(2),
                () => new BatchBlock <int>(2, new GroupingDataflowBlockOptions {
                    MaxMessagesPerTask = 1
                })
            };

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

                var target = generator();
                DataflowTestHelpers.TestOfferMessage_AcceptsDataDirectly(target, messages: target.BatchSize * 2);
                IList <int[]> items;
                Assert.True(target.TryReceiveAll(out items));
                Assert.Equal(expected: 2, actual: items.Count);
                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
                await target.Completion;

                target = generator();
                await DataflowTestHelpers.TestOfferMessage_AcceptsViaLinking(target, messages : target.BatchSize * 2);

                Assert.True(target.TryReceiveAll(out items));
                Assert.Equal(expected: 2, actual: items.Count);
                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
                await target.Completion;
            }
        }
        public async Task TestOfferMessage()
        {
            var generators = new Func <ActionBlock <int> >[]
            {
                () => new ActionBlock <int>(i => { }),
                () => new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions {
                    BoundedCapacity = 10
                }),
                () => new ActionBlock <int>(i => { }, new ExecutionDataflowBlockOptions {
                    BoundedCapacity = 10, MaxMessagesPerTask = 1, MaxDegreeOfParallelism = 4
                })
            };

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

                var target = generator();
                DataflowTestHelpers.TestOfferMessage_AcceptsDataDirectly(target);
                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
                await target.Completion;

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

                DataflowTestHelpers.TestOfferMessage_CompleteAndOffer(target);
                await target.Completion;
            }
        }
        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());
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
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;
            }
        }