feat(资源池): 增加单个任务并发数

This commit is contained in:
guoyuqi 2024-09-23 18:42:02 +08:00 committed by Craftsman
parent f5706f2a44
commit 06be04d2f7
5 changed files with 30 additions and 13 deletions

View File

@ -25,10 +25,10 @@ public class RoundRobinServiceTests {
@Order(1) @Order(1)
public void testInit() throws Exception { public void testInit() throws Exception {
List<TestResourceNodeDTO> nodes = new LinkedList<>(); List<TestResourceNodeDTO> nodes = new LinkedList<>();
nodes.add(new TestResourceNodeDTO("172.0.0.1", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.1", "8080", 10, 3));
nodes.add(new TestResourceNodeDTO("172.0.0.2", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.2", "8080", 10, 3));
nodes.add(new TestResourceNodeDTO("172.0.0.3", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.3", "8080", 10, 3));
nodes.add(new TestResourceNodeDTO("172.0.0.4", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.4", "8080", 10, 3));
roundRobinService.initializeNodes("test", nodes); roundRobinService.initializeNodes("test", nodes);
} }
@ -49,14 +49,14 @@ public class RoundRobinServiceTests {
@Order(3) @Order(3)
public void testInitAfter() throws Exception { public void testInitAfter() throws Exception {
List<TestResourceNodeDTO> nodes = new LinkedList<>(); List<TestResourceNodeDTO> nodes = new LinkedList<>();
nodes.add(new TestResourceNodeDTO("172.0.0.1", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.1", "8080", 10, 3));
nodes.add(new TestResourceNodeDTO("172.0.0.2", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.2", "8080", 10, 3));
nodes.add(new TestResourceNodeDTO("172.0.0.3", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.3", "8080", 10, 3));
roundRobinService.initializeNodes("test", nodes); roundRobinService.initializeNodes("test", nodes);
nodes.add(new TestResourceNodeDTO("172.0.0.3", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.3", "8080", 10, 3));
nodes.add(new TestResourceNodeDTO("172.0.0.7", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.7", "8080", 10, 3));
nodes.add(new TestResourceNodeDTO("172.0.0.6", "8080", 10)); nodes.add(new TestResourceNodeDTO("172.0.0.6", "8080", 10, 3));
roundRobinService.initializeNodes("test", nodes); roundRobinService.initializeNodes("test", nodes);
} }

View File

@ -30,4 +30,10 @@ public class TestResourceNodeDTO {
@Schema(description = "接口测试,性能测试最大并发数") @Schema(description = "接口测试,性能测试最大并发数")
private Integer concurrentNumber; private Integer concurrentNumber;
/**
* 接口测试 性能测试 最大并发数
*/
@Schema(description = "接口测试,性能测试单个任务最大并发数有可能为null为null则置为3")
private Integer singleTaskConcurrentNumber = 3;
} }

View File

@ -45,6 +45,9 @@ public class NodeResourcePoolService {
if (testResourceNodeDTO.getConcurrentNumber() > 10) { if (testResourceNodeDTO.getConcurrentNumber() > 10) {
testResourceNodeDTO.setConcurrentNumber(10); testResourceNodeDTO.setConcurrentNumber(10);
} }
if (testResourceNodeDTO.getSingleTaskConcurrentNumber() > 3) {
testResourceNodeDTO.setSingleTaskConcurrentNumber(3);
}
} }
isValid = validateNode(testResourceNodeDTO); isValid = validateNode(testResourceNodeDTO);

View File

@ -204,6 +204,12 @@ public class TestResourcePoolService {
TestResourceDTO testResourceDTO = JSON.parseObject(testResourceDTOStr, TestResourceDTO.class); TestResourceDTO testResourceDTO = JSON.parseObject(testResourceDTOStr, TestResourceDTO.class);
if (CollectionUtils.isEmpty(testResourceDTO.getNodesList())) { if (CollectionUtils.isEmpty(testResourceDTO.getNodesList())) {
testResourceDTO.setNodesList(new ArrayList<>()); testResourceDTO.setNodesList(new ArrayList<>());
} else {
for (TestResourceNodeDTO testResourceNodeDTO : testResourceDTO.getNodesList()) {
if (testResourceNodeDTO.getSingleTaskConcurrentNumber() == null) {
testResourceNodeDTO.setSingleTaskConcurrentNumber(3);
}
}
} }
TestResourceReturnDTO testResourceReturnDTO = new TestResourceReturnDTO(); TestResourceReturnDTO testResourceReturnDTO = new TestResourceReturnDTO();
BeanUtils.copyBean(testResourceReturnDTO, testResourceDTO); BeanUtils.copyBean(testResourceReturnDTO, testResourceDTO);

View File

@ -83,7 +83,8 @@ class TestResourcePoolControllerTests extends BaseTest {
" \"ip\":\"192.168.20.17\",\n" + " \"ip\":\"192.168.20.17\",\n" +
" \"port\": \"1194\",\n" + " \"port\": \"1194\",\n" +
" \"monitor\": \"9100\",\n" + " \"monitor\": \"9100\",\n" +
" \"concurrentNumber\": 100\n" + " \"concurrentNumber\": \"100\",\n" +
" \"singleTaskConcurrentNumber\": 3\n" +
" }],\n" + " }],\n" +
"\"ip\":\"172.2.130.1\",\n" + "\"ip\":\"172.2.130.1\",\n" +
"\"token\":\"dsdfssdsvgsd\",\n" + "\"token\":\"dsdfssdsvgsd\",\n" +
@ -104,7 +105,8 @@ class TestResourcePoolControllerTests extends BaseTest {
" \"ip\": \"172.16.200.8\",\n" + " \"ip\": \"172.16.200.8\",\n" +
" \"port\": \"8082\",\n" + " \"port\": \"8082\",\n" +
" \"monitor\": \"9100\",\n" + " \"monitor\": \"9100\",\n" +
" \"concurrentNumber\": 100\n" + " \"concurrentNumber\": \"100\",\n" +
" \"singleTaskConcurrentNumber\": 3\n" +
" }\n" + " }\n" +
" ],\n" + " ],\n" +
" \"orgIds\": [\"sys_default_organization_2\",\"sys_default_organization_3\"],\n" + " \"orgIds\": [\"sys_default_organization_2\",\"sys_default_organization_3\"],\n" +
@ -335,7 +337,7 @@ class TestResourcePoolControllerTests extends BaseTest {
Assertions.assertTrue((CollectionUtils.isNotEmpty(testResourcePoolReturnDTO.getTestResourceReturnDTO().getOrgIdNameMap()))); Assertions.assertTrue((CollectionUtils.isNotEmpty(testResourcePoolReturnDTO.getTestResourceReturnDTO().getOrgIdNameMap())));
Assertions.assertTrue(testResourcePoolReturnDTO.getTestResourceReturnDTO().getNodesList().size() > 0); Assertions.assertFalse(testResourcePoolReturnDTO.getTestResourceReturnDTO().getNodesList().isEmpty());
for (TestResourceNodeDTO testResourceNodeDTO : testResourcePoolReturnDTO.getTestResourceReturnDTO().getNodesList()) { for (TestResourceNodeDTO testResourceNodeDTO : testResourcePoolReturnDTO.getTestResourceReturnDTO().getNodesList()) {
Assertions.assertNotNull(testResourceNodeDTO.getIp()); Assertions.assertNotNull(testResourceNodeDTO.getIp());
Assertions.assertNotNull(testResourceNodeDTO.getPort()); Assertions.assertNotNull(testResourceNodeDTO.getPort());