zoukankan      html  css  js  c++  java
  • jmeter系列七(Visualizer的TestElement-ResultCollector)

    前面分析了Visualizer,今天看下他对应的testelement-ResultCollector

    ResultCollector实现了SampleListener, Clearable, Serializable,TestStateListener, Remoteable, NoThreadClone这几个接口

    一个一个的看下

    SampleListener接口 notification on events occuring during the sampling process

    Clearable接口 同上

    Serializable接口 可序列化

    TestStateListener接口 测试开始的过程中实现了这个接口的类可以被回调

    Remoteable接口 以后分析

    NoThreadClone接口 标记接口,标记了这个接口的testelement,在多个test run之间不会被clone

    重点看实现了TestStateListener接口的方法和实现了SampleListener接口的方法

    testStarted testEnded sampleOccurred

     1 @Override
     2     public void testStarted(String host) {
     3         synchronized(LOCK){
     4             if (instanceCount == 0) { // Only add the hook once
     5                 shutdownHook = new Thread(new ShutdownHook());
     6                 Runtime.getRuntime().addShutdownHook(shutdownHook);
     7             }
     8             instanceCount++;
     9             try {
    10                 initializeFileOutput();
    11                 if (getVisualizer() != null) {
    12                     this.isStats = getVisualizer().isStats();
    13                 }
    14             } catch (Exception e) {
    15                 log.error("", e);
    16             }
    17         }
    18         inTest = true;
    19 
    20         if(summariser != null) {
    21             summariser.testStarted(host);
    22         }
    23     }
     1 @Override
     2     public void testEnded(String host) {
     3         synchronized(LOCK){
     4             instanceCount--;
     5             if (instanceCount <= 0) {
     6                 // No need for the hook now
     7                 Runtime.getRuntime().removeShutdownHook(shutdownHook);
     8                 finalizeFileOutput();
     9                 inTest = false;
    10             }
    11         }
    12 
    13         if(summariser != null) {
    14             summariser.testEnded(host);
    15         }
    16     }
     1 @Override
     2     public void sampleOccurred(SampleEvent event) {
     3         SampleResult result = event.getResult();
     4 
     5         if (isSampleWanted(result.isSuccessful())) {
     6             sendToVisualizer(result);
     7             if (out != null && !isResultMarked(result) && !this.isStats) {
     8                 SampleSaveConfiguration config = getSaveConfig();
     9                 result.setSaveConfig(config);
    10                 try {
    11                     if (config.saveAsXml()) {
    12                         SaveService.saveSampleResult(event, out);
    13                     } else { // !saveAsXml
    14                         String savee = CSVSaveService.resultToDelimitedString(event);
    15                         out.println(savee);
    16                     }
    17                 } catch (Exception err) {
    18                     log.error("Error trying to record a sample", err); // should throw exception back to caller
    19                 }
    20             }
    21         }
    22 
    23         if(summariser != null) {
    24             summariser.sampleOccurred(event);
    25         }
    26     }

    其中涉及到的SaveService,CSVSaveService都是帮助保存文件的辅助类

  • 相关阅读:
    知识工程及语义网技术 2020-03-19 (第一节)-构建本体
    知识工程及语义网技术 2020-03-12 (第二节)-构建本体
    知识工程及语义网技术 2020-03-12 (第二节)、RDF(S)、OWL
    知识工程及语义网技术(一)-XML、RDF(S)、OWL-2020.3.5第一节
    知识工程及语义网技术(一)-知识工程,万维网、语义网、本体工程 2020-02-20 (第一节)
    本体
    语义网技术及其应用(四)-欧石燕
    一文深度揭秘3GPP:2G/3G/4G/Pre-5G标准化制定流程是这样的
    3GPP更新5G标准时间表
    一张图了解3GPP
  • 原文地址:https://www.cnblogs.com/liliqiang/p/4337106.html
Copyright © 2011-2022 走看看