Esempio n. 1
0
        public void AddOrUpdateDomain_AddDuplicateDomain_LastUpdateWins()
        {
            var domainRateLimiter = new DomainRateLimiter(5);
            var domain            = new Uri("http://a.com");

            domainRateLimiter.AddOrUpdateDomain(domain, 50);
            domainRateLimiter.AddOrUpdateDomain(domain, 150);//This should override the previous

            var timer = System.Diagnostics.Stopwatch.StartNew();

            domainRateLimiter.RateLimit(domain);
            domainRateLimiter.RateLimit(domain);
            timer.Stop();

            Assert.IsTrue(timer.ElapsedMilliseconds >= 100, "Expected it to take more than 100 millisecs but only took " + timer.ElapsedMilliseconds);
        }
Esempio n. 2
0
        public void AddOrUpdateDomain_ParamGreaterThanDefault_UsesParam()
        {
            Uri rootUri  = new Uri("http://a.com/");
            Uri pageUri1 = new Uri("http://a.com/a.html");
            Uri pageUri2 = new Uri("http://a.com/b.html");

            Stopwatch         timer         = Stopwatch.StartNew();
            DomainRateLimiter unitUnderTest = new DomainRateLimiter(5);

            unitUnderTest.AddOrUpdateDomain(rootUri, 100);

            unitUnderTest.RateLimit(rootUri);
            unitUnderTest.RateLimit(pageUri1);
            unitUnderTest.RateLimit(pageUri2);
            timer.Stop();

            Assert.IsTrue(timer.ElapsedMilliseconds > 190);
        }