Merge branch 'dev' of https://github.com/fit2cloudrd/metersphere-server into dev
This commit is contained in:
commit
e6756d5385
|
@ -128,6 +128,12 @@
|
||||||
<artifactId>opencsv</artifactId>
|
<artifactId>opencsv</artifactId>
|
||||||
<version>5.1</version>
|
<version>5.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- jmeter -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.jmeter</groupId>
|
||||||
|
<artifactId>ApacheJMeter_core</artifactId>
|
||||||
|
<version>${jmeter.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- easyexcel -->
|
<!-- easyexcel -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -31,7 +31,7 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public class PerformanceTestService {
|
public class PerformanceTestService {
|
||||||
private static final String HEADERS = "timestamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect";
|
public static final String HEADERS = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private LoadTestMapper loadTestMapper;
|
private LoadTestMapper loadTestMapper;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,101 @@
|
||||||
|
package io.metersphere;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
|
||||||
|
import io.metersphere.base.mapper.LoadTestReportMapper;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.jmeter.report.core.Sample;
|
||||||
|
import org.apache.jmeter.report.core.SampleMetadata;
|
||||||
|
import org.apache.jmeter.report.processor.SampleContext;
|
||||||
|
import org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer;
|
||||||
|
import org.apache.jmeter.report.processor.graph.impl.LatencyOverTimeGraphConsumer;
|
||||||
|
import org.apache.jmeter.util.JMeterUtils;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
public class GraphConsumerTest {
|
||||||
|
@Resource
|
||||||
|
private LoadTestReportMapper loadTestReportMapper;
|
||||||
|
private AbstractOverTimeGraphConsumer timeGraphConsumer;
|
||||||
|
// data array can't be initialized in the init()
|
||||||
|
private static String[] data = {"1527089951383", "0", "Read-compute", "200", "OK", "setupRegion 1-1", "true", "", "492", "0", "1", "1",
|
||||||
|
"null", "0", "0", "0"};
|
||||||
|
private SampleMetadata sampleMetaData = createTestMetaData();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
timeGraphConsumer = new LatencyOverTimeGraphConsumer();
|
||||||
|
timeGraphConsumer.setTitle("graph title");
|
||||||
|
timeGraphConsumer.setGranularity(60000);
|
||||||
|
|
||||||
|
JMeterUtils.loadJMeterProperties("jmeter.properties"); // 这个路径不存在
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
SampleContext sampleContext = new SampleContext();
|
||||||
|
sampleContext.setWorkingDirectory(FileUtils.getTempDirectory());
|
||||||
|
|
||||||
|
timeGraphConsumer.setSampleContext(sampleContext);
|
||||||
|
Sample sample = new Sample(0, sampleMetaData, data);
|
||||||
|
timeGraphConsumer.initialize();
|
||||||
|
timeGraphConsumer.startConsuming();
|
||||||
|
timeGraphConsumer.consume(sample, 0);
|
||||||
|
timeGraphConsumer.stopConsuming();
|
||||||
|
|
||||||
|
System.out.println(sampleContext.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test2() {
|
||||||
|
SampleContext sampleContext = new SampleContext();
|
||||||
|
sampleContext.setWorkingDirectory(new File("/tmp/test_report/"));
|
||||||
|
timeGraphConsumer.setSampleContext(sampleContext);
|
||||||
|
|
||||||
|
timeGraphConsumer.initialize();
|
||||||
|
timeGraphConsumer.startConsuming();
|
||||||
|
LoadTestReportWithBLOBs report = loadTestReportMapper.selectByPrimaryKey("7fa4dd2d-d42a-46de-92bf-10feec4c6ccf");
|
||||||
|
String content = report.getContent();
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(content, "\n");
|
||||||
|
// 去掉第一行
|
||||||
|
tokenizer.nextToken();
|
||||||
|
while (tokenizer.hasMoreTokens()) {
|
||||||
|
String line = tokenizer.nextToken();
|
||||||
|
String[] data = line.split(",", -1);
|
||||||
|
Sample sample = new Sample(0, sampleMetaData, data);
|
||||||
|
timeGraphConsumer.consume(sample, 0);
|
||||||
|
}
|
||||||
|
timeGraphConsumer.stopConsuming();
|
||||||
|
System.out.println(sampleContext.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Create a static SampleMetadataObject
|
||||||
|
private SampleMetadata createTestMetaData() {
|
||||||
|
String columnsString = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect";
|
||||||
|
columnsString = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect";
|
||||||
|
|
||||||
|
String[] columns = new String[17];
|
||||||
|
int lastComa = 0;
|
||||||
|
int columnIndex = 0;
|
||||||
|
for (int i = 0; i < columnsString.length(); i++) {
|
||||||
|
if (columnsString.charAt(i) == ',') {
|
||||||
|
columns[columnIndex] = columnsString.substring(lastComa, i);
|
||||||
|
lastComa = i + 1;
|
||||||
|
columnIndex++;
|
||||||
|
} else if (i + 1 == columnsString.length()) {
|
||||||
|
columns[columnIndex] = columnsString.substring(lastComa, i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SampleMetadata(',', columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<el-col v-if="auth">
|
<el-col v-if="auth">
|
||||||
<el-row id="header-top" type="flex" justify="space-between" align="middle">
|
<el-row id="header-top" type="flex" justify="space-between" align="middle">
|
||||||
<el-col :span="3">
|
<el-col :span="2">
|
||||||
<a class="logo"/>
|
<a class="logo"/>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="9">
|
<el-col :span="10">
|
||||||
<ms-top-menus/>
|
<ms-top-menus/>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<div>
|
<div>
|
||||||
<transition>
|
<transition>
|
||||||
<keep-alive>
|
<keep-alive>
|
||||||
<router-view :beaseUrl="beaseUrl"/>
|
<router-view :baseUrl="baseUrl"/>
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
components: {MsApiHeaderMenus},
|
components: {MsApiHeaderMenus},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
beaseUrl: "api"
|
baseUrl: "api"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<el-row type="flex" justify="end">
|
<el-row type="flex" justify="end">
|
||||||
<el-col :span="15" :offset="3">
|
<el-col :span="21">
|
||||||
<el-menu :unique-opened="true" mode="horizontal" router
|
<el-menu :unique-opened="true" mode="horizontal" router
|
||||||
class="header-user-menu align-right"
|
class="header-user-menu align-right"
|
||||||
background-color="#2c2a48"
|
background-color="#2c2a48"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<div>
|
<div>
|
||||||
<transition>
|
<transition>
|
||||||
<keep-alive>
|
<keep-alive>
|
||||||
<router-view :beaseUrl="beaseUrl"/>
|
<router-view :baseUrl="baseUrl"/>
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
components: {PerformanceHeaderMenus},
|
components: {PerformanceHeaderMenus},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
beaseUrl: "performance"
|
baseUrl: "performance"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
beaseUrl: {
|
baseUrl: {
|
||||||
type: String
|
type: String
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
if (this.$route.path.split('/')[2] === 'project' &&
|
if (this.$route.path.split('/')[2] === 'project' &&
|
||||||
this.$route.path.split('/')[3] === 'create') {
|
this.$route.path.split('/')[3] === 'create') {
|
||||||
this.create();
|
this.create();
|
||||||
this.$router.push('/' + this.beaseUrl + '/project/all');
|
this.$router.push('/' + this.baseUrl + '/project/all');
|
||||||
}
|
}
|
||||||
this.list();
|
this.list();
|
||||||
},
|
},
|
||||||
|
@ -99,7 +99,7 @@
|
||||||
if (this.$route.path.split('/')[2] === 'project' &&
|
if (this.$route.path.split('/')[2] === 'project' &&
|
||||||
to.path.split('/')[3] === 'create') {
|
to.path.split('/')[3] === 'create') {
|
||||||
this.create();
|
this.create();
|
||||||
this.$router.push('/' + this.beaseUrl + '/project/all');
|
this.$router.push('/' + this.baseUrl + '/project/all');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<div>
|
<div>
|
||||||
<transition>
|
<transition>
|
||||||
<keep-alive>
|
<keep-alive>
|
||||||
<router-view :beaseUrl="beaseUrl"/>
|
<router-view :baseUrl="baseUrl"/>
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
components: {TrackHeaderMenus},
|
components: {TrackHeaderMenus},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
beaseUrl: "track"
|
baseUrl: "track"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue