Exemplo n.º 1
0
        public virtual void ShovelTest()
        {
            int count = 100;

            int[]         expected = Enumerable.Range(0, count).ToArray();
            List <string> actual   = new List <string>();

            using (IChannel <int> c = new mq.Channel <int>("test-ShovelTest1" + Salt))
                using (IChannel <string> w = new mq.Channel <string>("test-ShovelTest2" + Salt))
                {
                    Task.Factory.StartNew(() =>
                    {
                        for (int i = 0; i < count; i++)
                        {
                            c.Write(i);
                        }

                        c.Close();
                    });

                    AbstractShovelThread <int, string> th = c.ShovelTo <int, string>(w, p => p.ToString(), TimeSpan.FromSeconds(10), true);
                    th.StoppedEvent += e => Assert.IsInstanceOfType(e, typeof(ChannelDrainedException));

                    foreach (string item in w.Enumerate())
                    {
                        actual.Add(item);
                    }

                    Assert.AreEqual(count, actual.Count);
                    CollectionAssert.AreEquivalent(expected.Select(p => p.ToString()).ToArray(), actual);
                }
        }