|
@@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.boot.test.context.TestConfiguration;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Import;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
@@ -32,8 +34,9 @@ import java.util.Set;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@SpringBootTest
|
|
|
-@Import(ConcurrentTestConfig.class)
|
|
|
+@Import(ConcurrentTest.ConcurrentTestConfig.class)
|
|
|
class ConcurrentTest {
|
|
|
+ public static final int poolSize = 40;
|
|
|
/**
|
|
|
* 测试结果保存文件夹
|
|
|
*/
|
|
@@ -47,6 +50,57 @@ class ConcurrentTest {
|
|
|
@Autowired
|
|
|
private ThreadPoolTaskScheduler threadPoolTaskScheduler;
|
|
|
|
|
|
+ @TestConfiguration
|
|
|
+ static class ConcurrentTestConfig {
|
|
|
+ @Bean
|
|
|
+ public RestTemplate restTemplate() {
|
|
|
+ return new RestTemplate();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
|
|
|
+ ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
|
|
+ scheduler.setPoolSize(poolSize);
|
|
|
+ scheduler.setWaitForTasksToCompleteOnShutdown(true);
|
|
|
+// scheduler.setThreadNamePrefix("");
|
|
|
+// scheduler.setAwaitTerminationSeconds(60);
|
|
|
+// scheduler.setErrorHandler(e -> log.error(">>> {}", e.getMessage(), e));
|
|
|
+ scheduler.initialize();
|
|
|
+ return scheduler;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testQuery() {
|
|
|
+ // 每个请求结果保存的路径
|
|
|
+ String singlePath = TEST_DIR + "query/single/";
|
|
|
+ // 合并结果保存的路径
|
|
|
+ String resultPath = TEST_DIR + "query/";
|
|
|
+ // 创建文件夹
|
|
|
+ try {
|
|
|
+ Files.createDirectories(Paths.get(singlePath));
|
|
|
+ Files.createDirectories(Paths.get(resultPath));
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ resultPath = resultPath + "黑名单查询接口" + poolSize + "个线程1000条数据测试结果.csv";
|
|
|
+ // 接口地址
|
|
|
+ String url = "http://192.168.50.3:12120/sms/blacklist/api/query/";
|
|
|
+// String url = "http://133.96.94.108:12120/sms/blacklist/api/query/";
|
|
|
+ Set<String> phones = readPhones();
|
|
|
+ for (String t : phones) {
|
|
|
+ RequestParams dto = new RequestParams();
|
|
|
+ dto.setPhone(t);
|
|
|
+ dto.setFromSystem("test");
|
|
|
+ threadPoolTaskScheduler.submit(new Task(restTemplate, t, url, dto, singlePath));
|
|
|
+ }
|
|
|
+ // 等待所有任务执行结束
|
|
|
+ while (threadPoolTaskScheduler.getActiveCount() > 0) {
|
|
|
+ }
|
|
|
+ mergeResult(phones, resultPath, singlePath);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void testRemove() {
|
|
|
// 每个请求结果保存的路径
|
|
@@ -61,7 +115,7 @@ class ConcurrentTest {
|
|
|
e.printStackTrace();
|
|
|
return;
|
|
|
}
|
|
|
- resultPath = resultPath + "一键解封接口" + threadPoolTaskScheduler.getPoolSize() + "个线程1000条数据测试结果.csv";
|
|
|
+ resultPath = resultPath + "一键解封接口" + poolSize + "个线程1000条数据测试结果.csv";
|
|
|
// 接口地址
|
|
|
String url = "http://133.96.94.108:12120/sms/blacklist/api/remove/";
|
|
|
Set<String> phones = readPhones();
|
|
@@ -70,7 +124,7 @@ class ConcurrentTest {
|
|
|
dto.setPhone(t);
|
|
|
dto.setFromSystem("test");
|
|
|
dto.setOperator("test");
|
|
|
- threadPoolTaskScheduler.scheduleWithFixedDelay(new Task(restTemplate, t, url, dto, singlePath), 10000);
|
|
|
+ threadPoolTaskScheduler.submit(new Task(restTemplate, t, url, dto, singlePath));
|
|
|
}
|
|
|
// 等待所有任务执行结束
|
|
|
while (threadPoolTaskScheduler.getActiveCount() > 0) {
|