Added BatchedJoinBlock`3
[mono.git] / mcs / class / System.Threading.Tasks.Dataflow / Test / System.Threading.Tasks.Dataflow / BatchedJoinBlock`3Test.cs
1 // 
2 // BatchedJoinBlockTest.cs
3 //  
4 // Author:
5 //       Petr Onderka <gsvick@gmail.com>
6 // 
7 // Copyright (c) 2012 Petr Onderka
8 // 
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:
15 // 
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 // 
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
25 // THE SOFTWARE.
26
27 using System;
28 using System.Collections.Generic;
29 using System.Threading;
30 using System.Threading.Tasks.Dataflow;
31 using NUnit.Framework;
32
33 namespace MonoTests.System.Threading.Tasks.Dataflow
34 {
35         [TestFixture]
36         public class BatchedJoinBlock3Test
37         {
38                 [Test]
39                 public void BasicUsageTest()
40                 {
41                         Tuple<IList<int>, IList<int>, IList<string>> result = null;
42                         var evt = new ManualResetEventSlim(false);
43
44                         var actionBlock = new ActionBlock<Tuple<IList<int>, IList<int>, IList<string>>>(r =>
45                         {
46                                 result = r;
47                                 evt.Set();
48                         });
49                         var block = new BatchedJoinBlock<int, int, string>(3);
50
51                         block.LinkTo(actionBlock);
52
53                         // all targets once
54                         Assert.IsTrue(block.Target1.Post(1));
55                         Assert.IsTrue(block.Target2.Post(2));
56
57                         Assert.IsFalse (evt.Wait(100));
58                         Assert.IsNull(result);
59
60                         Assert.IsTrue(block.Target3.Post("foo"));
61
62                         Assert.IsTrue(evt.Wait(100));
63
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);
68                 }
69         }
70 }