2 // BatchedJoinBlockTest.cs
5 // Petr Onderka <gsvick@gmail.com>
7 // Copyright (c) 2012 Petr Onderka
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 using System.Collections.Generic;
29 using System.Threading;
30 using System.Threading.Tasks.Dataflow;
31 using NUnit.Framework;
33 namespace MonoTests.System.Threading.Tasks.Dataflow
36 public class BatchedJoinBlock3Test
39 public void BasicUsageTest()
41 Tuple<IList<int>, IList<int>, IList<string>> result = null;
42 var evt = new ManualResetEventSlim(false);
44 var actionBlock = new ActionBlock<Tuple<IList<int>, IList<int>, IList<string>>>(r =>
49 var block = new BatchedJoinBlock<int, int, string>(3);
51 block.LinkTo(actionBlock);
54 Assert.IsTrue(block.Target1.Post(1));
55 Assert.IsTrue(block.Target2.Post(2));
57 Assert.IsFalse (evt.Wait(100));
58 Assert.IsNull(result);
60 Assert.IsTrue(block.Target3.Post("foo"));
62 Assert.IsTrue(evt.Wait(100));
64 Assert.IsNotNull(result);
65 CollectionAssert.AreEqual(new[] { 1 }, result.Item1);
66 CollectionAssert.AreEqual(new[] { 2 }, result.Item2);
67 CollectionAssert.AreEqual(new[] { "foo" }, result.Item3);