Пример #1
0
        public void SubToBatch()
        {
            Channel <string>   channel = new Channel <string>();
            StubCommandContext queue   = new StubCommandContext();
            bool received = false;
            Action <IList <string> > onReceive = delegate(IList <string> data)
            {
                Assert.AreEqual(5, data.Count);
                Assert.AreEqual("0", data[0]);
                Assert.AreEqual("4", data[4]);
                received = true;
            };

            channel.SubscribeToBatch(queue, onReceive, 0);

            for (int i = 0; i < 5; i++)
            {
                channel.Publish(i.ToString());
            }
            Assert.AreEqual(1, queue.Scheduled.Count);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            queue.Scheduled.Clear();
            received = false;

            channel.Publish("5");
            Assert.IsFalse(received);
            Assert.AreEqual(1, queue.Scheduled.Count);
        }
Пример #2
0
        public void SubscribeToLast()
        {
            Channel <int>      channel = new Channel <int>();
            StubCommandContext queue   = new StubCommandContext();
            bool         received      = false;
            int          lastReceived  = -1;
            Action <int> onReceive     = delegate(int data)
            {
                lastReceived = data;
                received     = true;
            };

            channel.SubscribeToLast(queue, onReceive, 0);

            for (int i = 0; i < 5; i++)
            {
                channel.Publish(i);
            }
            Assert.AreEqual(1, queue.Scheduled.Count);
            Assert.IsFalse(received);
            Assert.AreEqual(-1, lastReceived);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            Assert.AreEqual(4, lastReceived);
            queue.Scheduled.Clear();
            received     = false;
            lastReceived = -1;
            channel.Publish(5);
            Assert.IsFalse(received);
            Assert.AreEqual(1, queue.Scheduled.Count);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            Assert.AreEqual(5, lastReceived);
        }
Пример #3
0
        public void SubToKeyedBatch()
        {
            Channel <KeyValuePair <string, string> > channel = new Channel <KeyValuePair <string, string> >();
            StubCommandContext queue = new StubCommandContext();
            bool received            = false;
            Action <IDictionary <string, KeyValuePair <string, string> > > onReceive =
                delegate(IDictionary <string, KeyValuePair <string, string> > data)
            {
                Assert.AreEqual(2, data.Keys.Count);
                Assert.AreEqual(data["0"], new KeyValuePair <string, string>("0", "4"));
                Assert.AreEqual(data["1"], new KeyValuePair <string, string>("1", "3"));
                received = true;
            };
            Converter <KeyValuePair <string, string>, string> key =
                delegate(KeyValuePair <string, string> pair) { return(pair.Key); };

            channel.SubscribeToKeyedBatch(queue, key, onReceive, 0);

            for (int i = 0; i < 5; i++)
            {
                channel.Publish(new KeyValuePair <string, string>((i % 2).ToString(), i.ToString()));
            }
            Assert.AreEqual(1, queue.Scheduled.Count);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            queue.Scheduled.Clear();
            received = false;

            channel.Publish(new KeyValuePair <string, string>("1", "1"));
            Assert.IsFalse(received);
            Assert.AreEqual(1, queue.Scheduled.Count);
        }
Пример #4
0
        public void SubToKeyedBatch()
        {
            Channel<KeyValuePair<string, string>> channel = new Channel<KeyValuePair<string, string>>();
            StubCommandContext queue = new StubCommandContext();
            bool received = false;
            Action<IDictionary<string, KeyValuePair<string, string>>> onReceive =
                delegate(IDictionary<string, KeyValuePair<string, string>> data)
                    {
                        Assert.AreEqual(2, data.Keys.Count);
                        Assert.AreEqual(data["0"], new KeyValuePair<string, string>("0", "4"));
                        Assert.AreEqual(data["1"], new KeyValuePair<string, string>("1", "3"));
                        received = true;
                    };
            Converter<KeyValuePair<string, string>, string> key =
                delegate(KeyValuePair<string, string> pair) { return pair.Key; };
            channel.SubscribeToKeyedBatch(queue, key, onReceive, 0);

            for (int i = 0; i < 5; i++)
            {
                channel.Publish(new KeyValuePair<string, string>((i%2).ToString(), i.ToString()));
            }
            Assert.AreEqual(1, queue.Scheduled.Count);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            queue.Scheduled.Clear();
            received = false;

            channel.Publish(new KeyValuePair<string, string>("1", "1"));
            Assert.IsFalse(received);
            Assert.AreEqual(1, queue.Scheduled.Count);
        }
Пример #5
0
        public void SubToBatch()
        {
            Channel<string> channel = new Channel<string>();
            StubCommandContext queue = new StubCommandContext();
            bool received = false;
            Action<IList<string>> onReceive = delegate(IList<string> data)
                                                  {
                                                      Assert.AreEqual(5, data.Count);
                                                      Assert.AreEqual("0", data[0]);
                                                      Assert.AreEqual("4", data[4]);
                                                      received = true;
                                                  };
            channel.SubscribeToBatch(queue, onReceive, 0);

            for (int i = 0; i < 5; i++)
            {
                channel.Publish(i.ToString());
            }
            Assert.AreEqual(1, queue.Scheduled.Count);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            queue.Scheduled.Clear();
            received = false;

            channel.Publish("5");
            Assert.IsFalse(received);
            Assert.AreEqual(1, queue.Scheduled.Count);
        }
Пример #6
0
        public void SubscribeToLast()
        {
            Channel<int> channel = new Channel<int>();
            StubCommandContext queue = new StubCommandContext();
            bool received = false;
            int lastReceived = -1;
            Action<int> onReceive = delegate(int data)
                                        {
                                            lastReceived = data;
                                            received = true;
                                        };
            channel.SubscribeToLast(queue, onReceive, 0);

            for (int i = 0; i < 5; i++)
            {
                channel.Publish(i);
            }
            Assert.AreEqual(1, queue.Scheduled.Count);
            Assert.IsFalse(received);
            Assert.AreEqual(-1, lastReceived);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            Assert.AreEqual(4, lastReceived);
            queue.Scheduled.Clear();
            received = false;
            lastReceived = -1;
            channel.Publish(5);
            Assert.IsFalse(received);
            Assert.AreEqual(1, queue.Scheduled.Count);
            queue.Scheduled[0]();
            Assert.IsTrue(received);
            Assert.AreEqual(5, lastReceived);
        }