예제 #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 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);
            }
        }