diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 07102e552b..412c6bbb06 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -191,14 +191,16 @@ public class JMeterService { } } - private synchronized void nodeDebug(JmeterRunRequestDTO request) { + private void nodeDebug(JmeterRunRequestDTO request) { try { + LoggerUtil.info("获取调试资源池", request.getReportId()); List resources = GenerateHashTreeUtil.setPoolResource(request.getPoolId()); if (request.getHashTree() != null) { // 过程变量处理 this.fileProcessing(request); request.setHashTree(null); } + LoggerUtil.info("调用资源池开始执行", request.getReportId()); apiPoolDebugService.run(request, resources); } catch (Exception e) { LoggerUtil.error(e); @@ -208,7 +210,7 @@ public class JMeterService { } } - private synchronized void send(JmeterRunRequestDTO request) { + private void send(JmeterRunRequestDTO request) { try { if (redisTemplate.opsForValue().get(SmoothWeighted.EXEC_INDEX + request.getPoolId()) != null) { long index = Long.parseLong(redisTemplate.opsForValue().get(SmoothWeighted.EXEC_INDEX + request.getPoolId()).toString()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java index bbf083bb63..1c9b7ba39c 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java @@ -56,13 +56,16 @@ public class KafkaListenerTask implements Runnable { LoggerUtil.info("KAFKA解析结果任务开始解析结果", String.valueOf(record.key())); ResultDTO dto = this.formatResult(); if (dto == null) { + LoggerUtil.info("未获取到执行结果", String.valueOf(record.key())); return; } - redisTemplateService.delete(JmxFileUtil.getExecuteFileKeyInRedis(dto.getReportId())); if (dto.getArbitraryData() != null && dto.getArbitraryData().containsKey(ExtendedParameter.TEST_END) && (Boolean) dto.getArbitraryData().get(ExtendedParameter.TEST_END)) { + redisTemplateService.delete(JmxFileUtil.getExecuteFileKeyInRedis(dto.getReportId())); resultDTOS.add(dto); + // 全局并发队列 + PoolExecBlockingQueueUtil.offer(dto.getReportId()); LoggerUtil.info("KAFKA消费结果处理状态:" + dto.getArbitraryData().get(ExtendedParameter.TEST_END), String.valueOf(record.key())); } // 携带结果 @@ -71,7 +74,7 @@ public class KafkaListenerTask implements Runnable { if (assortMap.containsKey(key)) { assortMap.get(key).add(dto); } else { - assortMap.put(key, new LinkedList() {{ + assortMap.put(key, new LinkedList<>() {{ this.add(dto); }}); } @@ -88,8 +91,6 @@ public class KafkaListenerTask implements Runnable { testResultService.testEnded(testResult); LoggerUtil.info("执行队列处理:" + testResult.getQueueId(), testResult.getReportId()); apiExecutionQueueService.queueNext(testResult); - // 全局并发队列 - PoolExecBlockingQueueUtil.offer(testResult.getReportId()); // 更新测试计划报告 LoggerUtil.info("Check Processing Test Plan report status:" + testResult.getQueueId() + "," + testResult.getTestId(), testResult.getReportId()); apiExecutionQueueService.checkTestPlanCaseTestEnd(testResult.getTestId(), testResult.getRunMode(), testResult.getTestPlanReportId()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java index 8ec9f8a3dd..6a8b5768ff 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java @@ -33,9 +33,9 @@ public class MsKafkaListener { @Resource private TestResultService testResultService; // 线程池维护线程的最少数量 - private final static int CORE_POOL_SIZE = 5; + private final static int CORE_POOL_SIZE = 10; // 线程池维护线程的最大数量 - private final static int MAX_POOL_SIZE = 5; + private final static int MAX_POOL_SIZE = 10; // 线程池维护线程所允许的空闲时间 private final static int KEEP_ALIVE_TIME = 1; // 线程池所使用的缓冲队列大小 @@ -67,7 +67,6 @@ public class MsKafkaListener { task.setRedisTemplateService(redisTemplateService); threadPool.execute(task); }); - JvmUtil.memoryInfo(); } catch (Exception e) { LoggerUtil.error("KAFKA消费失败:", e); } finally { diff --git a/api-test/backend/src/main/java/io/metersphere/service/RedisTemplateService.java b/api-test/backend/src/main/java/io/metersphere/service/RedisTemplateService.java index 2be3f4817a..f22c2d8226 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/RedisTemplateService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/RedisTemplateService.java @@ -1,6 +1,6 @@ package io.metersphere.service; -import io.metersphere.commons.utils.LogUtil; +import io.metersphere.utils.LoggerUtil; import jakarta.annotation.Resource; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -17,7 +17,7 @@ public class RedisTemplateService { try { return redisTemplate.opsForValue().setIfAbsent(key, value); } catch (Exception e) { - LogUtil.error(e); + LoggerUtil.error(key, e); return true; } } @@ -26,7 +26,7 @@ public class RedisTemplateService { try { return redisTemplate.expire(key, TIME_OUT, TimeUnit.MINUTES); } catch (Exception e) { - LogUtil.error(e); + LoggerUtil.error(key, e); return false; } } @@ -35,7 +35,7 @@ public class RedisTemplateService { try { return redisTemplate.opsForValue().get(key); } catch (Exception e) { - LogUtil.error(e); + LoggerUtil.error(key, e); } return null; } @@ -44,7 +44,7 @@ public class RedisTemplateService { try { return redisTemplate.delete(key); } catch (Exception e) { - LogUtil.error(e); + LoggerUtil.error(key, e); return false; } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java index f3f3bde571..d96188c8e6 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java @@ -256,27 +256,27 @@ public class ApiScenarioReportService { return report; } - public ApiScenarioReportWithBLOBs editReport(String reportType, String reportId, String status, String runMode) { - ApiScenarioReportWithBLOBs report = apiScenarioReportMapper.selectByPrimaryKey(reportId); - if (report == null) { - report = new ApiScenarioReportWithBLOBs(); - report.setId(reportId); + public ApiScenarioReport editReport(String reportType, String reportId, String status, String runMode) { + ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId); + if (report != null) { + if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString()) + || StringUtils.equals(report.getStatus(), ApiReportStatus.STOPPED.name())) { + return report; + } + ApiScenarioReportWithBLOBs bloBs = new ApiScenarioReportWithBLOBs(); + if (StringUtils.equals(runMode, CommonConstants.CASE)) { + bloBs.setTriggerMode(TriggerMode.MANUAL.name()); + } + bloBs.setId(reportId); + bloBs.setStatus(status); + bloBs.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis())); + bloBs.setEndTime(System.currentTimeMillis()); + bloBs.setUpdateTime(System.currentTimeMillis()); + if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals(CommonConstants.CASE)) { + bloBs.setTriggerMode(TriggerMode.MANUAL.name()); + } + apiScenarioReportMapper.updateByPrimaryKeySelective(bloBs); } - if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString()) - || StringUtils.equals(report.getStatus(), ApiReportStatus.STOPPED.name())) { - return report; - } - if (StringUtils.equals(runMode, CommonConstants.CASE)) { - report.setTriggerMode(TriggerMode.MANUAL.name()); - } - report.setStatus(status); - report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis())); - report.setEndTime(System.currentTimeMillis()); - report.setUpdateTime(System.currentTimeMillis()); - if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals(CommonConstants.CASE)) { - report.setTriggerMode(TriggerMode.MANUAL.name()); - } - apiScenarioReportMapper.updateByPrimaryKeySelective(report); return report; } @@ -340,7 +340,7 @@ public class ApiScenarioReportService { List testPlanReportIdList = new ArrayList<>(); ResultVO resultVO = ReportStatusUtil.computedProcess(dto); - ApiScenarioReportWithBLOBs report = editReport(dto.getReportType(), dto.getReportId(), resultVO.getStatus(), dto.getRunMode()); + ApiScenarioReport report = editReport(dto.getReportType(), dto.getReportId(), resultVO.getStatus(), dto.getRunMode()); if (report != null) { if (StringUtils.isNotEmpty(dto.getTestPlanReportId()) && !testPlanReportIdList.contains(dto.getTestPlanReportId())) { testPlanReportIdList.add(dto.getTestPlanReportId()); diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportStructureService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportStructureService.java index 2e5d6ef7c0..accdfcce2a 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportStructureService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportStructureService.java @@ -125,14 +125,18 @@ public class ApiScenarioReportStructureService { public void update(String reportId, String console, boolean isActuator) { ApiScenarioReportStructureExample example = new ApiScenarioReportStructureExample(); example.createCriteria().andReportIdEqualTo(reportId); - List structures = mapper.selectByExampleWithBLOBs(example); - for (ApiScenarioReportStructureWithBLOBs structure : structures) { + List structures = mapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(structures)) { + ApiScenarioReportStructureWithBLOBs bloBs = new ApiScenarioReportStructureWithBLOBs(); + bloBs.setId(structures.get(0).getId()); if (isActuator) { - structure.setConsole(StringUtils.join(structure.getConsole(), StringUtils.LF, console)); + // 集合报告日志合并处理 + bloBs = mapper.selectByPrimaryKey(structures.get(0).getId()); + bloBs.setConsole(StringUtils.join(bloBs.getConsole(), StringUtils.LF, console)); } else { - structure.setConsole(console); + bloBs.setConsole(console); } - mapper.updateByPrimaryKeyWithBLOBs(structure); + mapper.updateByPrimaryKeySelective(bloBs); } }