grinder脚本解析原理

本文详细介绍了Grinder脚本的解析过程,从Test类的初始化到HTTP请求的执行。解析过程包括Test类的注册、TestRegistry的管理、创建代理对象及Python对象的包装。在脚本执行过程中,涉及到了请求的发送、计时和数据统计功能。
摘要由CSDN通过智能技术生成
先看个典型的grinder脚本
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPRequest

test1 = Test(1, "Request resource")
request1 = test1.wrap(HTTPRequest())
class TestRunner:
    def __call__(self):
        result = request1.GET("http://www.google.com.hk)

脚本解析的入口:Test 类。

1. 解析脚本:test1 = Test(1, "Request resource")
// number=1,description="Request resource"
public class Test extends AbstractTestSemantics implements Serializable{
  public Test( int number, String description) {
    m_number = number;
    m_description = description;
//Test类在初始化的时候,向registeredTest注册该测试对象Test
    m_registeredTest = Grinder.grinder .getTestRegistry().register(this);
  }
class TestRegistryImplementation
  public RegisteredTest register(Test test) {
 //先判断instrumenter是否为空
    if ( m_instrumenter == null) {
      throw new AssertionError("Instrumenter not set");
    }
  // 创建测试业务实现对象, TestData可以包装关联被测目标对象 /方法,同时实现计时功能
    final TestData newTestData;
    //同步信息,从testMap中查询是否存在这个test,如果存在就直接返回。保证test在testMap中的唯一性。 
    synchronized ( this) {
      final TestData existing = m_testMap .get(test);
      if (existing != null) {
        return existing;
      }
      //如果不存在,new 一个TestData对象。
      newTestData = new TestData(m_threadContextLocator ,
                                 m_statisticsSetFactory,
                                 m_testStatisticsHelper,
                                 m_timeAuthority,
                                 m_instrumenter,
                                 test);
// 把test和newTestData放入testMap 中进行管理。
      m_testMap.put(test, newTestData);
      m_testStatisticsMap.put(test, newTestData.getTestStatistics());

      if (m_newTests == null) {
        m_newTests = new ArrayList<Test>();
      }

      // To avoid many minor console updates we store a collection of
      // the new tests which is periodically read and sent to the
      // console by the scheduled reporter task.
      //Collection<Test> 中新增这个test
      m_newTests.add(test);
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值