fix(环境参数设置,系统设置): #1007555 #1007479 测试计划定时任务-设置环境参数错误;服务集成中的提示图片无法显示

--bug=1007555 --user=宋天阳
测试计划定时任务-设置环境参数错误
https://www.tapd.cn/55049933/s/1061753;--bug=1007479
--user=宋天阳 服务集成中的提示图片无法显示 https://www.tapd.cn/55049933/s/1061758
This commit is contained in:
song-tianyang 2021-10-29 16:00:14 +08:00 committed by song-tianyang
parent 57ffb143bd
commit dda3915812
5 changed files with 61 additions and 5 deletions

View File

@ -7,6 +7,8 @@ import io.metersphere.api.service.MsResultService;
import io.metersphere.api.service.TestResultService;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.samplers.SampleResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -31,6 +33,8 @@ public class APIBackendListenerHandler {
@Resource
private MsResultService resultService;
Logger testPlanLog = LoggerFactory.getLogger("testPlanExecuteLog");
public void handleTeardownTest(List<SampleResult> queue, String runMode, String testId, String debugReportId) throws Exception {
TestResult testResult = new TestResult();
testResult.setTestId(testId);
@ -42,7 +46,7 @@ public class APIBackendListenerHandler {
// 线程名称: <场景名> <场景Index>-<请求Index>, 例如Scenario 2-1
if (StringUtils.equals(result.getSampleLabel(), RunningParamKeys.RUNNING_DEBUG_SAMPLER_NAME)) {
String evnStr = result.getResponseDataAsString();
apiEnvironmentRunningParamService.parseEvn(evnStr);
ExecutedHandleSingleton.parseEnvironment(evnStr);
} else {
resultService.formatTestResult(testResult, scenarios, result);
}

View File

@ -0,0 +1,27 @@
package io.metersphere.api.jmeter;
import io.metersphere.api.service.ApiEnvironmentRunningParamService;
import io.metersphere.commons.utils.CommonBeanFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 执行结束后的处理(单例类
*
* @author song.tianyang
* @Date 2021/10/29 11:22 上午
*/
public class ExecutedHandleSingleton {
private static volatile ApiEnvironmentRunningParamService apiEnvironmentRunningParamService = CommonBeanFactory.getBean(ApiEnvironmentRunningParamService.class);
static Logger testPlanLog = LoggerFactory.getLogger("testPlanExecuteLog");
private ExecutedHandleSingleton() {
}
public synchronized static void parseEnvironment(String evnStr) {
try {
Thread.sleep(1000);
}catch (Exception e){
}
apiEnvironmentRunningParamService.parseEvn(evnStr);
}
}

View File

@ -3,9 +3,14 @@ package io.metersphere.api.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.exception.MSException;
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -20,8 +25,13 @@ import javax.annotation.Resource;
public class ApiEnvironmentRunningParamService {
@Resource
ApiTestEnvironmentService apiTestEnvironmentService;
@Resource
SqlSessionFactory sqlSessionFactory;
Logger testPlanLog = LoggerFactory.getLogger("testPlanExecuteLog");
public synchronized void addParam(String enviromentId, String key, String value) {
if(StringUtils.isEmpty(key)){
return;
}
@ -86,8 +96,22 @@ public class ApiEnvironmentRunningParamService {
commonConfig.put("variables",variables);
configObj.put("commonConfig",commonConfig);
}
apiTestEnvironmentWithBLOBs.setConfig(configObj.toJSONString());
apiTestEnvironmentService.update(apiTestEnvironmentWithBLOBs);
SqlSession sqlSession = null;
try {
sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
ApiTestEnvironmentMapper batchMapper = sqlSession.getMapper(ApiTestEnvironmentMapper.class);
batchMapper.updateByPrimaryKeyWithBLOBs(apiTestEnvironmentWithBLOBs);
sqlSession.commit();
}catch (Exception e){
sqlSession.rollback();
}finally {
sqlSession.close();
}
testPlanLog.info("update by sty: "+enviromentId + ":[" + key +":"+ value +"]");
}
public void parseEvn(String envStr) {

View File

@ -874,6 +874,7 @@ public class ApiTestCaseService {
Map<String, EnvironmentConfig> envConfig = new HashMap<>(16);
if (environment != null && environment.getConfig() != null) {
EnvironmentConfig environmentConfig = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
environmentConfig.setApiEnvironmentid(environment.getId());
envConfig.put(testCaseWithBLOBs.getProjectId(), environmentConfig);
parameterConfig.setConfig(envConfig);
}

View File

@ -18,7 +18,7 @@
<el-input v-model="form.issuetype" :placeholder="$t('organization.integration.input_azure_issuetype')"/>
<ms-instructions-icon effect="light">
<template>
<img class="jira-image" src="src/assets/azureDevops-type.png"/>
<img class="jira-image" src="@/assets/azureDevops-type.png"/>
</template>
</ms-instructions-icon>
</el-form-item>
@ -26,7 +26,7 @@
<el-input v-model="form.storytype" :placeholder="$t('organization.integration.input_azure_storytype')"/>
<ms-instructions-icon effect="light">
<template>
<img class="jira-image" src="src/assets/azureDevops-type.png"/>
<img class="jira-image" src="@/assets/azureDevops-type.png"/>
</template>
</ms-instructions-icon>
</el-form-item>