feat(Mock): 修复TCPMock无法匹配的问题

修复TCPMock无法匹配的问题
This commit is contained in:
song-tianyang 2021-10-25 15:06:47 +08:00 committed by song-tianyang
parent 59278de022
commit 7e12d281ea
3 changed files with 21 additions and 5 deletions

View File

@ -73,7 +73,7 @@ public class ApiDefinitionExecResultService {
result.getScenarios().forEach(scenarioResult -> {
if (scenarioResult != null && CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) {
scenarioResult.getRequestResults().forEach(item -> {
if(!StringUtils.equalsIgnoreCase(item.getMethod(),"Request") && !StringUtils.startsWithAny(item.getName(),"PRE_PROCESSOR_ENV_","POST_PROCESSOR_ENV_")){
if(!StringUtils.startsWithAny(item.getName(),"PRE_PROCESSOR_ENV_","POST_PROCESSOR_ENV_")){
ApiDefinitionExecResult saveResult = MessageCache.batchTestCases.get(result.getTestId());
if (saveResult == null) {
saveResult = apiDefinitionExecResultMapper.selectByPrimaryKey(result.getTestId());

View File

@ -894,7 +894,7 @@ public class ApiDefinitionService {
if (res != null && CollectionUtils.isNotEmpty(res.getScenarios()) && res.getScenarios().get(0) != null && CollectionUtils.isNotEmpty(res.getScenarios().get(0).getRequestResults())) {
RequestResult result = null;
for (RequestResult itemResult : res.getScenarios().get(0).getRequestResults()) {
if (!StringUtils.equalsIgnoreCase(itemResult.getMethod(), "Request") && !StringUtils.startsWithAny(itemResult.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) {
if (!StringUtils.startsWithAny(itemResult.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) {
result = itemResult;
break;
}

View File

@ -45,10 +45,12 @@ public class TCPServicer {
if(matchdMockExpect != null){
String response = matchdMockExpect.getResponse();
JSONObject responseObj = JSONObject.parseObject(response);
int delayed = 0;
try {
int delayed = responseObj.getInteger("delayed");
Thread.sleep(delayed);
} catch (InterruptedException e) {
if(responseObj.containsKey("delayed")){
delayed = responseObj.getInteger("delayed");
}
} catch (Exception e) {
e.printStackTrace();
}
if(responseObj.containsKey("responseResult")){
@ -56,9 +58,23 @@ public class TCPServicer {
if(respResultObj.containsKey("body")){
returnMsg = MockApiUtils.getResultByResponseResult(respResultObj.getJSONObject("body"),"",null,null);
}
try {
if(respResultObj.containsKey("delayed")){
delayed = respResultObj.getInteger("delayed");
}
} catch (Exception e) {
e.printStackTrace();
}
}else {
returnMsg = responseObj.getString("body");
}
try {
Thread.sleep(delayed);
} catch (Exception e) {
e.printStackTrace();
}
}
return returnMsg;
}