Пример #1
0
        public void TestChronologicalWorkQueue()
        {
            using (var queue = new RedisChronologicalWorkQueue <string>(10, 10, "127.0.0.1", 6379))
            {
                const int numMessages = 6;
                var       messages    = new List <string>();
                var       patients    = new List <string>();
                var       time        = new List <double>();

                for (int i = 0; i < numMessages; ++i)
                {
                    time.Add(i);
                    patients.Add(String.Format("patient{0}", i));
                    messages.Add(String.Format("{0}_message{1}", patients[i], i));
                    queue.Enqueue(patients[i], messages[i], i);
                }

                // dequeue half of the messages
                var batch = queue.Dequeue(0, numMessages, numMessages / 2);
                // check that half of patient[0] messages are returned
                for (int i = 0; i < numMessages / 2; ++i)
                {
                    Assert.AreEqual(batch[i].Value, messages[i]);
                }

                // dequeue the rest of the messages
                batch = queue.Dequeue(0, numMessages, 2 * numMessages);
                // check that batch size is respected
                Assert.AreEqual(batch.Count, numMessages / 2);
                for (int i = 0; i < numMessages / 2; ++i)
                {
                    Assert.AreEqual(batch[i].Value, messages[i + numMessages / 2]);
                }

                // check that there are no more messages in the queue
                batch = queue.Dequeue(0, numMessages, numMessages);
                Assert.AreEqual(batch.Count, 0);
            }
        }
Пример #2
0
        public void TestChronologicalWorkQueue()
        {
            using (var queue = new RedisChronologicalWorkQueue<string>(10, 10, TestConfig.SingleHost, TestConfig.RedisPort))
            {
                const int numMessages = 6;
                var messages = new List<string>();
                var patients = new List<string>();
                var time = new List<double>();

                for (int i = 0; i < numMessages; ++i)
                {
                    time.Add(i);
                    patients.Add(String.Format("patient{0}",i));
                    messages.Add(String.Format("{0}_message{1}", patients[i], i));
                    queue.Enqueue(patients[i], messages[i],i);
                }

                // dequeue half of the messages
                var batch = queue.Dequeue(0, numMessages, numMessages / 2);
                // check that half of patient[0] messages are returned
                for (int i = 0; i < numMessages / 2; ++i)
                    Assert.AreEqual(batch[i].Value, messages[i]);

                // dequeue the rest of the messages
                batch = queue.Dequeue(0,numMessages,2 * numMessages);
                // check that batch size is respected
                Assert.AreEqual(batch.Count, numMessages/2);
                for (int i = 0; i < numMessages/2; ++i)
                    Assert.AreEqual(batch[i].Value, messages[i + numMessages/2]);

                // check that there are no more messages in the queue
                batch = queue.Dequeue(0,numMessages, numMessages);
                Assert.AreEqual(batch.Count, 0);

            }
        }