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都是帮助保存文件的辅助类

转载于:https://www.cnblogs.com/liliqiang/p/4337106.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值