Esempio n. 1
0
        public void SumFlowControlTest()
        {
            var strategy = new FlowControlStrategy()
            {
                ID               = "SumFC",
                Name             = "服务总访问量限流",
                Creator          = "Teld",
                LastModifier     = "Teld",
                CreateTime       = DateTime.Now,
                LastModifyTime   = DateTime.Now,
                StrategyType     = FlowControlStrategyType.Sum,
                IntThreshold     = 100,
                TimeSpan         = FlowControlTimespan.Second,
                IsRefusedRequest = true
            };

            FlowControlService.FlowControl(strategy, 1);

            try
            {
                for (int i = 0; i < 300; i++)
                {
                    FlowControlService.FlowControl(strategy, 1);
                }
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.Message, "触发流控!");
            }
        }
Esempio n. 2
0
        public void DelayFlowControlWaitTest()
        {
            var strategy = new FlowControlStrategy()
            {
                ID               = "DelayFC",
                Name             = "服务总访问量限流",
                Creator          = "Teld",
                LastModifier     = "Teld",
                CreateTime       = DateTime.Now,
                LastModifyTime   = DateTime.Now,
                StrategyType     = FlowControlStrategyType.Delay,
                IntThreshold     = 100,
                TimeSpan         = FlowControlTimespan.Second,
                IsRefusedRequest = false
            };

            FlowControlService.FlowControl(strategy, 1);

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            for (int i = 0; i < 100; i++)
            {
                FlowControlService.FlowControl(strategy, 1);
            }

            stopWatch.Stop();
            Assert.IsTrue(stopWatch.ElapsedMilliseconds > 100 * 100);
        }
        public void TPSFlowControlTest()
        {
            var strategy = new FlowControlStrategy()
            {
                ID               = "TPSFC",
                Name             = "服务TPS限流",
                Creator          = "User",
                LastModifier     = "User",
                CreateTime       = DateTime.Now,
                LastModifyTime   = DateTime.Now,
                StrategyType     = FlowControlStrategyType.TPS,
                IntThreshold     = 100,
                IsRefusedRequest = true
            };

            FlowControlService.FlowControl(strategy, 1);

            try
            {
                for (int i = 0; i < 300; i++)
                {
                    FlowControlService.FlowControl(strategy, 1);
                }
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.Message, "触发流控!");
            }
        }
Esempio n. 4
0
        public void TPSFlowControlWaitTest()
        {
            var strategy = new FlowControlStrategy()
            {
                ID               = "TPSFC",
                Name             = "服务TPS限流",
                Creator          = "Teld",
                LastModifier     = "Teld",
                CreateTime       = DateTime.Now,
                LastModifyTime   = DateTime.Now,
                StrategyType     = FlowControlStrategyType.TPS,
                IntThreshold     = 100,
                IsRefusedRequest = false
            };

            FlowControlService.FlowControl(strategy, 1);

            for (int i = 0; i < 300; i++)
            {
                FlowControlService.FlowControl(strategy, 1);
            }
        }
Esempio n. 5
0
        public void SumFlowControlWaitTest()
        {
            var strategy = new FlowControlStrategy()
            {
                ID               = "SumFC",
                Name             = "服务总访问量限流",
                Creator          = "Teld",
                LastModifier     = "Teld",
                CreateTime       = DateTime.Now,
                LastModifyTime   = DateTime.Now,
                StrategyType     = FlowControlStrategyType.Sum,
                IntThreshold     = 100,
                TimeSpan         = FlowControlTimespan.Second,
                IsRefusedRequest = false
            };

            FlowControlService.FlowControl(strategy, 1);

            for (int i = 0; i < 300; i++)
            {
                FlowControlService.FlowControl(strategy, 1);
            }
        }