From 3e4b4488f03fe18727637a7311def5267683b784 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Mon, 22 Aug 2022 19:26:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=81=9C=E6=AD=A2=E6=80=A7=E8=83=BD=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=97=B6=E6=8A=A5NULL=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016101 --user=刘瑞斌 [性能测试] github#17179-执行过程中,无法停止执行 https://www.tapd.cn/55049933/s/1230237 Closes #17179 --- .../engine/docker/DockerTestEngine.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java b/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java index 8ae1a52b89..ba5ee827ff 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java +++ b/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java @@ -20,6 +20,7 @@ import io.metersphere.performance.engine.AbstractEngine; import io.metersphere.performance.engine.request.StartTestRequest; import io.metersphere.service.SystemParameterService; import org.apache.commons.lang3.StringUtils; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import java.util.HashMap; @@ -28,8 +29,16 @@ import java.util.UUID; public class DockerTestEngine extends AbstractEngine { private static final String BASE_URL = "http://%s:%d"; - private RestTemplate restTemplate; - private RestTemplate restTemplateWithTimeOut; + private static final RestTemplate restTemplate = new RestTemplate(); + private static final RestTemplate restTemplateWithTimeOut = new RestTemplate(); + + static { + HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(); + httpRequestFactory.setConnectionRequestTimeout(2000); + httpRequestFactory.setConnectTimeout(2000); + httpRequestFactory.setReadTimeout(10000); + restTemplateWithTimeOut.setRequestFactory(httpRequestFactory); + } public DockerTestEngine(LoadTestReportWithBLOBs loadTestReport) { this.init(loadTestReport); @@ -38,8 +47,6 @@ public class DockerTestEngine extends AbstractEngine { @Override protected void init(LoadTestReportWithBLOBs loadTestReport) { super.init(loadTestReport); - this.restTemplate = (RestTemplate) CommonBeanFactory.getBean("restTemplate"); - this.restTemplateWithTimeOut = (RestTemplate) CommonBeanFactory.getBean("restTemplateWithTimeOut"); } @Override