public void TestMethod() { int requestQuota = 15; int countRequests = (int)(requestQuota / 2d * 1.4); var tasks = new List <Task>(); using (var t = TrapForThrottlingController.Create("test", requestQuota, 5)) { var localTrapForThrottling = t; for (int i = 0; i < countRequests; i++) { var counter = i + 1; tasks.Add(new Task(() => localTrapForThrottling.Execute(CreateAction(string.Format("Action #{0}", counter + 1))))); tasks.Add(new Task(() => localTrapForThrottling.Execute(CreateAction(string.Format("Limit Action #{0}", counter + 1), ActionAccessType.Limit)))); //Thread.Sleep( 10 * 1000 ); } //Thread.Sleep( requestQuota * 90 * 1000 ); tasks.Add(new Task(() => localTrapForThrottling.Execute(CreateAction(string.Format("Action #{0}", countRequests + 1))))); //Thread.Sleep( requestQuota / 3 * 90 * 1000 ); tasks.Add(new Task(() => localTrapForThrottling.Execute(CreateAction(string.Format("Action #{0}", countRequests + 2))))); //Thread.Sleep( 5 * 60 * 1000 ); tasks.ForEach(t1 => t1.Start()); tasks.ForEach(t1 => t1.Wait()); TrapForThrottlingController.Exit(); } }
public void TestMethod2() { for (int i = 0; i < 10; i++) { var t = TrapForThrottlingController.Create(string.Format("test {0}", i + 1), 15); t.Execute(CreateAction()); } var tShort = TrapForThrottlingController.Create("test short", 15, 1); tShort.Execute(CreateAction()); Thread.Sleep(5000); TrapForThrottlingController.Exit(); }