Exemplo n.º 1
0
        public void Status()
        {
            Extension.Scheduler.RedisScheduler scheduler = GetRedisScheduler();
            ISpider spider = new DefaultSpider("test", new Site());

            scheduler.Init(spider);

            scheduler.Clean();

            scheduler.Push(new Request("http://www.a.com/", null));
            scheduler.Push(new Request("http://www.b.com/", null));
            scheduler.Push(new Request("http://www.c.com/", null));
            scheduler.Push(new Request("http://www.d.com/", null));

            Assert.AreEqual(0, scheduler.GetErrorRequestsCount());
            Assert.AreEqual(4, scheduler.GetLeftRequestsCount());
            Assert.AreEqual(4, scheduler.GetTotalRequestsCount());
            scheduler.IncreaseErrorCounter();
            Assert.AreEqual(1, scheduler.GetErrorRequestsCount());
            Assert.AreEqual(0, scheduler.GetSuccessRequestsCount());
            scheduler.IncreaseSuccessCounter();
            Assert.AreEqual(1, scheduler.GetSuccessRequestsCount());

            scheduler.Poll();
            Assert.AreEqual(3, scheduler.GetLeftRequestsCount());
            Assert.AreEqual(1, scheduler.GetSuccessRequestsCount());
            Assert.AreEqual(1, scheduler.GetErrorRequestsCount());
            Assert.AreEqual(4, scheduler.GetTotalRequestsCount());

            scheduler.Poll();
            Assert.AreEqual(2, scheduler.GetLeftRequestsCount());
            Assert.AreEqual(1, scheduler.GetSuccessRequestsCount());
            Assert.AreEqual(1, scheduler.GetErrorRequestsCount());
            Assert.AreEqual(4, scheduler.GetTotalRequestsCount());

            scheduler.Poll();
            Assert.AreEqual(1, scheduler.GetLeftRequestsCount());
            Assert.AreEqual(1, scheduler.GetSuccessRequestsCount());
            Assert.AreEqual(1, scheduler.GetErrorRequestsCount());
            Assert.AreEqual(4, scheduler.GetTotalRequestsCount());

            scheduler.Poll();
            Assert.AreEqual(0, scheduler.GetLeftRequestsCount());
            Assert.AreEqual(1, scheduler.GetSuccessRequestsCount());
            Assert.AreEqual(1, scheduler.GetErrorRequestsCount());
            Assert.AreEqual(4, scheduler.GetTotalRequestsCount());

            scheduler.Poll();
            scheduler.Poll();
            Assert.AreEqual(0, scheduler.GetLeftRequestsCount());
            Assert.AreEqual(1, scheduler.GetSuccessRequestsCount());
            Assert.AreEqual(1, scheduler.GetErrorRequestsCount());
            Assert.AreEqual(4, scheduler.GetTotalRequestsCount());

            scheduler.Clean();
        }