• jmeter系列二(jmeter engine相关)


    准备知识org.apache.jorphan.collections下的类,engine会使用到

    Data类:模拟table存储数据

    HashTree类:将对象以树形存储

    HashTreeTraverser接口:实现了该接口的类可以获得HashTree中的存储的对象

    SearchByClass类:实现了SearchByClass接口,engine会大量用到

    第一篇讲的是界面相关的问题,当点击启动按钮jmeter将执行测试开始

    这个toolbar是类org.apache.jmeter.gui.util.JMeterMenuBar实现的,看类中的makeRunMenu方法中代码

    run_start = makeMenuItemRes("start", 'S', ActionNames.ACTION_START, KeyStrokes.ACTION_START);
    
    1 private static JMenuItem makeMenuItemRes(String resource, int mnemonic, String actionCommand, KeyStroke keyStroke){
    2         JMenuItem menuItem = new JMenuItem(JMeterUtils.getResString(resource), mnemonic);
    3         menuItem.setName(resource);
    4         menuItem.setActionCommand(actionCommand);
    5         menuItem.setAccelerator(keyStroke);
    6         menuItem.addActionListener(ActionRouter.getInstance());
    7         return menuItem;
    8     }

    menu的响应事件的类是ActionRouter,从前面文章可以知道在org.apache.jmeter.gui.action下找到类Start

     1 public void doAction(ActionEvent e) {
     2         if (e.getActionCommand().equals(ActionNames.ACTION_START)) {
     3             popupShouldSave(e);
     4             startEngine(false);
     5         } else if (e.getActionCommand().equals(ActionNames.ACTION_START_NO_TIMERS)) {
     6             popupShouldSave(e);
     7             startEngine(true);
     8         } else if (e.getActionCommand().equals(ActionNames.ACTION_STOP)) {
     9             if (engine != null) {
    10                 log.info("Stopping test");
    11                 GuiPackage.getInstance().getMainFrame().showStoppingMessage("");
    12                 engine.stopTest();
    13             }
    14         } else if (e.getActionCommand().equals(ActionNames.ACTION_SHUTDOWN)) {
    15             if (engine != null) {
    16                 log.info("Shutting test down");
    17                 GuiPackage.getInstance().getMainFrame().showStoppingMessage("");
    18                 engine.askThreadsToStop();
    19             }
    20         }
    21     }

    追踪到startEngine方法,其中经过一系列HashTree的相互转换和配置(前提看懂HashTree类的代码),engine开始测试

    runTest方法

     1 public void runTest() throws JMeterEngineException {
     2         if (host != null){
     3             long now=System.currentTimeMillis();
     4             System.out.println("Starting the test on host " + host + " @ "+new Date(now)+" ("+now+")");
     5         }
     6         try {
     7             Thread runningThread = new Thread(this, "StandardJMeterEngine");
     8             runningThread.start();
     9         } catch (Exception err) {
    10             stopTest();
    11             throw new JMeterEngineException(err);
    12         }
    13     }

    最后看到JmeterThread类中run方法,run方法大概流程

    1.通过controller获取Sampler

    2.执行preprocess(PreProcessor)

    3.执行sampler(Sampler)

    4.执行postprocess(PostProcessor)

    5.调用SampleListeners(Visualizer)

    6.调用controller的isDone方法判断是否loop

    其中的这些元素都是通过HashTree来存储

  • 相关阅读:
    pandas 流式导出excel
    django serializer 定制error_message
    selenium etree xpath使用总结
    Python之路--Python基础
    初见Flask
    Git
    MySQL补充——索引,流程控制,数据备份,python操作mysql,SQLAlchemy
    Python之路--Django--Ajax、同源策略、Jsonp、CORS
    Python之路--Django--form组件与model form组件
    Python之路--Django--中间件
  • 原文地址:https://www.cnblogs.com/liliqiang/p/4176313.html
Copyright © 2020-2023  润新知