예제 #1
0
        private void Instance_AfterExecute(object sender, CommandEventArgs e)
        {
            DateTime endTime = DateTime.Now;
            TimeSpan ts      = endTime - _startTime;

            PerformanceModule.CheckDbExecuteTime(e.DbCommand, ts);
        }
예제 #2
0
        public void Test_PerformanceMoudle_测试HTTP请求执行超时场景()
        {
            // 测试 HTTP 请求执行超时场景
            using (WebContext context = HttpInfoTest.CreateWebContext()) {
                PerformanceModule module = new PerformanceModule();


                System.Threading.Thread.Sleep(WriterFactory.Config.TimerPeriod + 1000);
                // 暂停异步写入
                SetAsyncWriteEnabled(false);

                // 这个调用仅仅为了覆盖代码,没什么具体意义
                module.Init(context.Application.Instance);

                // 代替 HttpApplicaton 触发 PreRequestHandlerExecute事件
                MethodInfo method = module.GetType().GetMethod("app_PreRequestHandlerExecute", BindingFlags.Instance | BindingFlags.NonPublic);
                method.Invoke(module, new object[] { context.Application.Instance, null });

                // 获取结果,检查上面的调用是否成功
                object value = context.HttpContext.Items["289e8920-b291-4167-80b0-793cd46cad22"];
                Assert.IsTrue(value.GetType() == typeof(DateTime));


                // 模拟超时
                System.Threading.Thread.Sleep(WriterFactory.Config.Performance.HttpExecuteTimeout + 1000);


                // 代替 HttpApplicaton 触发 PostRequestHandlerExecute事件
                method = module.GetType().GetMethod("app_PostRequestHandlerExecute", BindingFlags.Instance | BindingFlags.NonPublic);
                method.Invoke(module, new object[] { context.Application.Instance, null });

                // 获取调用 LogHelper.Write(info); 的数据

                List <PerformanceInfo> list = GetQueueData();

                Assert.AreEqual(1, list.Count);

                PerformanceInfo performanceInfo = list[0];
                Assert.AreEqual("http://www.bing.com/sfdjosfdj/slfjsfj/sdjfosf.aspx", performanceInfo.HttpInfo.Url);

                // 启用异步写入
                SetAsyncWriteEnabled(true);

                module.Dispose();
            }
        }
예제 #3
0
        public void Test2()
        {
            // 测试 HTTP 请求执行超时场景
            using (WebContext context = HttpInfoTest.CreateWebContext()) {
                context.SetUserName("fish li");
                // 测试 SQL 执行超时场景

                PerformanceModule module = new PerformanceModule();

                System.Threading.Thread.Sleep(WriterFactory.Config.TimerPeriod + 1000);
                // 暂停异步写入
                SetAsyncWriteEnabled(false);


                TimeSpan  timeSpan = TimeSpan.FromSeconds(2d);
                DbCommand command  = SqlInfoTest.CreateDbCommand();

                // 第一次调用,第一个参数command = null
                PerformanceModule.CheckDbExecuteTime(null, timeSpan);

                // 第二次调用
                PerformanceModule.CheckDbExecuteTime(command, timeSpan);



                // 获取调用 LogHelper.Write(info); 的数据
                List <PerformanceInfo> list = GetQueueData();

                Assert.AreEqual(1, list.Count);

                PerformanceInfo performanceInfo = list[0];
                Assert.AreEqual(command.CommandText, performanceInfo.SqlInfo.SqlText.ToString());

                Assert.IsNotNull(performanceInfo.HttpInfo);
                Assert.AreEqual(context.HttpContext.Request.Url.OriginalString, performanceInfo.HttpInfo.Url);
                Console.WriteLine(performanceInfo.HttpInfo.Url);
                Assert.AreEqual("fish li", performanceInfo.HttpInfo.UserName);

                // 启用异步写入
                SetAsyncWriteEnabled(true);
            }
        }
예제 #4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ChampionGgClient" /> class.
 /// </summary>
 public ChampionGgClient()
 {
     Performance = new PerformanceModule(new Uri("http://api.champion.gg/v2"));
     Champions   = new ChampionModule(new Uri("http://api.champion.gg/v2"));
 }