Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
xiaofang li
MeterSphere
Commits
3c405804
Commit
3c405804
authored
3 years ago
by
fit2-zhao
Committed by
fit2-zhao
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
fix(接口测试): 修复调试时websocket 同步到消息内容问题
parent
af124898
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java
+2
-2
...rc/main/java/io/metersphere/api/jmeter/JMeterService.java
backend/src/main/java/io/metersphere/api/jmeter/MsResultCollector.java
+15
-29
...ain/java/io/metersphere/api/jmeter/MsResultCollector.java
backend/src/main/java/io/metersphere/websocket/c/to/c/IndexWebSocket.java
+2
-2
.../java/io/metersphere/websocket/c/to/c/IndexWebSocket.java
backend/src/main/java/io/metersphere/websocket/c/to/c/WebSocketUtils.java
+23
-2
.../java/io/metersphere/websocket/c/to/c/WebSocketUtils.java
backend/src/main/java/io/metersphere/websocket/c/to/c/util/SocketClient.java
+0
-19
...va/io/metersphere/websocket/c/to/c/util/SocketClient.java
frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue
+1
-1
.../components/api/automation/report/SysnApiReportDetail.vue
frontend/src/business/components/api/automation/scenario/EditApiScenario.vue
+1
-1
...ss/components/api/automation/scenario/EditApiScenario.vue
with
44 additions
and
56 deletions
+44
-56
backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java
+
2
-
2
View file @
3c405804
...
...
@@ -68,9 +68,9 @@ public class JMeterService {
}
private
void
addDebugListener
(
String
testId
,
HashTree
testPlan
)
{
Ms
DebugListene
r
resultCollector
=
new
Ms
DebugListene
r
();
Ms
ResultCollecto
r
resultCollector
=
new
Ms
ResultCollecto
r
();
resultCollector
.
setName
(
testId
);
resultCollector
.
setProperty
(
TestElement
.
TEST_CLASS
,
Ms
DebugListene
r
.
class
.
getName
());
resultCollector
.
setProperty
(
TestElement
.
TEST_CLASS
,
Ms
ResultCollecto
r
.
class
.
getName
());
resultCollector
.
setProperty
(
TestElement
.
GUI_CLASS
,
SaveService
.
aliasToClass
(
"ViewResultsFullVisualizer"
));
resultCollector
.
setEnabled
(
true
);
testPlan
.
add
(
testPlan
.
getArray
()[
0
],
resultCollector
);
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/api/jmeter/Ms
DebugListene
r.java
→
backend/src/main/java/io/metersphere/api/jmeter/Ms
ResultCollecto
r.java
+
15
-
29
View file @
3c405804
...
...
@@ -23,11 +23,10 @@ import io.metersphere.api.service.MsResultService;
import
io.metersphere.commons.utils.CommonBeanFactory
;
import
io.metersphere.commons.utils.LogUtil
;
import
io.metersphere.dto.RequestResult
;
import
io.metersphere.dto.ResultDTO
;
import
io.metersphere.jmeter.JMeterBase
;
import
io.metersphere.utils.JMeterVars
;
import
io.metersphere.utils.LoggerUtil
;
import
io.metersphere.websocket.c.to.c.
Ms
WebSocket
Client
;
import
io.metersphere.websocket.c.to.c.WebSocket
Utils
;
import
io.metersphere.websocket.c.to.c.util.MsgDto
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -44,7 +43,7 @@ import java.util.Map;
/**
* 实时结果监听
*/
public
class
Ms
DebugListene
r
extends
AbstractListenerElement
implements
SampleListener
,
Clearable
,
Serializable
,
public
class
Ms
ResultCollecto
r
extends
AbstractListenerElement
implements
SampleListener
,
Clearable
,
Serializable
,
TestStateListener
,
Remoteable
,
NoThreadClone
{
private
static
final
String
ERROR_LOGGING
=
"MsResultCollector.error_logging"
;
// $NON-NLS-1$
...
...
@@ -55,11 +54,9 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi
public
static
final
String
TEST_END
=
"MS_TEST_END"
;
private
MsWebSocketClient
client
;
@Override
public
Object
clone
()
{
Ms
DebugListener
clone
=
(
MsDebugListene
r
)
super
.
clone
();
Ms
ResultCollector
clone
=
(
MsResultCollecto
r
)
super
.
clone
();
return
clone
;
}
...
...
@@ -100,28 +97,20 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi
@Override
public
void
testEnded
(
String
host
)
{
LoggerUtil
.
debug
(
"TestEnded "
+
this
.
getName
());
SampleResult
result
=
new
SampleResult
();
result
.
setResponseCode
(
TEST_END
);
ResultDTO
dto
=
new
ResultDTO
();
dto
.
setReportId
(
this
.
getName
());
try
{
if
(
client
!=
null
)
{
client
.
close
();
}
}
catch
(
Exception
e
)
{
LogUtil
.
error
(
e
);
}
MsgDto
dto
=
new
MsgDto
();
dto
.
setExecEnd
(
false
);
dto
.
setContent
(
TEST_END
);
dto
.
setReportId
(
"send."
+
this
.
getName
());
dto
.
setToReport
(
this
.
getName
());
LoggerUtil
.
debug
(
"send. "
+
this
.
getName
());
WebSocketUtils
.
sendMessageSingle
(
dto
);
WebSocketUtils
.
onClose
(
this
.
getName
());
}
@Override
public
void
testStarted
(
String
host
)
{
LogUtil
.
debug
(
"TestStarted "
+
this
.
getName
());
try
{
client
=
new
MsWebSocketClient
(
"ws://127.0.0.1:8081/ws/"
+
"send."
+
this
.
getName
());
client
.
connect
();
}
catch
(
Exception
e
)
{
LogUtil
.
error
(
e
);
}
}
@Override
...
...
@@ -142,10 +131,9 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi
dto
.
setReportId
(
"send."
+
this
.
getName
());
dto
.
setToReport
(
this
.
getName
());
LoggerUtil
.
debug
(
"send. "
+
this
.
getName
());
if
(
client
!=
null
)
{
client
.
send
(
JSON
.
toJSONString
(
dto
));
}
WebSocketUtils
.
sendMessageSingle
(
dto
);
}
catch
(
Exception
ex
)
{
LoggerUtil
.
error
(
"消息推送失败:"
+
ex
.
getMessage
());
}
}
...
...
@@ -179,9 +167,7 @@ public class MsDebugListener extends AbstractListenerElement implements SampleLi
dto
.
setReportId
(
"send."
+
this
.
getName
());
dto
.
setToReport
(
this
.
getName
());
LoggerUtil
.
debug
(
"send. "
+
this
.
getName
());
if
(
client
!=
null
)
{
client
.
send
(
JSON
.
toJSONString
(
dto
));
}
WebSocketUtils
.
sendMessageSingle
(
dto
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/websocket/c/to/c/IndexWebSocket.java
+
2
-
2
View file @
3c405804
...
...
@@ -22,7 +22,7 @@ public class IndexWebSocket {
public
void
openSession
(
@PathParam
(
"reportId"
)
String
reportId
,
Session
session
)
{
WebSocketUtils
.
ONLINE_USER_SESSIONS
.
put
(
reportId
,
session
);
log
.
info
(
"客户端: ["
+
reportId
+
"] : 连接成功!"
);
WebSocketUtils
.
sendMessageAll
(
"客户端: ["
+
reportId
+
"] : 连接成功!"
);
//
WebSocketUtils.sendMessageAll("客户端: [" + reportId + "] : 连接成功!");
}
/**
...
...
@@ -45,7 +45,7 @@ public class IndexWebSocket {
WebSocketUtils
.
ONLINE_USER_SESSIONS
.
remove
(
reportId
);
log
.
info
(
"["
+
reportId
+
"] : 断开连接!"
);
//并且通知其他人当前用户已经断开连接了
WebSocketUtils
.
sendMessageAll
(
"["
+
reportId
+
"] : 断开连接!"
);
//
WebSocketUtils.sendMessageAll("[" + reportId + "] : 断开连接!");
session
.
close
();
}
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/websocket/c/to/c/WebSocketUtils.java
+
23
-
2
View file @
3c405804
package
io.metersphere.websocket.c.to.c
;
import
io.metersphere.utils.LoggerUtil
;
import
io.metersphere.websocket.c.to.c.util.MsgDto
;
import
javax.websocket.RemoteEndpoint
;
...
...
@@ -12,9 +13,13 @@ public class WebSocketUtils {
// 单用户推送
public
static
void
sendMessage
(
Session
session
,
String
message
)
{
if
(
session
==
null
)
{
return
;
}
if
(
session
==
null
)
{
return
;
}
RemoteEndpoint
.
Async
async
=
session
.
getAsyncRemote
();
if
(
async
==
null
)
{
return
;
}
if
(
async
==
null
)
{
return
;
}
async
.
sendText
(
message
);
}
...
...
@@ -30,4 +35,20 @@ public class WebSocketUtils {
sendMessage
(
session
,
message
);
});
}
//当前的Session 移除
public
static
void
onClose
(
String
reportId
)
{
try
{
if
(
WebSocketUtils
.
ONLINE_USER_SESSIONS
.
containsKey
(
reportId
))
{
WebSocketUtils
.
ONLINE_USER_SESSIONS
.
get
(
reportId
).
close
();
WebSocketUtils
.
ONLINE_USER_SESSIONS
.
remove
(
reportId
);
}
if
(
WebSocketUtils
.
ONLINE_USER_SESSIONS
.
containsKey
((
"send."
+
reportId
)))
{
WebSocketUtils
.
ONLINE_USER_SESSIONS
.
get
((
"send."
+
reportId
)).
close
();
WebSocketUtils
.
ONLINE_USER_SESSIONS
.
remove
((
"send."
+
reportId
));
}
}
catch
(
Exception
e
)
{
LoggerUtil
.
error
(
"关闭socket失败:"
+
e
.
getMessage
());
}
}
}
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/websocket/c/to/c/util/SocketClient.java
deleted
100644 → 0
+
0
-
19
View file @
af124898
package
io.metersphere.websocket.c.to.c.util
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @author: jason
* @Date: 2020-12-23
*/
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public
class
SocketClient
{
private
Integer
userId
;
private
String
username
;
}
This diff is collapsed.
Click to expand it.
frontend/src/business/components/api/automation/report/SysnApiReportDetail.vue
+
1
-
1
View file @
3c405804
...
...
@@ -356,7 +356,7 @@ export default {
if
(
e
.
data
)
{
this
.
runningEvaluation
(
e
.
data
);
}
if
(
e
.
data
&&
e
.
data
.
indexOf
(
"
断开连接
"
)
!==
-
1
)
{
if
(
e
.
data
&&
e
.
data
.
indexOf
(
"
MS_TEST_END
"
)
!==
-
1
)
{
this
.
getReport
();
this
.
messageWebSocket
.
close
();
scenario
.
$emit
(
'
hide
'
,
this
.
scenarioId
);
...
...
This diff is collapsed.
Click to expand it.
frontend/src/business/components/api/automation/scenario/EditApiScenario.vue
+
1
-
1
View file @
3c405804
...
...
@@ -789,7 +789,7 @@ export default {
}
this
.
runningEvaluation
(
e
.
data
);
this
.
message
=
getUUID
();
if
(
e
.
data
&&
e
.
data
.
indexOf
(
"
断开连接
"
)
!==
-
1
)
{
if
(
e
.
data
&&
e
.
data
.
indexOf
(
"
MS_TEST_END
"
)
!==
-
1
)
{
this
.
runScenario
=
undefined
;
this
.
debugLoading
=
false
;
this
.
message
=
"
stop
"
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help