Esempio n. 1
0
        public virtual void CloseTest()
        {
            int count = 100;

            int[]      expected  = Enumerable.Range(0, count).ToArray();
            List <int> actualInt = new List <int>();
            Dictionary <string, string> testString = new Dictionary <string, string>()
            {
                { "val", "test" }
            };
            string queueName = "test-CloseTest" + Salt;

            using (ISubscribableChannel <Dictionary <string, string> > w = new mq.SubscribableChannel <Dictionary <string, string> >(queueName))
                using (IChannel <Dictionary <string, string> > c = new mq.Channel <Dictionary <string, string> >(queueName))
                {
                    IChannelReader <Dictionary <string, string> > t = w.Subscribe();

                    c.Close();

                    w.Write(testString);

                    Dictionary <string, string> result = t.Read();
                    Assert.IsTrue(result.ContainsKey("val"));
                    Assert.AreEqual(testString["val"], result["val"]);
                }
        }
Esempio n. 2
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());
                    }
        }
Esempio n. 3
0
        public virtual void SyncSelect_Timeout()
        {
            int expected = 3;

            using (IChannel <int> c0 = new Channel <int>())
                using (IChannel <int> c1 = new Channel <int>())
                    using (IChannel <int> c2 = new Channel <int>())
                    {
                        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(Timeblok * 5, c1, c2);
                        Assert.AreEqual(c0, res);
                        Assert.AreEqual(expected, res.Read());

                        Assert.IsNull(c1.SelectWith(Timeblok / 2, c2));
                    }
        }
Esempio n. 4
0
        public virtual void DifferentTypesTest()
        {
            int count = 100;

            int[]      expected   = Enumerable.Range(0, count).ToArray();
            List <int> actualInt  = new List <int>();
            string     testString = "test";
            string     queueName  = "test-DifferentTypesTest" + Salt;

            using (ISubscribableChannel <int> c = new mq.SubscribableChannel <int>(queueName))
                using (ISubscribableChannel <string> w = new mq.SubscribableChannel <string>(queueName))
                {
                    IChannelReader <string> t = w.Subscribe();
                    IChannelReader <int>    x = c.Subscribe();
                    Task.Factory.StartNew(() =>
                    {
                        for (int i = 0; i < count; i++)
                        {
                            if (i == 2)
                            {
                                w.Write(testString);
                            }
                            c.Write(i);
                        }

                        c.Close();
                    });

                    string val = t.Read();
                    foreach (int item in x.Enumerate())
                    {
                        actualInt.Add(item);
                    }
                    w.Write(testString + "1");
                    val = t.Read();

                    Assert.AreEqual(val, testString + "1");
                    Assert.IsFalse(t.Drained);
                    Assert.IsTrue(x.Drained);
                }
        }
Esempio n. 5
0
        public virtual void UntypedTypesTest2()
        {
            int count = 100;

            int[]      expected  = Enumerable.Range(0, count).ToArray();
            List <int> actualInt = new List <int>();
            Dictionary <string, string> testString = new Dictionary <string, string>()
            {
                { "val", "test" }
            };
            string queueName = "test-UntypedTypesTest2" + Salt;

            using (ISubscribableChannel <Dictionary <string, string> > w = new mq.SubscribableChannel <Dictionary <string, string> >(queueName))
            {
                IChannelReader <Dictionary <string, string> > t = w.Subscribe();

                #region bare rabbitmq
                ConnectionFactory fc = new ConnectionFactory()
                {
                    HostName = "code.test.aliaslab.net", Port = 5672, VirtualHost = "channels-lib", UserName = "******", Password = "******"
                };
                IConnection connection = fc.CreateConnection();
                IModel      _channel   = connection.CreateModel();

                _channel.BasicQos(0, 1, true);

                _channel.ExchangeDeclare(queueName, ExchangeType.Fanout, true, true, null);
                IBasicProperties prop = _channel.CreateBasicProperties();
                prop.ContentEncoding = "utf-8";
                prop.ContentType     = "application/json";
                prop.Persistent      = true;
                prop.Headers         = new Dictionary <string, object>();

                byte[] data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new { name = "piero", age = 13 }));
                _channel.BasicPublish(queueName, "test", prop, data);

                _channel.BasicPublish("channels-subscribableChannelCollectorExchange", $"{queueName}", prop, data);

                #endregion

                w.Write(testString);

                Dictionary <string, string> result = t.Read();
                Assert.IsTrue(result.ContainsKey("name"));
                Assert.AreEqual("piero", result["name"]);
            }
        }
Esempio n. 6
0
 public bool MoveNext()
 {
     if (_ch.Drained)
     {
         return(false);
     }
     else
     {
         try
         {
             Current = _ch.Read();
             return(true);
         }
         catch (ChannelDrainedException e)
         {
             return(false);
         }
     }
 }
Esempio n. 7
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();
                }
        }
Esempio n. 8
0
 public D Read()
 {
     return(Transform(_channel.Read()));
 }
Esempio n. 9
0
 public T Read()
 {
     return(_destiantion.Read());
 }