feat(性能测试): 性能测试报告页面数据自动更新时间可动态调整
This commit is contained in:
parent
e91c8f44f1
commit
f32939922e
|
@ -13,6 +13,7 @@ import javax.websocket.*;
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
import javax.websocket.server.ServerEndpoint;
|
import javax.websocket.server.ServerEndpoint;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ServerEndpoint("/performance/report/{reportId}")
|
@ServerEndpoint("/performance/report/{reportId}")
|
||||||
@Component
|
@Component
|
||||||
|
@ -20,6 +21,7 @@ public class ReportWebSocket {
|
||||||
|
|
||||||
private static ReportService reportService;
|
private static ReportService reportService;
|
||||||
private static PerformanceTestService performanceTestService;
|
private static PerformanceTestService performanceTestService;
|
||||||
|
private static ConcurrentHashMap<Session, Integer> refreshTimes = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
public void setReportService(ReportService reportService) {
|
public void setReportService(ReportService reportService) {
|
||||||
|
@ -38,6 +40,7 @@ public class ReportWebSocket {
|
||||||
public void onOpen(@PathParam("reportId") String reportId, Session session) throws IOException {
|
public void onOpen(@PathParam("reportId") String reportId, Session session) throws IOException {
|
||||||
//开启一个线程对数据库中的数据进行轮询
|
//开启一个线程对数据库中的数据进行轮询
|
||||||
ReportThread reportThread = new ReportThread(session, reportId);
|
ReportThread reportThread = new ReportThread(session, reportId);
|
||||||
|
refreshTimes.put(session, 20);
|
||||||
Thread thread = new Thread(reportThread);
|
Thread thread = new Thread(reportThread);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
@ -47,7 +50,7 @@ public class ReportWebSocket {
|
||||||
*/
|
*/
|
||||||
@OnClose
|
@OnClose
|
||||||
public void onClose(Session session) {
|
public void onClose(Session session) {
|
||||||
|
refreshTimes.remove(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +58,17 @@ public class ReportWebSocket {
|
||||||
*/
|
*/
|
||||||
@OnMessage
|
@OnMessage
|
||||||
public void onMessage(Session session, String message) {
|
public void onMessage(Session session, String message) {
|
||||||
|
int refreshTime = 20;
|
||||||
|
try {
|
||||||
|
refreshTime = Integer.parseInt(message);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
refreshTimes.put(session, refreshTime);
|
||||||
|
try {
|
||||||
|
session.getBasicRemote().sendText("refresh-" + 0);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,7 +118,7 @@ public class ReportWebSocket {
|
||||||
if (StringUtils.equalsAny(report.getStatus(), PerformanceTestStatus.Running.name(), PerformanceTestStatus.Reporting.name())) {
|
if (StringUtils.equalsAny(report.getStatus(), PerformanceTestStatus.Running.name(), PerformanceTestStatus.Reporting.name())) {
|
||||||
session.getBasicRemote().sendText("refresh-" + this.refresh++);
|
session.getBasicRemote().sendText("refresh-" + this.refresh++);
|
||||||
}
|
}
|
||||||
Thread.sleep(20 * 1000L);
|
Thread.sleep(refreshTimes.get(session) * 1000L);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
<el-button :disabled="isReadOnly" type="info" plain size="mini" @click="handleExport(reportName)">
|
<el-button :disabled="isReadOnly" type="info" plain size="mini" @click="handleExport(reportName)">
|
||||||
{{ $t('test_track.plan_view.export_report') }}
|
{{ $t('test_track.plan_view.export_report') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button :disabled="isReadOnly || report.status !== 'Completed'" type="default" plain size="mini" @click="compareReports()">
|
<el-button :disabled="isReadOnly || report.status !== 'Completed'" type="default" plain size="mini"
|
||||||
|
@click="compareReports()">
|
||||||
{{ $t('report.compare') }}
|
{{ $t('report.compare') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button :disabled="isReadOnly" type="warning" plain size="mini" @click="downloadJtl()">
|
<el-button :disabled="isReadOnly" type="warning" plain size="mini" @click="downloadJtl()">
|
||||||
|
@ -33,7 +34,7 @@
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="8">
|
<el-col :span="6">
|
||||||
<span class="ms-report-time-desc">
|
<span class="ms-report-time-desc">
|
||||||
{{ $t('report.test_duration', [this.minutes, this.seconds]) }}
|
{{ $t('report.test_duration', [this.minutes, this.seconds]) }}
|
||||||
</span>
|
</span>
|
||||||
|
@ -44,6 +45,22 @@
|
||||||
{{ $t('report.test_end_time') }}:{{ endTime }}
|
{{ $t('report.test_end_time') }}:{{ endTime }}
|
||||||
</span>
|
</span>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
<el-col :span="2">
|
||||||
|
<el-select v-model="refreshTime"
|
||||||
|
size="mini"
|
||||||
|
@change="refresh"
|
||||||
|
style="width: 100%;">
|
||||||
|
<template slot="prefix">
|
||||||
|
<i class="el-icon-refresh" style="cursor: pointer;padding-top: 8px;" @click="refresh"></i>
|
||||||
|
</template>
|
||||||
|
<el-option
|
||||||
|
v-for="item in refreshTimes"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-divider/>
|
<el-divider/>
|
||||||
|
@ -136,8 +153,19 @@ export default {
|
||||||
websocket: null,
|
websocket: null,
|
||||||
dialogFormVisible: false,
|
dialogFormVisible: false,
|
||||||
reportExportVisible: false,
|
reportExportVisible: false,
|
||||||
testPlan: {testResourcePoolId: null}
|
testPlan: {testResourcePoolId: null},
|
||||||
}
|
refreshTime: '20',
|
||||||
|
refreshTimes: [
|
||||||
|
{value: '1', label: '1s'},
|
||||||
|
{value: '3', label: '3s'},
|
||||||
|
{value: '5', label: '5s'},
|
||||||
|
{value: '10', label: '10s'},
|
||||||
|
{value: '20', label: '20s'},
|
||||||
|
{value: '30', label: '30s'},
|
||||||
|
{value: '60', label: '1m'},
|
||||||
|
{value: '300', label: '5m'}
|
||||||
|
]
|
||||||
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initBreadcrumb(callback) {
|
initBreadcrumb(callback) {
|
||||||
|
@ -155,7 +183,7 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
this.$error(this.$t('report.not_exist'));
|
this.$error(this.$t('report.not_exist'));
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
initReportTimeInfo() {
|
initReportTimeInfo() {
|
||||||
|
@ -235,7 +263,7 @@ export default {
|
||||||
this.$router.push({path: '/performance/report/view/' + this.reportId});
|
this.$router.push({path: '/performance/report/view/' + this.reportId});
|
||||||
// 注册 socket
|
// 注册 socket
|
||||||
this.initWebSocket();
|
this.initWebSocket();
|
||||||
})
|
});
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -303,10 +331,10 @@ export default {
|
||||||
aTag.download = this.reportId + ".zip";
|
aTag.download = this.reportId + ".zip";
|
||||||
aTag.href = URL.createObjectURL(blob);
|
aTag.href = URL.createObjectURL(blob);
|
||||||
aTag.click();
|
aTag.click();
|
||||||
URL.revokeObjectURL(aTag.href)
|
URL.revokeObjectURL(aTag.href);
|
||||||
} else {
|
} else {
|
||||||
// IE10+下载
|
// IE10+下载
|
||||||
navigator.msSaveBlob(blob, this.filename)
|
navigator.msSaveBlob(blob, this.filename);
|
||||||
}
|
}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
let text = e.response.data.text();
|
let text = e.response.data.text();
|
||||||
|
@ -336,9 +364,14 @@ export default {
|
||||||
this.initBreadcrumb();
|
this.initBreadcrumb();
|
||||||
this.initWebSocket();
|
this.initWebSocket();
|
||||||
} else {
|
} else {
|
||||||
this.$error(this.$t('report.not_exist'))
|
this.$error(this.$t('report.not_exist'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
refresh() {
|
||||||
|
if (this.status === 'Running') {
|
||||||
|
this.websocket.send(this.refreshTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -366,11 +399,11 @@ export default {
|
||||||
this.initWebSocket();
|
this.initWebSocket();
|
||||||
} else {
|
} else {
|
||||||
// console.log("close socket.");
|
// console.log("close socket.");
|
||||||
this.websocket.close() //离开路由之后断开websocket连接
|
this.websocket.close(); //离开路由之后断开websocket连接
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
Loading…
Reference in New Issue