Ejemplo n.º 1
0
 public void ProductionAsyncTest()
 {
     var site = new Site() { Domain = "www.usashopcn.com" };
     var requestMessage = NewTestRequestMessage(site);
     var bloomFilter = new MemoryBloomFilter<string>(1000 * 10, 1000 * 10 * 20);
     var lineScheduler = new SequenceScheduler(bloomFilter);
     lineScheduler.PushAsync(requestMessage);
     Thread.Sleep(500);
     Trace.WriteLine("CurrentQueueCount:" + lineScheduler.CurrentQueueCount());
     Assert.IsTrue(lineScheduler.CurrentQueueCount() == 1, "添加消息失败");
     lineScheduler.Dispose();
 }
Ejemplo n.º 2
0
        public void ConsumeTest()
        {
            var site = new Site() {Domain = "www.usashopcn.com"};

            var requestMessages = NewTestRequestMessages(site);
            var bloomFilter = new MemoryBloomFilter<string>(1000 * 10, 1000 * 10 * 20);
            var lineScheduler = new SequenceScheduler(bloomFilter);
            lineScheduler.Push(requestMessages);
            Trace.WriteLine("CurrentQueueCount:" + lineScheduler.CurrentQueueCount());

            var resultPipeline = new ResultPipeline();
            resultPipeline.RegisterModule(new TestPipelineMoudle());
            var pageAnalyzers = new List<KeyValuePair<string, Type>>();
            pageAnalyzers.Add(new KeyValuePair<string, Type>(site.Domain, typeof(TestPageAnalyzer)));
            var consumerBroker = new ConsumerBroker(2, lineScheduler, new List<IDownloader>() {new TestDownloader()}, new ResultPipeline(), pageAnalyzers);
            consumerBroker.Start();

            var timer = new Timer((state) =>
            {
                Trace.WriteLine("Timer结束:");
                Assert.IsTrue(lineScheduler.CurrentQueueCount() == 0, "添加消息失败");
            }, null, 20000, 0);
            
            //lineScheduler.Dispose();
        }