JMeter插件-如何收听TestState [英] JMeter Plugin - How to Listen to TestState
问题描述
我正在开发JMeter插件.我正在尝试创建一个能够监视当前测试状态的AbstractVisualizer.但是,实现TestStateListener似乎不起作用.
I am working on developing a JMeter plugin. I'm trying to create an AbstractVisualizer that is capable of monitoring the current test state. However, implementing the TestStateListener doesn't seem to be working.
我正在通过创建一个基本的侦听器进行测试,该侦听器具有一个登录名,可以将任意信息输出到JMeter的日志记录控制台.通过添加"功能发送样品时,会向控制台发送一行.但是,各种TestState函数都不会触发任何事件.我还缺少一些更具结构性的东西吗?
I'm testing this by creating a basic listener that has a login to output arbitrary info to JMeter's logging console. When a sample is sent through the Add function, a line is sent to the console. But nothing is ever triggered on the various TestState functions. Is there something more structural I'm missing?
public class TestListener extends AbstractVisualizer
implements TestStateListener
{
private static final Logger log = LoggingManager.getLoggerForClass();
@Override
public void add(SampleResult arg0) {
log.info("add");
}
@Override
public void clearData() {
// TODO Auto-generated method stub
}
@Override
public String getStaticLabel()
{
return "Test Listener";
}
@Override
public String getLabelResource() {
return null;
}
@Override
public void testEnded() {
log.info("Test Ended");
}
@Override
public void testEnded(String arg0) {
log.info("Test Ended");
}
@Override
public void testStarted() {
log.info("Test started");
}
@Override
public void testStarted(String arg0) {
log.info("Test started");
}
}
推荐答案
我不确定如何在1节课中做到这一点.我有2节课:
I'm not sure how to do it in 1 class. I have 2 classes:
用户界面:
public class MonitorGui extends AbstractListenerGui
{
// ...
@Override
public TestElement createTestElement()
{
TestElement element = new Monitor();// <-- this is the backend
modifyTestElement(element);
return element;
}
// ...
}
然后后端是这样的:
public class Monitor extends AbstractListenerElement
implements SampleListener,
Clearable, Serializable,
TestStateListener, Remoteable,
NoThreadClone
{
private static final String TEST_IS_LOCAL = "*local*";
// ...
@Override
public void testStarted()
{
testStarted(TEST_IS_LOCAL);
}
@Override
public void testEnded()
{
testEnded(TEST_IS_LOCAL);
}
@Override
public void testStarted(String host)
{
// ...
}
// ...
}
您可能不需要像我一样实现SampleListener
,但可能其他情况也很相似.
You may not need to implement SampleListener
like I do, but probably other things are quite similar.
我基于一对 ResultCollector 是将结果保存到Simple Data Writer,Summary Report等文件中的组件.
I based that implementation on a built-in pair of ResultSaverGui and ResultCollector which are the components that are saving results into the file(s) for Simple Data Writer, Summary Report and so on.
这篇关于JMeter插件-如何收听TestState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!