zoukankan      html  css  js  c++  java
  • So you want to replay an IIS web server log?

    原文地址:http://blogs.msdn.com/joshch/archive/2006/07/03/655518.aspx

    A few months ago, a group in Microsoft wanted to be able to play back a large IIS log as a Visual Studio web test.  They started off with a converter that converted the IIS log into a gigantic coded web test.  The 118MB .cs file that resulted was a bit ridiculous and didn't perform very well at design time or run time.

    I took a different approach by reading the IIS log from within the web test.  It depends on the the handy LogReader 2.2 download to handle all the log parsing and keep the code short and simple.

    Here's a sample WebTest that plays back an IIS log:

    public class IISLogCodedWebTest : WebTest
    {
        public IISLogCodedWebTest()
        {
            this.PreAuthenticate = true;
        }

        public override IEnumerator<WebTestRequest> GetRequestEnumerator()
        {
            IISLogReader reader = new IISLogReader(@"d:\download\ex060209.log");
            foreach (WebTestRequest request in reader.GetRequests())
            {
                yield return request;
            }
        }
    }

    The code for the IISLogReader class used above is below:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using MSUtil;
    using LogQuery = MSUtil.LogQueryClassClass;
    using IISLogInputFormat = MSUtil.COMIISW3CInputContextClassClass;
    using LogRecordSet = MSUtil.ILogRecordset;
    using Microsoft.VisualStudio.TestTools.WebTesting;

    namespace IISLogToWebTest
    {
        public class IISLogReader
        {
            private string _iisLogPath;

            public IISLogReader(string iisLogPath)
            {
                _iisLogPath = iisLogPath;
            }

            public IEnumerable<WebTestRequest> GetRequests()
            {
                LogQuery logQuery = new LogQuery();
                IISLogInputFormat iisInputFormat = new IISLogInputFormat();

                string query = @"SELECT s-ip, s-port, cs-method, cs-uri-stem, cs-uri-query FROM " + _iisLogPath;

                LogRecordSet recordSet = logQuery.Execute(query, iisInputFormat);
                while (!recordSet.atEnd())
                {
                    ILogRecord record = recordSet.getRecord();
                    if (record.getValueEx("cs-method").ToString() == "GET")
                    {
                        string server = record.getValueEx("s-ip").ToString();
                        string path = record.getValueEx("cs-uri-stem").ToString();
                        string querystring = record.getValueEx("cs-uri-query").ToString();

                        StringBuilder urlBuilder = new StringBuilder();
                        urlBuilder.Append("http://");
                        urlBuilder.Append(server);
                        urlBuilder.Append(path);
                        if (!String.IsNullOrEmpty(querystring))
                        {
                            urlBuilder.Append("?");
                            urlBuilder.Append(querystring);
                        }

                        WebTestRequest request = new WebTestRequest(urlBuilder.ToString());
                        yield return request;
                    }

                    recordSet.moveNext();
                }
                recordSet.close();
            }
        }
    }

     

    这真是一个不错的主意:通过Logparser读取IIS日志文件,并且利用它来做测试的重放。

  • 相关阅读:
    js 性能调试
    js 面向对象编程
    js 零碎
    如果遇到二维数组 想取某个字段的和
    昨天写支付接口时遇到支付接口返回数据接收地址,session数据丢失(或者说失效)的问题
    mysql报错: 1548-Cannot load from mysql.proc. The table is probably corrupted 解决办法
    php 时间倒计时代码 个人写法 有好的想法的欢迎贴出来分享
    linux 环境下安装mysql5.6
    关于数据库连接不上 出现错误的问题
    推荐一个不错的css3网站 可以直接调用的
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1493924.html
Copyright © 2011-2022 走看看