예제 #1
0
        public virtual void SyncSelect()
        {
            int expected = 3;

            using (IChannel <int> c0 = new mq.Channel <int>("test-SyncSelect1" + Salt))
                using (IChannel <int> c1 = new mq.Channel <int>("test-SyncSelect2" + Salt))
                    using (IChannel <int> c2 = new mq.Channel <int>("test-SyncSelect3" + Salt))
                    {
                        Task.Factory.StartNew(() =>
                        {
                            Thread.Sleep(Timeblok);
                            c0.Write(expected);
                        });
                        Task.Factory.StartNew(() =>
                        {
                            Thread.Sleep(2 * Timeblok);
                            c1.Write(expected);
                        });
                        Task.Factory.StartNew(() =>
                        {
                            Thread.Sleep(3 * Timeblok);
                            c2.Write(expected);
                        });

                        IChannelReader <int> res = c0.SelectWith(c1, c2);
                        Assert.AreEqual(c0, res);
                        Assert.AreEqual(expected, res.Read());
                    }
        }
예제 #2
0
        public virtual void ConcurretSingleQueue()
        {
            string salt = Salt;

            using (IChannel <int> c1 = new mq.Channel <int>("test-ConcurretSingleQueue" + salt))
                using (IChannel <int> c2 = new mq.Channel <int>("test-ConcurretSingleQueue" + salt))
                {
                    c2.Write(1);
                    c1.Write(2);

                    IChannelReader <int> x = c1.SelectWith(c2);

                    Assert.AreEqual(1, x.Read());

                    IChannelReader <int> y = c1.SelectWith(c2);

                    Assert.AreNotEqual(x, y);
                    Assert.AreEqual(2, y.Read());
                    Console.WriteLine();
                }
        }