Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MeterSphere
metersphere
提交
e736019e
M
metersphere
项目概览
MeterSphere
/
metersphere
上一次同步 大约 3 年
通知
25
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
metersphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e736019e
编写于
5月 25, 2020
作者:
Q
q4speed
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
改为后台增加BackendListener,保证前端生成的jmx独立性
上级
af47f8d9
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
22 addition
and
16 deletion
+22
-16
backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java
...a/io/metersphere/api/jmeter/APIBackendListenerClient.java
+7
-7
backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java
...rc/main/java/io/metersphere/api/jmeter/JMeterService.java
+14
-1
backend/src/main/java/io/metersphere/api/service/APITestService.java
.../main/java/io/metersphere/api/service/APITestService.java
+1
-1
frontend/src/business/components/api/test/model/ScenarioModel.js
...d/src/business/components/api/test/model/ScenarioModel.js
+0
-7
未找到文件。
backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java
浏览文件 @
e736019e
...
@@ -13,19 +13,18 @@ import org.apache.jmeter.visualizers.backend.BackendListenerContext;
...
@@ -13,19 +13,18 @@ import org.apache.jmeter.visualizers.backend.BackendListenerContext;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
/**
* JMeter BackendListener扩展, jmx脚本中使用
* JMeter BackendListener扩展, jmx脚本中使用
*/
*/
public
class
APIBackendListenerClient
extends
AbstractBackendListenerClient
implements
Serializable
{
public
class
APIBackendListenerClient
extends
AbstractBackendListenerClient
implements
Serializable
{
public
final
static
String
TEST_ID
=
"ms.test.id"
;
private
final
static
String
THREAD_SPLIT
=
" "
;
private
final
static
String
THREAD_SPLIT
=
" "
;
private
final
static
String
ID_SPLIT
=
"-"
;
private
final
static
String
ID_SPLIT
=
"-"
;
private
final
static
String
TEST_ID
=
"id"
;
private
final
List
<
SampleResult
>
queue
=
new
ArrayList
<>();
private
final
List
<
SampleResult
>
queue
=
new
ArrayList
<>();
private
APITestService
apiTestService
;
private
APITestService
apiTestService
;
...
@@ -33,11 +32,11 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
...
@@ -33,11 +32,11 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
private
APIReportService
apiReportService
;
private
APIReportService
apiReportService
;
// 测试ID
// 测试ID
private
String
i
d
;
private
String
testI
d
;
@Override
@Override
public
void
setupTest
(
BackendListenerContext
context
)
throws
Exception
{
public
void
setupTest
(
BackendListenerContext
context
)
throws
Exception
{
this
.
i
d
=
context
.
getParameter
(
TEST_ID
);
this
.
testI
d
=
context
.
getParameter
(
TEST_ID
);
apiTestService
=
CommonBeanFactory
.
getBean
(
APITestService
.
class
);
apiTestService
=
CommonBeanFactory
.
getBean
(
APITestService
.
class
);
if
(
apiTestService
==
null
)
{
if
(
apiTestService
==
null
)
{
LogUtil
.
error
(
"apiTestService is required"
);
LogUtil
.
error
(
"apiTestService is required"
);
...
@@ -47,6 +46,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
...
@@ -47,6 +46,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
if
(
apiReportService
==
null
)
{
if
(
apiReportService
==
null
)
{
LogUtil
.
error
(
"apiReportService is required"
);
LogUtil
.
error
(
"apiReportService is required"
);
}
}
super
.
setupTest
(
context
);
}
}
@Override
@Override
...
@@ -57,7 +57,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
...
@@ -57,7 +57,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
@Override
@Override
public
void
teardownTest
(
BackendListenerContext
context
)
throws
Exception
{
public
void
teardownTest
(
BackendListenerContext
context
)
throws
Exception
{
TestResult
testResult
=
new
TestResult
();
TestResult
testResult
=
new
TestResult
();
testResult
.
setTestId
(
i
d
);
testResult
.
setTestId
(
testI
d
);
testResult
.
setTotal
(
queue
.
size
());
testResult
.
setTotal
(
queue
.
size
());
// 一个脚本里可能包含多个场景(ThreadGroup),所以要区分开,key: 场景Id
// 一个脚本里可能包含多个场景(ThreadGroup),所以要区分开,key: 场景Id
...
@@ -99,7 +99,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
...
@@ -99,7 +99,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
testResult
.
getScenarios
().
addAll
(
scenarios
.
values
());
testResult
.
getScenarios
().
addAll
(
scenarios
.
values
());
testResult
.
getScenarios
().
sort
(
Comparator
.
comparing
(
ScenarioResult:
:
getId
));
testResult
.
getScenarios
().
sort
(
Comparator
.
comparing
(
ScenarioResult:
:
getId
));
apiTestService
.
changeStatus
(
i
d
,
APITestStatus
.
Completed
);
apiTestService
.
changeStatus
(
testI
d
,
APITestStatus
.
Completed
);
apiReportService
.
complete
(
testResult
);
apiReportService
.
complete
(
testResult
);
queue
.
clear
();
queue
.
clear
();
...
...
backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java
浏览文件 @
e736019e
...
@@ -3,8 +3,10 @@ package io.metersphere.api.jmeter;
...
@@ -3,8 +3,10 @@ package io.metersphere.api.jmeter;
import
io.metersphere.commons.exception.MSException
;
import
io.metersphere.commons.exception.MSException
;
import
io.metersphere.config.JmeterProperties
;
import
io.metersphere.config.JmeterProperties
;
import
io.metersphere.i18n.Translator
;
import
io.metersphere.i18n.Translator
;
import
org.apache.jmeter.config.Arguments
;
import
org.apache.jmeter.save.SaveService
;
import
org.apache.jmeter.save.SaveService
;
import
org.apache.jmeter.util.JMeterUtils
;
import
org.apache.jmeter.util.JMeterUtils
;
import
org.apache.jmeter.visualizers.backend.BackendListener
;
import
org.apache.jorphan.collections.HashTree
;
import
org.apache.jorphan.collections.HashTree
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -19,7 +21,7 @@ public class JMeterService {
...
@@ -19,7 +21,7 @@ public class JMeterService {
@Resource
@Resource
private
JmeterProperties
jmeterProperties
;
private
JmeterProperties
jmeterProperties
;
public
void
run
(
InputStream
is
)
{
public
void
run
(
String
testId
,
InputStream
is
)
{
String
JMETER_HOME
=
jmeterProperties
.
getHome
();
String
JMETER_HOME
=
jmeterProperties
.
getHome
();
String
JMETER_PROPERTIES
=
JMETER_HOME
+
"/bin/jmeter.properties"
;
String
JMETER_PROPERTIES
=
JMETER_HOME
+
"/bin/jmeter.properties"
;
JMeterUtils
.
loadJMeterProperties
(
JMETER_PROPERTIES
);
JMeterUtils
.
loadJMeterProperties
(
JMETER_PROPERTIES
);
...
@@ -27,6 +29,7 @@ public class JMeterService {
...
@@ -27,6 +29,7 @@ public class JMeterService {
try
{
try
{
Object
scriptWrapper
=
SaveService
.
loadElement
(
is
);
Object
scriptWrapper
=
SaveService
.
loadElement
(
is
);
HashTree
testPlan
=
getHashTree
(
scriptWrapper
);
HashTree
testPlan
=
getHashTree
(
scriptWrapper
);
addBackendListener
(
testId
,
testPlan
);
LocalRunner
runner
=
new
LocalRunner
(
testPlan
);
LocalRunner
runner
=
new
LocalRunner
(
testPlan
);
runner
.
run
();
runner
.
run
();
...
@@ -40,4 +43,14 @@ public class JMeterService {
...
@@ -40,4 +43,14 @@ public class JMeterService {
field
.
setAccessible
(
true
);
field
.
setAccessible
(
true
);
return
(
HashTree
)
field
.
get
(
scriptWrapper
);
return
(
HashTree
)
field
.
get
(
scriptWrapper
);
}
}
private
void
addBackendListener
(
String
testId
,
HashTree
testPlan
)
{
BackendListener
backendListener
=
new
BackendListener
();
backendListener
.
setName
(
testId
);
Arguments
arguments
=
new
Arguments
();
arguments
.
addArgument
(
APIBackendListenerClient
.
TEST_ID
,
testId
);
backendListener
.
setArguments
(
arguments
);
backendListener
.
setClassname
(
APIBackendListenerClient
.
class
.
getCanonicalName
());
testPlan
.
add
(
testPlan
.
getArray
()[
0
],
backendListener
);
}
}
}
backend/src/main/java/io/metersphere/api/service/APITestService.java
浏览文件 @
e736019e
...
@@ -90,7 +90,7 @@ public class APITestService {
...
@@ -90,7 +90,7 @@ public class APITestService {
String
reportId
=
apiReportService
.
create
(
get
(
request
.
getId
()));
String
reportId
=
apiReportService
.
create
(
get
(
request
.
getId
()));
changeStatus
(
request
.
getId
(),
APITestStatus
.
Running
);
changeStatus
(
request
.
getId
(),
APITestStatus
.
Running
);
jMeterService
.
run
(
is
);
jMeterService
.
run
(
request
.
getId
(),
is
);
return
reportId
;
return
reportId
;
}
}
...
...
frontend/src/business/components/api/test/model/ScenarioModel.js
浏览文件 @
e736019e
...
@@ -386,7 +386,6 @@ class JMXGenerator {
...
@@ -386,7 +386,6 @@ class JMXGenerator {
let
testPlan
=
new
TestPlan
(
test
.
name
);
let
testPlan
=
new
TestPlan
(
test
.
name
);
this
.
addScenarios
(
testPlan
,
test
.
scenarioDefinition
);
this
.
addScenarios
(
testPlan
,
test
.
scenarioDefinition
);
this
.
addBackendListener
(
testPlan
,
test
.
id
);
this
.
jmeterTestPlan
=
new
JMeterTestPlan
();
this
.
jmeterTestPlan
=
new
JMeterTestPlan
();
this
.
jmeterTestPlan
.
put
(
testPlan
);
this
.
jmeterTestPlan
.
put
(
testPlan
);
...
@@ -424,12 +423,6 @@ class JMXGenerator {
...
@@ -424,12 +423,6 @@ class JMXGenerator {
})
})
}
}
addBackendListener
(
testPlan
,
testId
)
{
let
className
=
'
io.metersphere.api.jmeter.APIBackendListenerClient
'
;
let
args
=
[
new
KeyValue
(
"
id
"
,
testId
)];
testPlan
.
put
(
new
BackendListener
(
testId
,
className
,
args
));
}
addScenarioVariables
(
threadGroup
,
scenario
)
{
addScenarioVariables
(
threadGroup
,
scenario
)
{
let
args
=
this
.
replaceKV
(
scenario
.
variables
);
let
args
=
this
.
replaceKV
(
scenario
.
variables
);
if
(
args
.
length
>
0
)
{
if
(
args
.
length
>
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录