public void QueueManager_EnqueTest()
 {
     //Init
     var qn = "q1";
     var q = new QueueManager<string>(qn);
     q.Flush();
     // Push items into queue
     data.ForEach(x => q.Push(x));
     // Test 
     Assert.AreEqual(q.GetElements().Length, data.Count);        
 }
예제 #2
0
    static void Main(string[] args)
    {
      BootstrapManager.InitLogging();
      BootstrapManager.BootRedis();

      var queueManager = new QueueManager<Job>("urn:company:product:module:function");
      queueManager.Flush();

      queueManager.SubscribeForNewItem(
          job => job.DoWork()
        );

      Console.WriteLine("Press ENTER to stop serving...");
      Console.Read();

    }
        public void Test_Multiple_Push_And_Pop()
        {
            int count = 100;
            var qn = "q1";
            var q = new QueueManager<string>(qn);
            q.Flush();

            for (int i = 0; i < count; i++)
            {
                q.Push(i.ToString());
            }
            for (int i = 0; i < count; i++)
            {
                var p = q.Pop();
                Assert.AreEqual(int.Parse(p), i);
            }
        }
        public void Queue_Enque_Pop_Test()
        {
            // Init
            var qn = "q1";
            var q = new QueueManager<string>(qn);
            q.Flush();

            // Push items into queue q1
            data.ForEach(x => q.Push(x));

            // Pop and test
            Assert.AreEqual(q.Pop(), data.First());
        }
        public void Test_Queue_Notifications_Concurrency()
        {
            int count = 100;
            var qn = "q1";
            var cq1 = new QueueManager<string>(qn);
            var cq2 = new QueueManager<string>(qn);
            var incomingMessages1 = new List<string>();
            var incomingMessages2 = new List<string>();
            cq1.Flush();
            cq2.Flush();

            cq1.SubscribeForNewItem(x => {
                incomingMessages1.Add(x);
               Log.Debug("Incoming item cq1 Value:" + x);
            });
            cq2.SubscribeForNewItem(x =>
            {
                incomingMessages2.Add(x);
                Log.Debug("Incoming item cq2 Value:" + x);
            });

            int xx = 0;
            for (int i = 0; i < count; i++)
            {
                Task.Factory.StartNew(() => {
                    int item = xx++;
                    Log.Debug("New Push:" + item.ToString() + " Thread:" + Thread.CurrentThread.ManagedThreadId);
                    cq1.Push(item.ToString(), true); 
                });
            }

            Log.Debug("Waiting...");

            Thread.Sleep(2000);
            Assert.AreEqual(incomingMessages1.Count + incomingMessages2.Count, count);

            Log.Debug("Check if the queues are empty.");
            var p1 = cq1.Pop();
            Assert.IsNull(p1);
            Log.Debug("Done!");
        }