From 3af71757766a2081b8ecf864b6455f2bced2af7f Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 11 May 2022 14:53:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=A7=E6=89=B9=E9=87=8F=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=90=AB=E8=87=AA=E5=AE=9A=E4=B9=89=E8=84=9A=E6=9C=AC=E5=92=8C?= =?UTF-8?q?CSV=E6=96=87=E4=BB=B6=E5=AF=BC=E8=87=B4=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E9=98=BB=E5=A1=9E=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 1278 ++++++++--------- .../api/jmeter/APISingleResultListener.java | 20 +- .../metersphere/api/jmeter/JMeterService.java | 16 + .../api/jmeter/KafkaListenerTask.java | 5 +- ...rvice.java => MsGroovyLoadJarService.java} | 3 +- .../api/jmeter/MsKafkaListener.java | 4 +- 6 files changed, 681 insertions(+), 645 deletions(-) rename backend/src/main/java/io/metersphere/api/jmeter/{GroovyLoadJarService.java => MsGroovyLoadJarService.java} (91%) diff --git a/backend/pom.xml b/backend/pom.xml index 7f8de4c540..21488c724f 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -1,639 +1,639 @@ - - - - - - metersphere-server - io.metersphere - ${revision} - - - 4.0.0 - backend - - - UTF-8 - 1.8.0 - 11 - 7.15.0 - 2.7.15 - false - - - - - org.springframework.boot - spring-boot-starter-web - - - spring-boot-starter-tomcat - org.springframework.boot - - - - - - org.springframework.boot - spring-boot-configuration-processor - - - - org.springframework.boot - spring-boot-starter - - - - org.springframework.boot - spring-boot-starter-actuator - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework.boot - spring-boot-starter-aop - - - org.springframework.boot - spring-boot-starter-undertow - - - org.springframework.boot - spring-boot-starter-mail - - - org.springframework.kafka - spring-kafka - - - org.projectlombok - lombok - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - 2.2.2 - - - - org.springframework.boot - spring-boot-starter-websocket - - - - org.springframework.boot - spring-boot-starter-validation - - - - - io.metersphere - jmeter-plugins-webdriver - 3.4 - - - org.apache.jmeter - ApacheJMeter_core - - - slf4j-nop - org.slf4j - - - servlet-api - javax.servlet - - - mail - javax.mail - - - geronimo-spec-javamail - geronimo-spec - - - - - - - org.flywaydb - flyway-core - - - mysql - mysql-connector-java - runtime - - - com.github.pagehelper - pagehelper - 5.3.0 - - - - org.apache.shiro - shiro-spring-boot-starter - ${shiro.version} - - - org.redisson - redisson-spring-boot-starter - 3.17.0 - - - org.springframework.session - spring-session-data-redis - - - - org.apache.commons - commons-lang3 - - - org.apache.commons - commons-text - 1.8 - - - commons-codec - commons-codec - - - - com.alibaba - fastjson - 1.2.80 - - - - - org.springdoc - springdoc-openapi-ui - 1.6.3 - - - - - org.springframework.boot - spring-boot-starter-rsocket - - - - io.metersphere - ms-jmeter-core - 1.1.6 - - - netty - io.netty - - - mail - javax.mail - - - - - - - org.apache.dubbo - dubbo - ${dubbo.version} - - - spring-context - org.springframework - - - - - - com.google.inject - guice - 5.1.0 - - - - xz - org.tukaani - 1.9 - - - - - - com.thoughtworks.xstream - xstream - 1.4.19 - - - - - com.alibaba - easyexcel - 2.2.10 - - - - org.apache.xmlbeans - xmlbeans - 3.0.0 - - - - - com.fit2cloud - quartz-spring-boot-starter - 0.0.9 - - - - - - org.springframework.boot - spring-boot-starter-data-ldap - - - - - io.swagger.parser.v3 - swagger-parser - 2.0.24 - - - - - - org.mozilla - rhino-engine - 1.7.13 - - - - org.jsoup - jsoup - 1.14.2 - - - - com.atlassian.commonmark - commonmark - 0.15.2 - - - - org.apache.commons - commons-compress - 1.21 - - - - org.dom4j - dom4j - 2.1.3 - - - - jaxen - jaxen - 1.2.0 - - - net.sourceforge.htmlcleaner - htmlcleaner - 2.24 - - - - org.apache.httpcomponents - httpclient - - - - org.reflections - reflections - 0.10.2 - - - - io.fabric8 - kubernetes-client - 4.13.2 - - - - org.java-websocket - Java-WebSocket - 1.5.0 - - - - com.github.eljah - xmindjbehaveplugin - 0.8 - - - org.codehaus.plexus - plexus-utils - 3.0.24 - - - - org.seleniumhq.selenium - selenium-java - - - - io.metersphere - metersphere-plugin-core - 1.0.1 - - - log4j-slf4j-impl - org.apache.logging.log4j - - - ApacheJMeter_core - org.apache.jmeter - - - - - - com.apifan.common - common-random - 1.0.7 - - - com.github.mifmif - generex - 1.0.2 - - - - net.sf.json-lib - json-lib - 2.4 - jdk15 - - - - guava - com.google.guava - 31.0.1-jre - - - - - com.github.java-json-tools - json-schema-validator - 2.2.14 - - - - - - - src/main/java - - **/*.properties - **/*.xml - **/*.json - **/*.tpl - **/*.js - - false - - - src/main/resources - - **/* - - false - - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - org.projectlombok - lombok - - - org.springframework.boot - spring-boot-configuration-processor - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - true - - - - maven-clean-plugin - - - - src/main/resources/static - - ** - - false - - - src/main/resources/public - - ** - - false - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 11 - - - - - - org.apache.maven.plugins - maven-war-plugin - 2.6 - - - - - org.apache.maven.plugins - maven-antrun-plugin - - - main-class-placement - generate-resources - - ${skipAntRunForJenkins} - - - - - - - - - - - - - - - - - - - - run - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy - generate-resources - - copy - - - - - - - org.apache.jmeter - ApacheJMeter_functions - 5.4.3 - jar - true - src/main/resources/jmeter/lib/ext - ApacheJMeter_functions.jar - - - io.metersphere - metersphere-jmeter-functions - 1.4 - jar - true - src/main/resources/jmeter/lib/ext - metersphere-jmeter-functions.jar - - - org.python - jython-standalone - 2.7.2 - jar - true - src/main/resources/jmeter/lib/ext - jython-standalone.jar - - - ${project.build.directory}/wars - false - true - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.3.7 - - true - true - - - - mysql - mysql-connector-java - 8.0.16 - - - com.itfsw - mybatis-generator-plugin - 1.3.8 - - - - - org.apache.maven.plugins - maven-resources-plugin - - - copy-and-filter-allatori-config - package - - copy-resources - - - ${basedir}/target - - - ${basedir}/allatori - - allatori.xml - - true - - - - - - - - org.codehaus.mojo - exec-maven-plugin - - - run-allatori - package - - exec - - - - - java - - -Xms128m - -Xmx512m - -jar - ${basedir}/target/classes/allatori/allatori.jar - ${basedir}/target/classes/allatori/allatori.xml - - - - - - - + + + + + + metersphere-server + io.metersphere + ${revision} + + + 4.0.0 + backend + + + UTF-8 + 1.8.0 + 11 + 7.15.0 + 2.7.15 + false + + + + + org.springframework.boot + spring-boot-starter-web + + + spring-boot-starter-tomcat + org.springframework.boot + + + + + + org.springframework.boot + spring-boot-configuration-processor + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework.boot + spring-boot-starter-undertow + + + org.springframework.boot + spring-boot-starter-mail + + + org.springframework.kafka + spring-kafka + + + org.projectlombok + lombok + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + org.springframework.boot + spring-boot-starter-websocket + + + + org.springframework.boot + spring-boot-starter-validation + + + + + io.metersphere + jmeter-plugins-webdriver + 3.4 + + + org.apache.jmeter + ApacheJMeter_core + + + slf4j-nop + org.slf4j + + + servlet-api + javax.servlet + + + mail + javax.mail + + + geronimo-spec-javamail + geronimo-spec + + + + + + + org.flywaydb + flyway-core + + + mysql + mysql-connector-java + runtime + + + com.github.pagehelper + pagehelper + 5.3.0 + + + + org.apache.shiro + shiro-spring-boot-starter + ${shiro.version} + + + org.redisson + redisson-spring-boot-starter + 3.17.0 + + + org.springframework.session + spring-session-data-redis + + + + org.apache.commons + commons-lang3 + + + org.apache.commons + commons-text + 1.8 + + + commons-codec + commons-codec + + + + com.alibaba + fastjson + 1.2.80 + + + + + org.springdoc + springdoc-openapi-ui + 1.6.3 + + + + + org.springframework.boot + spring-boot-starter-rsocket + + + + io.metersphere + ms-jmeter-core + 1.1.7 + + + netty + io.netty + + + mail + javax.mail + + + + + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + spring-context + org.springframework + + + + + + com.google.inject + guice + 5.1.0 + + + + xz + org.tukaani + 1.9 + + + + + + com.thoughtworks.xstream + xstream + 1.4.19 + + + + + com.alibaba + easyexcel + 2.2.10 + + + + org.apache.xmlbeans + xmlbeans + 3.0.0 + + + + + com.fit2cloud + quartz-spring-boot-starter + 0.0.9 + + + + + + org.springframework.boot + spring-boot-starter-data-ldap + + + + + io.swagger.parser.v3 + swagger-parser + 2.0.24 + + + + + + org.mozilla + rhino-engine + 1.7.13 + + + + org.jsoup + jsoup + 1.14.2 + + + + com.atlassian.commonmark + commonmark + 0.15.2 + + + + org.apache.commons + commons-compress + 1.21 + + + + org.dom4j + dom4j + 2.1.3 + + + + jaxen + jaxen + 1.2.0 + + + net.sourceforge.htmlcleaner + htmlcleaner + 2.24 + + + + org.apache.httpcomponents + httpclient + + + + org.reflections + reflections + 0.10.2 + + + + io.fabric8 + kubernetes-client + 4.13.2 + + + + org.java-websocket + Java-WebSocket + 1.5.0 + + + + com.github.eljah + xmindjbehaveplugin + 0.8 + + + org.codehaus.plexus + plexus-utils + 3.0.24 + + + + org.seleniumhq.selenium + selenium-java + + + + io.metersphere + metersphere-plugin-core + 1.0.1 + + + log4j-slf4j-impl + org.apache.logging.log4j + + + ApacheJMeter_core + org.apache.jmeter + + + + + + com.apifan.common + common-random + 1.0.7 + + + com.github.mifmif + generex + 1.0.2 + + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + + guava + com.google.guava + 31.0.1-jre + + + + + com.github.java-json-tools + json-schema-validator + 2.2.14 + + + + + + + src/main/java + + **/*.properties + **/*.xml + **/*.json + **/*.tpl + **/*.js + + false + + + src/main/resources + + **/* + + false + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + org.projectlombok + lombok + + + org.springframework.boot + spring-boot-configuration-processor + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + true + + + + maven-clean-plugin + + + + src/main/resources/static + + ** + + false + + + src/main/resources/public + + ** + + false + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + + + + + + org.apache.maven.plugins + maven-war-plugin + 2.6 + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + main-class-placement + generate-resources + + ${skipAntRunForJenkins} + + + + + + + + + + + + + + + + + + + + run + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + generate-resources + + copy + + + + + + + org.apache.jmeter + ApacheJMeter_functions + 5.4.3 + jar + true + src/main/resources/jmeter/lib/ext + ApacheJMeter_functions.jar + + + io.metersphere + metersphere-jmeter-functions + 1.4 + jar + true + src/main/resources/jmeter/lib/ext + metersphere-jmeter-functions.jar + + + org.python + jython-standalone + 2.7.2 + jar + true + src/main/resources/jmeter/lib/ext + jython-standalone.jar + + + ${project.build.directory}/wars + false + true + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.3.7 + + true + true + + + + mysql + mysql-connector-java + 8.0.16 + + + com.itfsw + mybatis-generator-plugin + 1.3.8 + + + + + org.apache.maven.plugins + maven-resources-plugin + + + copy-and-filter-allatori-config + package + + copy-resources + + + ${basedir}/target + + + ${basedir}/allatori + + allatori.xml + + true + + + + + + + + org.codehaus.mojo + exec-maven-plugin + + + run-allatori + package + + exec + + + + + java + + -Xms128m + -Xmx512m + -jar + ${basedir}/target/classes/allatori/allatori.jar + ${basedir}/target/classes/allatori/allatori.xml + + + + + + + diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APISingleResultListener.java b/backend/src/main/java/io/metersphere/api/jmeter/APISingleResultListener.java index eb66c0fb5f..982b94eae7 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APISingleResultListener.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APISingleResultListener.java @@ -7,20 +7,32 @@ import io.metersphere.api.service.TestResultService; import io.metersphere.cache.JMeterEngineCache; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.dto.ResultDTO; +import io.metersphere.jmeter.JMeterBase; import io.metersphere.jmeter.MsExecListener; import io.metersphere.utils.LoggerUtil; import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.samplers.SampleResult; +import java.util.List; import java.util.Map; -public class APISingleResultListener extends MsExecListener { +public class APISingleResultListener implements MsExecListener { private ApiExecutionQueueService apiExecutionQueueService; + /** + * 参数初始化方法 + */ @Override - public void handleTeardownTest(ResultDTO dto, Map kafkaConfig) { + public void setupTest() { + LoggerUtil.info("初始化监听"); + } + + @Override + public void handleTeardownTest(List results, ResultDTO dto, Map kafkaConfig) { LoggerUtil.info("接收到执行结果开始处理报告【" + dto.getReportId() + " 】,资源【 " + dto.getTestId() + " 】"); dto.setConsole(FixedCapacityUtils.getJmeterLogger(dto.getReportId())); + JMeterBase.resultFormatting(results, dto); CommonBeanFactory.getBean(TestResultService.class).saveResults(dto); } @@ -50,6 +62,10 @@ public class APISingleResultListener extends MsExecListener { } } catch (Exception e) { LoggerUtil.error(e); + } finally { + if (FixedCapacityUtils.jmeterLogTask.containsKey(dto.getReportId())) { + FixedCapacityUtils.jmeterLogTask.remove(dto.getReportId()); + } } } } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index b1938c2149..75386f7c59 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -11,6 +11,7 @@ import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.config.JmeterProperties; import io.metersphere.config.KafkaConfig; +import io.metersphere.constants.BackendListenerConstants; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.JmeterRunRequestDTO; import io.metersphere.dto.JvmInfoDTO; @@ -22,9 +23,11 @@ import io.metersphere.performance.engine.EngineFactory; import io.metersphere.utils.LoggerUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; +import org.apache.jmeter.threads.ThreadGroup; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.collections.HashTree; import org.springframework.context.i18n.LocaleContextHolder; @@ -72,12 +75,25 @@ public class JMeterService { } } + /** + * 添加调试监听 + * + * @param testId + * @param testPlan + */ private void addDebugListener(String testId, HashTree testPlan) { MsDebugListener resultCollector = new MsDebugListener(); resultCollector.setName(testId); resultCollector.setProperty(TestElement.TEST_CLASS, MsDebugListener.class.getName()); resultCollector.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ViewResultsFullVisualizer")); resultCollector.setEnabled(true); + + // 添加DEBUG标示 + HashTree test = ArrayUtils.isNotEmpty(testPlan.getArray()) ? testPlan.getTree(testPlan.getArray()[0]) : null; + if (test != null && ArrayUtils.isNotEmpty(test.getArray()) && test.getArray()[0] instanceof ThreadGroup) { + ThreadGroup group = (ThreadGroup) test.getArray()[0]; + group.setProperty(BackendListenerConstants.MS_DEBUG.name(), true); + } testPlan.add(testPlan.getArray()[0], resultCollector); } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java b/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java index 42cdba7ab7..f232b475e3 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java @@ -56,7 +56,9 @@ public class KafkaListenerTask implements Runnable { if (testResult != null) { if (testResult.getArbitraryData() != null && testResult.getArbitraryData().containsKey("TEST_END") && (Boolean) testResult.getArbitraryData().get("TEST_END")) { resultDTOS.add(testResult); - } else { + } + // 携带结果 + if (CollectionUtils.isNotEmpty(testResult.getRequestResults())) { String key = RUN_MODE_MAP.get(testResult.getRunMode()); if (assortMap.containsKey(key)) { assortMap.get(key).add(testResult); @@ -68,6 +70,7 @@ public class KafkaListenerTask implements Runnable { } } }); + if (MapUtils.isNotEmpty(assortMap)) { LoggerUtil.info("KAFKA消费执行内容存储开始"); testResultService.batchSaveResults(assortMap); diff --git a/backend/src/main/java/io/metersphere/api/jmeter/GroovyLoadJarService.java b/backend/src/main/java/io/metersphere/api/jmeter/MsGroovyLoadJarService.java similarity index 91% rename from backend/src/main/java/io/metersphere/api/jmeter/GroovyLoadJarService.java rename to backend/src/main/java/io/metersphere/api/jmeter/MsGroovyLoadJarService.java index 2d06f35d1b..7b218ea82a 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/GroovyLoadJarService.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/MsGroovyLoadJarService.java @@ -4,6 +4,7 @@ import groovy.lang.GroovyClassLoader; import io.metersphere.base.domain.JarConfig; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.jmeter.LoadJarService; import io.metersphere.service.JarConfigService; import org.springframework.stereotype.Service; @@ -11,7 +12,7 @@ import java.io.File; import java.util.List; @Service -public class GroovyLoadJarService { +public class MsGroovyLoadJarService implements LoadJarService { /** * groovy 使用的是自己的类加载器, * 这里再执行脚本前,使用 groovy的加载器加载jar包, diff --git a/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java b/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java index 81fd831b7c..eb7eada5b1 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java @@ -51,9 +51,9 @@ public class MsKafkaListener { }}; // 线程池维护线程的最少数量 - private final static int CORE_POOL_SIZE = 50; + private final static int CORE_POOL_SIZE = 20; // 线程池维护线程的最大数量 - private final static int MAX_POOL_SIZE = 50; + private final static int MAX_POOL_SIZE = 20; // 线程池维护线程所允许的空闲时间 private final static int KEEP_ALIVE_TIME = 1; // 线程池所使用的缓冲队列大小