Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
auto-test
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄承天
auto-test
Commits
675c3740
提交
675c3740
authored
3月 27, 2020
作者:
孙洁清
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
路由规则
上级
ddfa4f29
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
180 行增加
和
31 行删除
+180
-31
WebSocketConfig.java
src/main/java/com/zjty/autotest/config/WebSocketConfig.java
+1
-1
TestTask.java
src/main/java/com/zjty/autotest/mq/TestTask.java
+37
-27
UploadCodeServiceImpl.java
...com/zjty/autotest/service/impl/UploadCodeServiceImpl.java
+5
-3
WebSocketServer.java
...ain/java/com/zjty/autotest/websocket/WebSocketServer.java
+137
-0
没有找到文件。
src/main/java/com/zjty/autotest/config/WebSocketConfig.java
浏览文件 @
675c3740
...
@@ -6,7 +6,7 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
...
@@ -6,7 +6,7 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
@Configuration
public
class
WebSocketConfig
{
public
class
WebSocketConfig
{
//
@Bean
@Bean
public
ServerEndpointExporter
serverEndpointExporter
()
{
public
ServerEndpointExporter
serverEndpointExporter
()
{
return
new
ServerEndpointExporter
();
return
new
ServerEndpointExporter
();
}
}
...
...
src/main/java/com/zjty/autotest/mq/TestTask.java
浏览文件 @
675c3740
...
@@ -14,6 +14,7 @@ import com.zjty.autotest.service.impl.SeleniumExecutor;
...
@@ -14,6 +14,7 @@ import com.zjty.autotest.service.impl.SeleniumExecutor;
import
com.zjty.autotest.util.FileHtmlUtil
;
import
com.zjty.autotest.util.FileHtmlUtil
;
import
com.zjty.autotest.util.IdWorker
;
import
com.zjty.autotest.util.IdWorker
;
import
com.zjty.autotest.util.UnZipRarUtil
;
import
com.zjty.autotest.util.UnZipRarUtil
;
import
com.zjty.autotest.websocket.WebSocketServer
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -22,6 +23,7 @@ import org.springframework.scheduling.annotation.Scheduled;
...
@@ -22,6 +23,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.*
;
import
java.util.function.Predicate
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -80,7 +82,7 @@ public class TestTask {
...
@@ -80,7 +82,7 @@ public class TestTask {
Report
report
=
seleniumExecutor
.
execute
(
project
);
Report
report
=
seleniumExecutor
.
execute
(
project
);
System
.
out
.
println
(
report
);
System
.
out
.
println
(
report
);
List
<
Measure
>
measures
=
report
.
getMeasures
();
List
<
Measure
>
measures
=
report
.
getMeasures
();
if
(
measures
!=
null
)
{
if
(
measures
!=
null
&&
measures
.
size
()>
0
)
{
long
count
=
measures
.
stream
().
filter
(
m
->
!
m
.
getSuccess
()).
count
();
long
count
=
measures
.
stream
().
filter
(
m
->
!
m
.
getSuccess
()).
count
();
System
.
out
.
println
(
report
);
System
.
out
.
println
(
report
);
EvaReport
evaReport
=
new
EvaReport
();
EvaReport
evaReport
=
new
EvaReport
();
...
@@ -187,10 +189,10 @@ public class TestTask {
...
@@ -187,10 +189,10 @@ public class TestTask {
pageRoutes
.
add
(
route
);
pageRoutes
.
add
(
route
);
List
<
PageRoute
>
ps
=
routemap
.
get
(
s
);
List
<
PageRoute
>
ps
=
routemap
.
get
(
s
);
if
(
ps
!=
null
){
if
(
ps
!=
null
){
routemap
.
put
(
s
,
pageRoutes
);
}
else
{
ps
.
add
(
route
);
ps
.
add
(
route
);
routemap
.
put
(
s
,
ps
);
routemap
.
put
(
s
,
ps
);
}
else
{
routemap
.
put
(
s
,
pageRoutes
);
}
}
}
}
...
@@ -217,9 +219,15 @@ public class TestTask {
...
@@ -217,9 +219,15 @@ public class TestTask {
testReportService
.
update
(
testReport
);
testReportService
.
update
(
testReport
);
autoResultSetService
.
updateByid
(
id
);
autoResultSetService
.
updateByid
(
id
);
WebSocketServer
.
sendInfo
(
"测试完成,"
+
id
,
"sjq110"
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
try
{
WebSocketServer
.
sendInfo
(
"测试失败,"
+
id
,
"sjq110"
);
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
}
}
}
...
@@ -229,36 +237,38 @@ public class TestTask {
...
@@ -229,36 +237,38 @@ public class TestTask {
String
pattern
=
"(\\/:*[a-zA-Z0-9]+)+"
;
String
pattern
=
"(\\/:*[a-zA-Z0-9]+)+"
;
List
<
String
>
allRouters
=
new
ArrayList
<>();
List
<
String
>
allRouters
=
new
ArrayList
<>();
Set
<
String
>
all
=
alls
.
keySet
();
Set
<
String
>
all
=
alls
.
keySet
();
//所有的路由
if
(
all
!=
null
)
{
if
(
fileRoutes
.
equals
(
"vue"
))
{
//所有的路由
for
(
String
s1
:
all
)
{
if
(
fileRoutes
.
equals
(
"vue"
))
{
List
<
FileType
>
fileBeans
=
alls
.
get
(
s1
);
for
(
String
s1
:
all
)
{
if
(
fileRoutes
!=
null
)
{
List
<
FileType
>
fileBeans
=
alls
.
get
(
s1
);
if
(
s1
.
contains
(
"router"
))
{
if
(
fileRoutes
!=
null
)
{
for
(
FileType
fileBean
:
fileBeans
)
{
if
(
s1
.
contains
(
"router"
))
{
allRouters
.
addAll
(
FileHtmlUtil
.
readTxtFile
(
fileBean
.
getAddress
(),
pattern
));
for
(
FileType
fileBean
:
fileBeans
)
{
allRouters
.
addAll
(
FileHtmlUtil
.
readTxtFile
(
fileBean
.
getAddress
(),
pattern
));
}
}
}
}
}
}
}
}
}
else
if
(
fileRoutes
.
equals
(
"angular"
)
||
fileRoutes
.
equals
(
"react"
))
{
}
else
if
(
fileRoutes
.
equals
(
"angular"
)||
fileRoutes
.
equals
(
"react"
))
{
for
(
String
s1
:
all
)
{
for
(
String
s1
:
all
)
{
List
<
FileType
>
fileBeans
=
alls
.
get
(
s1
);
List
<
FileType
>
fileBeans
=
alls
.
get
(
s1
);
if
(
fileRoutes
!=
null
)
{
if
(
fileRoutes
!=
null
)
{
for
(
FileType
fileBean
:
fileBeans
)
{
for
(
FileType
fileBean
:
fileBeans
)
{
if
(
fileBean
.
getSuffix
().
equals
(
"js"
)
)
{
if
(
fileBean
.
getSuffix
().
equals
(
"js"
))
{
allRouters
.
addAll
(
FileHtmlUtil
.
readTxtFile
(
fileBean
.
getAddress
(),
pattern
));
allRouters
.
addAll
(
FileHtmlUtil
.
readTxtFile
(
fileBean
.
getAddress
(),
pattern
));
}
}
}
}
}
}
}
}
}
else
{
}
else
{
for
(
String
s1
:
all
)
{
for
(
String
s1
:
all
)
{
List
<
FileType
>
fileBeans
=
alls
.
get
(
s1
);
List
<
FileType
>
fileBeans
=
alls
.
get
(
s1
);
if
(
fileRoutes
!=
null
)
{
if
(
fileRoutes
!=
null
)
{
for
(
FileType
fileBean
:
fileBeans
)
{
for
(
FileType
fileBean
:
fileBeans
)
{
if
(
fileBean
.
getSuffix
().
equals
(
"jsp"
)
)
{
if
(
fileBean
.
getSuffix
().
equals
(
"jsp"
))
{
allRouters
.
addAll
(
FileHtmlUtil
.
readTxtFile
(
fileBean
.
getAddress
(),
pattern
));
allRouters
.
addAll
(
FileHtmlUtil
.
readTxtFile
(
fileBean
.
getAddress
(),
pattern
));
}
}
}
}
}
}
}
...
...
src/main/java/com/zjty/autotest/service/impl/UploadCodeServiceImpl.java
浏览文件 @
675c3740
...
@@ -34,13 +34,13 @@ public class UploadCodeServiceImpl implements UploadCodeService {
...
@@ -34,13 +34,13 @@ public class UploadCodeServiceImpl implements UploadCodeService {
return
ResponseResult
.
errorResult
(
AppHttpCodeEnum
.
File_Empty
);
return
ResponseResult
.
errorResult
(
AppHttpCodeEnum
.
File_Empty
);
}
}
String
fileName
=
file
.
getOriginalFilename
();
String
fileName
=
file
.
getOriginalFilename
();
// String fileType = fileName.substring(
fileName.lastIndexOf("."));
String
fileType
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
));
File
dest
=
new
File
(
uploadFile
+
File
.
separator
+
idWorker
.
nextId
()+
File
.
separator
+
file
Nam
e
);
File
dest
=
new
File
(
uploadFile
+
File
.
separator
+
idWorker
.
nextId
()+
File
.
separator
+
file
Typ
e
);
if
(!
dest
.
getParentFile
().
exists
())
{
if
(!
dest
.
getParentFile
().
exists
())
{
dest
.
getParentFile
().
mkdirs
();
dest
.
getParentFile
().
mkdirs
();
}
}
file
.
transferTo
(
dest
);
file
.
transferTo
(
dest
);
String
toUrl
=
uploadUnFile
+
File
.
separator
+
idWorker
.
nextId
()+
File
.
separator
+
fileName
;
String
toUrl
=
uploadUnFile
+
idWorker
.
nextId
()+
File
.
separator
+
fileName
;
String
s
=
UnZipRarUtil
.
zipRarToFile
(
fileName
,
dest
.
getPath
(),
toUrl
);
String
s
=
UnZipRarUtil
.
zipRarToFile
(
fileName
,
dest
.
getPath
(),
toUrl
);
FileBean
bean
=
new
FileBean
(
s
,
fileName
);
FileBean
bean
=
new
FileBean
(
s
,
fileName
);
...
@@ -53,4 +53,6 @@ public class UploadCodeServiceImpl implements UploadCodeService {
...
@@ -53,4 +53,6 @@ public class UploadCodeServiceImpl implements UploadCodeService {
}
}
}
}
src/main/java/com/zjty/autotest/websocket/WebSocketServer.java
0 → 100644
浏览文件 @
675c3740
package
com
.
zjty
.
autotest
.
websocket
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
javax.websocket.*
;
import
javax.websocket.server.PathParam
;
import
javax.websocket.server.ServerEndpoint
;
import
java.io.IOException
;
import
java.util.concurrent.ConcurrentHashMap
;
@ServerEndpoint
(
"/imserver/{userId}"
)
@Component
@Slf4j
public
class
WebSocketServer
{
/**静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。*/
private
static
int
onlineCount
=
0
;
/**concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。*/
private
static
ConcurrentHashMap
<
String
,
WebSocketServer
>
webSocketMap
=
new
ConcurrentHashMap
<>();
/**与某个客户端的连接会话,需要通过它来给客户端发送数据*/
private
Session
session
;
/**接收userId*/
private
String
userId
=
""
;
/**
* 连接建立成功调用的方法*/
@OnOpen
public
void
onOpen
(
Session
session
,
@PathParam
(
"userId"
)
String
userId
)
{
this
.
session
=
session
;
this
.
userId
=
userId
;
if
(
webSocketMap
.
containsKey
(
userId
)){
webSocketMap
.
remove
(
userId
);
webSocketMap
.
put
(
userId
,
this
);
//加入set中
}
else
{
webSocketMap
.
put
(
userId
,
this
);
//加入set中
addOnlineCount
();
//在线数加1
}
log
.
info
(
"用户连接:"
+
userId
+
",当前在线人数为:"
+
getOnlineCount
());
try
{
sendMessage
(
"连接成功"
);
}
catch
(
IOException
e
)
{
log
.
error
(
"用户:"
+
userId
+
",网络异常!!!!!!"
);
}
}
/**
* 连接关闭调用的方法
*/
@OnClose
public
void
onClose
()
{
if
(
webSocketMap
.
containsKey
(
userId
)){
webSocketMap
.
remove
(
userId
);
//从set中删除
subOnlineCount
();
}
log
.
info
(
"用户退出:"
+
userId
+
",当前在线人数为:"
+
getOnlineCount
());
}
/**
* 收到客户端消息后调用的方法
*
* @param message 客户端发送过来的消息*/
@OnMessage
public
void
onMessage
(
String
message
,
Session
session
)
{
log
.
info
(
"用户消息:"
+
userId
+
",报文:"
+
message
);
//可以群发消息
//消息保存到数据库、redis
/*if(StringUtils.isNotBlank(message)){
try {
//解析发送的报文
JSONObject jsonObject = JSON.parseObject(message);
//追加发送人(防止串改)
jsonObject.put("fromUserId",this.userId);
String toUserId=jsonObject.getString("toUserId");
//传送给对应toUserId用户的websocket
if(StringUtils.isNotBlank(toUserId)&&webSocketMap.containsKey(toUserId)){
webSocketMap.get(toUserId).sendMessage(jsonObject.toJSONString());
}else{
log.error("请求的userId:"+toUserId+"不在该服务器上");
//否则不在这个服务器上,发送到mysql或者redis
}
}catch (Exception e){
e.printStackTrace();
}
}*/
}
/**
*
* @param session
* @param error
*/
@OnError
public
void
onError
(
Session
session
,
Throwable
error
)
{
log
.
error
(
"用户错误:"
+
this
.
userId
+
",原因:"
+
error
.
getMessage
());
error
.
printStackTrace
();
}
/**
* 实现服务器主动推送
*/
public
void
sendMessage
(
String
message
)
throws
IOException
{
this
.
session
.
getBasicRemote
().
sendText
(
message
);
}
/**
* 发送自定义消息
* */
public
static
void
sendInfo
(
String
message
,
@PathParam
(
"userId"
)
String
userId
)
throws
IOException
{
log
.
info
(
"发送消息到:"
+
userId
+
",报文:"
+
message
);
if
(
StringUtils
.
isNotBlank
(
userId
)&&
webSocketMap
.
containsKey
(
userId
)){
webSocketMap
.
get
(
userId
).
sendMessage
(
message
);
}
else
{
log
.
error
(
"用户"
+
userId
+
",不在线!"
);
}
}
public
static
synchronized
int
getOnlineCount
()
{
return
onlineCount
;
}
public
static
synchronized
void
addOnlineCount
()
{
WebSocketServer
.
onlineCount
++;
}
public
static
synchronized
void
subOnlineCount
()
{
WebSocketServer
.
onlineCount
--;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论