From 4f827ca0d9860debc302d5cfa260ba1819237648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E9=AD=81?= <670569467@qq.com> Date: Thu, 18 Jul 2024 11:15:38 +0800 Subject: [PATCH] Adjust integration tests for common modules in the core module to comply with checkstyle. (#12349) * Fix exception code error.(#10925) * [IT]Adjust integration tests for ability, base, and client modules in the core module to comply with checkstyle. * [IT]Optimize the class naming. * [IT]Adjust integration tests for common modules in the core module to comply with checkstyle. --- ...TCase.java => FileTypeEnumCoreITCase.java} | 13 ++-- ... => NacosAsyncRestTemplateCoreITCase.java} | 60 +++++++++--------- ....java => NacosRestTemplateCoreITCase.java} | 61 ++++++++++--------- ...osRestTemplateInterceptorsCoreITCase.java} | 29 +++++---- ...se.java => WatchFileCenterCoreITCase.java} | 38 ++++++------ 5 files changed, 111 insertions(+), 90 deletions(-) rename test/core-test/src/test/java/com/alibaba/nacos/test/common/{FileTypeEnum_ITCase.java => FileTypeEnumCoreITCase.java} (82%) rename test/core-test/src/test/java/com/alibaba/nacos/test/common/{NacosAsyncRestTemplate_ITCase.java => NacosAsyncRestTemplateCoreITCase.java} (78%) rename test/core-test/src/test/java/com/alibaba/nacos/test/common/{NacosRestTemplate_ITCase.java => NacosRestTemplateCoreITCase.java} (72%) rename test/core-test/src/test/java/com/alibaba/nacos/test/common/{NacosRestTemplate_Interceptors_ITCase.java => NacosRestTemplateInterceptorsCoreITCase.java} (80%) rename test/core-test/src/test/java/com/alibaba/nacos/test/common/{WatchFileCenter_ITCase.java => WatchFileCenterCoreITCase.java} (81%) diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/common/FileTypeEnum_ITCase.java b/test/core-test/src/test/java/com/alibaba/nacos/test/common/FileTypeEnumCoreITCase.java similarity index 82% rename from test/core-test/src/test/java/com/alibaba/nacos/test/common/FileTypeEnum_ITCase.java rename to test/core-test/src/test/java/com/alibaba/nacos/test/common/FileTypeEnumCoreITCase.java index ab88d31cc77..6b4a1160a6e 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/common/FileTypeEnum_ITCase.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/common/FileTypeEnumCoreITCase.java @@ -23,12 +23,17 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; /** + * This class contains integration tests for the FileTypeEnum enumeration. It verifies the functionality of the + * getFileTypeEnumByFileExtensionOrFileType method. The tests ensure that the FileTypeEnum correctly maps file + * extensions and file types to their respective enum values. + * * @author by jiangmin.wu on 2020/12/30 */ -class FileTypeEnum_ITCase { +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") +class FileTypeEnumCoreITCase { @Test - void fileTypeEnum_test1() { + void fileTypeEnumTest1() { for (FileTypeEnum value : FileTypeEnum.values()) { FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(value.name()); assertEquals(fileTypeEnum, value); @@ -36,7 +41,7 @@ void fileTypeEnum_test1() { } @Test - void fileTypeEnum_test2() { + void fileTypeEnumTest2() { for (FileTypeEnum value : FileTypeEnum.values()) { FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(value.getFileType()); assertNotNull(fileTypeEnum); @@ -44,7 +49,7 @@ void fileTypeEnum_test2() { } @Test - void fileTypeEnum_test3() { + void fileTypeEnumTest3() { FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType("t"); assertEquals(FileTypeEnum.TEXT, fileTypeEnum); diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosAsyncRestTemplate_ITCase.java b/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosAsyncRestTemplateCoreITCase.java similarity index 78% rename from test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosAsyncRestTemplate_ITCase.java rename to test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosAsyncRestTemplateCoreITCase.java index 76fce58a1df..f9b6b789e50 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosAsyncRestTemplate_ITCase.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosAsyncRestTemplateCoreITCase.java @@ -48,49 +48,51 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** - * NacosAsyncRestTemplate_ITCase. + * This class provides integration tests for NacosAsyncRestTemplate. These tests cover various HTTP methods such as + * POST, GET, PUT, and DELETE to ensure the correct functioning of asynchronous HTTP requests in the context of Nacos. * * @author mai.jh */ -@SuppressWarnings("all") +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") @TestMethodOrder(MethodName.class) @ExtendWith(SpringExtension.class) @SpringBootTest(classes = Nacos.class, properties = { "server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -class NacosAsyncRestTemplate_ITCase { +class NacosAsyncRestTemplateCoreITCase { private static final HttpClientFactory PROCESSOR_ASYNC_HTTP_CLIENT_FACTORY = new ProcessorHttpClientFactory(); - private final String CONFIG_INSTANCE_PATH = "/nacos/v1/ns"; + private static final String CONFIG_INSTANCE_PATH = "/nacos/v1/ns"; + private final NacosAsyncRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate( + LoggerFactory.getLogger(NacosAsyncRestTemplateCoreITCase.class)); + + @SuppressWarnings("deprecation") @LocalServerPort private int port; - private NacosAsyncRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate( - LoggerFactory.getLogger(NacosAsyncRestTemplate_ITCase.class)); - private NacosAsyncRestTemplate processorRestTemplate = null; - private String IP = null; + private String ip = null; @Autowired private Environment environment; @BeforeEach void init() throws NacosException { - IP = String.format("http://localhost:%d", port); + ip = String.format("http://localhost:%d", port); EnvUtil.setEnvironment((ConfigurableEnvironment) environment); processorRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(PROCESSOR_ASYNC_HTTP_CLIENT_FACTORY); } @Test - void test_url_post_form() throws Exception { - String url = IP + CONFIG_INSTANCE_PATH + "/instance"; + void testUrlPostForm() throws Exception { Map param = new HashMap<>(); param.put("serviceName", "app-test"); param.put("port", "8080"); param.put("ip", "11.11.11.11"); CallbackMap callbackMap = new CallbackMap<>(); + String url = ip + CONFIG_INSTANCE_PATH + "/instance"; nacosRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap); Thread.sleep(2000); HttpRestResult restResult = callbackMap.getRestResult(); @@ -100,14 +102,15 @@ void test_url_post_form() throws Exception { } @Test - void test_url_post_form_by_processor() throws Exception { - String url = IP + CONFIG_INSTANCE_PATH + "/instance"; + void testUrlPostFormByProcessor() throws Exception { Map param = new HashMap<>(); param.put("serviceName", "app-test2"); param.put("port", "8080"); param.put("ip", "11.11.11.11"); CallbackMap callbackMap = new CallbackMap<>(); - processorRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap); + String url = ip + CONFIG_INSTANCE_PATH + "/instance"; + processorRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, + callbackMap); Thread.sleep(2000); HttpRestResult restResult = callbackMap.getRestResult(); System.out.println(restResult.getData()); @@ -116,13 +119,13 @@ void test_url_post_form_by_processor() throws Exception { } @Test - void test_url_put_form() throws Exception { - String url = IP + CONFIG_INSTANCE_PATH + "/instance"; + void testUrlPutForm() throws Exception { Map param = new HashMap<>(); param.put("serviceName", "app-test-change"); param.put("port", "8080"); param.put("ip", "11.11.11.11"); CallbackMap callbackMap = new CallbackMap<>(); + String url = ip + CONFIG_INSTANCE_PATH + "/instance"; nacosRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap); Thread.sleep(2000); HttpRestResult restResult = callbackMap.getRestResult(); @@ -132,13 +135,13 @@ void test_url_put_form() throws Exception { } @Test - void test_url_get() throws Exception { - String url = IP + CONFIG_INSTANCE_PATH + "/instance/list"; + void testUrlGet() throws Exception { + String url = ip + CONFIG_INSTANCE_PATH + "/instance/list"; Query query = Query.newInstance().addParam("serviceName", "app-test"); - CallbackMap callbackMap = new CallbackMap<>(); + CallbackMap> callbackMap = new CallbackMap<>(); nacosRestTemplate.get(url, Header.newInstance(), query, Map.class, callbackMap); Thread.sleep(2000); - HttpRestResult restResult = callbackMap.getRestResult(); + HttpRestResult> restResult = callbackMap.getRestResult(); System.out.println(restResult.getData()); System.out.println(restResult.getHeader()); assertTrue(restResult.ok()); @@ -146,14 +149,14 @@ void test_url_get() throws Exception { } @Test - void test_url_by_map() throws Exception { - String url = IP + CONFIG_INSTANCE_PATH + "/instance/list"; + void testUrlByMap() throws Exception { + String url = ip + CONFIG_INSTANCE_PATH + "/instance/list"; Map param = new HashMap<>(); param.put("serviceName", "app-test"); - CallbackMap callbackMap = new CallbackMap<>(); + CallbackMap> callbackMap = new CallbackMap<>(); nacosRestTemplate.get(url, Header.newInstance(), Query.newInstance().initParams(param), Map.class, callbackMap); Thread.sleep(2000); - HttpRestResult restResult = callbackMap.getRestResult(); + HttpRestResult> restResult = callbackMap.getRestResult(); System.out.println(restResult.getData()); System.out.println(restResult.getHeader()); assertTrue(restResult.ok()); @@ -161,9 +164,10 @@ void test_url_by_map() throws Exception { } @Test - void test_url_delete() throws Exception { - String url = IP + CONFIG_INSTANCE_PATH + "/instance"; - Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080").addParam("serviceName", "app-test"); + void testUrlDelete() throws Exception { + String url = ip + CONFIG_INSTANCE_PATH + "/instance"; + Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080") + .addParam("serviceName", "app-test"); CallbackMap callbackMap = new CallbackMap<>(); nacosRestTemplate.delete(url, Header.newInstance(), query, String.class, callbackMap); Thread.sleep(2000); @@ -173,7 +177,7 @@ void test_url_delete() throws Exception { assertTrue(restResult.ok()); } - private class CallbackMap implements Callback { + private static class CallbackMap implements Callback { private HttpRestResult restResult; diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_ITCase.java b/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplateCoreITCase.java similarity index 72% rename from test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_ITCase.java rename to test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplateCoreITCase.java index 5783a684828..b1035be29a0 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_ITCase.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplateCoreITCase.java @@ -44,36 +44,38 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** - * NacosRestTemplate_ITCase. + * Integration tests for NacosRestTemplate.This class contains integration tests for NacosRestTemplate using various + * HTTP methods. * * @author mai.jh */ +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") @ExtendWith(SpringExtension.class) @SpringBootTest(classes = Nacos.class, properties = { "server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @TestMethodOrder(MethodName.class) -class NacosRestTemplate_ITCase { +class NacosRestTemplateCoreITCase { - private final String INSTANCE_PATH = "/nacos/v1/ns"; + private static final String INSTANCE_PATH = "/nacos/v1/ns"; - private final String CONFIG_PATH = "/nacos/v1/cs"; + private static final String CONFIG_PATH = "/nacos/v1/cs"; + + private final NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate( + LoggerFactory.getLogger(NacosRestTemplateCoreITCase.class)); @LocalServerPort private int port; - private NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate( - LoggerFactory.getLogger(NacosRestTemplate_ITCase.class)); - - private String IP = null; + private String ip = null; @BeforeEach void init() throws NacosException { - IP = String.format("http://localhost:%d", port); + ip = String.format("http://localhost:%d", port); } @Test - void test_url_post_config() throws Exception { - String url = IP + CONFIG_PATH + "/configs"; + void testUrlPostConfig() throws Exception { + String url = ip + CONFIG_PATH + "/configs"; Map param = new HashMap<>(); param.put("dataId", "test-1"); param.put("group", "DEFAULT_GROUP"); @@ -85,9 +87,10 @@ void test_url_post_config() throws Exception { } @Test - void test_url_get_return_restResult() throws Exception { - String url = IP + CONFIG_PATH + "/configs"; - Query query = Query.newInstance().addParam("beta", true).addParam("dataId", "test-1").addParam("group", "DEFAULT_GROUP"); + void testUrlGetReturnRestResult() throws Exception { + String url = ip + CONFIG_PATH + "/configs"; + Query query = Query.newInstance().addParam("beta", true).addParam("dataId", "test-1") + .addParam("group", "DEFAULT_GROUP"); HttpRestResult restResult = nacosRestTemplate.get(url, Header.newInstance(), query, new TypeReference>() { }.getType()); @@ -96,10 +99,9 @@ void test_url_get_return_restResult() throws Exception { System.out.println(restResult.getHeader()); } - @Test - void test_url_post_form() throws Exception { - String url = IP + INSTANCE_PATH + "/instance"; + void testUrlPostForm() throws Exception { + String url = ip + INSTANCE_PATH + "/instance"; Map param = new HashMap<>(); param.put("serviceName", "app-test"); param.put("port", "8080"); @@ -111,8 +113,8 @@ void test_url_post_form() throws Exception { @Test @Disabled("new version can't update instance when service and instance is not exist") - void test_url_put_from() throws Exception { - String url = IP + INSTANCE_PATH + "/instance"; + void testUrlPutFrom() throws Exception { + String url = ip + INSTANCE_PATH + "/instance"; Map param = new HashMap<>(); param.put("serviceName", "app-test-change"); param.put("port", "8080"); @@ -123,30 +125,33 @@ void test_url_put_from() throws Exception { } @Test - void test_url_get() throws Exception { - String url = IP + INSTANCE_PATH + "/instance/list"; + void testUrlGet() throws Exception { + String url = ip + INSTANCE_PATH + "/instance/list"; Query query = Query.newInstance().addParam("serviceName", "app-test"); - HttpRestResult restResult = nacosRestTemplate.get(url, Header.newInstance(), query, Map.class); + HttpRestResult> restResult = nacosRestTemplate.get(url, Header.newInstance(), query, + Map.class); assertTrue(restResult.ok()); assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name")); System.out.println(restResult.getData()); } @Test - void test_url_get_by_map() throws Exception { - String url = IP + INSTANCE_PATH + "/instance/list"; + void testUrlGetByMap() throws Exception { + String url = ip + INSTANCE_PATH + "/instance/list"; Map param = new HashMap<>(); param.put("serviceName", "app-test"); - HttpRestResult restResult = nacosRestTemplate.get(url, Header.newInstance(), Query.newInstance().initParams(param), Map.class); + HttpRestResult> restResult = nacosRestTemplate.get(url, Header.newInstance(), + Query.newInstance().initParams(param), Map.class); assertTrue(restResult.ok()); assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name")); System.out.println(restResult.getData()); } @Test - void test_url_delete() throws Exception { - String url = IP + INSTANCE_PATH + "/instance"; - Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080").addParam("serviceName", "app-test"); + void testUrlDelete() throws Exception { + String url = ip + INSTANCE_PATH + "/instance"; + Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080") + .addParam("serviceName", "app-test"); HttpRestResult restResult = nacosRestTemplate.delete(url, Header.newInstance(), query, String.class); assertTrue(restResult.ok()); System.out.println(restResult); diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_Interceptors_ITCase.java b/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplateInterceptorsCoreITCase.java similarity index 80% rename from test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_Interceptors_ITCase.java rename to test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplateInterceptorsCoreITCase.java index 20ac2ee722d..39eb17a5b22 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_Interceptors_ITCase.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplateInterceptorsCoreITCase.java @@ -39,42 +39,45 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; /** - * NacosRestTemplate_Interceptors_ITCase + * Integration tests for NacosRestTemplateInterceptorsCoreITCase.These tests verify the functionality of HTTP request + * interceptors in NacosRestTemplate. * * @author mai.jh */ +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") @ExtendWith(SpringExtension.class) @SpringBootTest(classes = Nacos.class, properties = { "server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @TestMethodOrder(MethodName.class) -class NacosRestTemplate_Interceptors_ITCase { +class NacosRestTemplateInterceptorsCoreITCase { - private final String CONFIG_PATH = "/nacos/v1/cs"; + private static final String CONFIG_PATH = "/nacos/v1/cs"; + private final NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate( + LoggerFactory.getLogger(NacosRestTemplateInterceptorsCoreITCase.class)); + + @SuppressWarnings("deprecation") @LocalServerPort private int port; - private NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate( - LoggerFactory.getLogger(NacosRestTemplate_Interceptors_ITCase.class)); - - private String IP = null; + private String ip = null; @BeforeEach void init() throws NacosException { - nacosRestTemplate.setInterceptors(Arrays.asList(new TerminationInterceptor())); - IP = String.format("http://localhost:%d", port); + nacosRestTemplate.setInterceptors(Collections.singletonList(new TerminationInterceptor())); + ip = String.format("http://localhost:%d", port); } @Test - void test_url_post_config() throws Exception { - String url = IP + CONFIG_PATH + "/configs"; + void testUrlPostConfig() throws Exception { + String url = ip + CONFIG_PATH + "/configs"; Map param = new HashMap<>(); param.put("dataId", "test-1"); param.put("group", "DEFAULT_GROUP"); @@ -86,7 +89,7 @@ void test_url_post_config() throws Exception { System.out.println(restResult.getHeader()); } - private class TerminationInterceptor implements HttpClientRequestInterceptor { + private static class TerminationInterceptor implements HttpClientRequestInterceptor { @Override public HttpClientResponse intercept() { diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenter_ITCase.java b/test/core-test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenterCoreITCase.java similarity index 81% rename from test/core-test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenter_ITCase.java rename to test/core-test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenterCoreITCase.java index 598084df521..3497158a957 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenter_ITCase.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/common/WatchFileCenterCoreITCase.java @@ -43,35 +43,39 @@ import static org.junit.jupiter.api.Assertions.assertEquals; /** + * Integration tests for file watching and modification handling using WatchFileCenter.These tests verify the + * concurrency and accuracy of file change notifications under high loads. + * * @author liaochuntao */ -class WatchFileCenter_ITCase { +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") +class WatchFileCenterCoreITCase { - static final String path = Paths.get(System.getProperty("user.home"), "/watch_file_change_test").toString(); + private static final String PATH = Paths.get(System.getProperty("user.home"), "/watch_file_change_test").toString(); - static final Executor executor = Executors.newFixedThreadPool(32); + private static final Executor EXECUTOR = Executors.newFixedThreadPool(32); final Object monitor = new Object(); @BeforeAll static void beforeCls() throws Exception { - DiskUtils.deleteDirThenMkdir(path); + DiskUtils.deleteDirThenMkdir(PATH); } @AfterAll static void afterCls() throws Exception { - DiskUtils.deleteDirectory(path); + DiskUtils.deleteDirectory(PATH); } // The last file change must be notified @Test - void test_high_concurrency_modify() throws Exception { + void testHighConcurrencyModify() throws Exception { AtomicInteger count = new AtomicInteger(0); Set set = new ConcurrentHashSet<>(); final String fileName = "test2_file_change"; - final File file = Paths.get(path, fileName).toFile(); + final File file = Paths.get(PATH, fileName).toFile(); func(fileName, file, content -> { set.add(content); @@ -82,14 +86,14 @@ void test_high_concurrency_modify() throws Exception { } @Test - void test_modify_file_much() throws Exception { + void testModifyFileMuch() throws Exception { final String fileName = "modify_file_much"; - final File file = Paths.get(path, fileName).toFile(); + final File file = Paths.get(PATH, fileName).toFile(); CountDownLatch latch = new CountDownLatch(3); AtomicInteger count = new AtomicInteger(0); - WatchFileCenter.registerWatcher(path, new FileWatcher() { + WatchFileCenter.registerWatcher(PATH, new FileWatcher() { @Override public void onChange(FileChangeEvent event) { try { @@ -118,16 +122,16 @@ public boolean interest(String context) { } @Test - void test_multi_file_modify() throws Exception { + void testMultiFileModify() throws Exception { CountDownLatch latch = new CountDownLatch(10); for (int i = 0; i < 10; i++) { AtomicInteger count = new AtomicInteger(0); Set set = new ConcurrentHashSet<>(); final String fileName = "test2_file_change_" + i; - final File file = Paths.get(path, fileName).toFile(); + final File file = Paths.get(PATH, fileName).toFile(); - executor.execute(() -> { + EXECUTOR.execute(() -> { try { func(fileName, file, content -> { set.add(content); @@ -148,10 +152,10 @@ void test_multi_file_modify() throws Exception { private void func(final String fileName, final File file, final Consumer consumer) throws Exception { CountDownLatch latch = new CountDownLatch(100); DiskUtils.touch(file); - WatchFileCenter.registerWatcher(path, new FileWatcher() { + WatchFileCenter.registerWatcher(PATH, new FileWatcher() { @Override public void onChange(FileChangeEvent event) { - final File file = Paths.get(path, fileName).toFile(); + final File file = Paths.get(PATH, fileName).toFile(); final String content = DiskUtils.readFile(file); consumer.accept(content); } @@ -165,10 +169,10 @@ public boolean interest(String context) { final AtomicInteger id = new AtomicInteger(0); final AtomicReference finalContent = new AtomicReference<>(null); for (int i = 0; i < 100; i++) { - executor.execute(() -> { + EXECUTOR.execute(() -> { final String j = fileName + "_" + id.incrementAndGet(); try { - final File file1 = Paths.get(path, fileName).toFile(); + final File file1 = Paths.get(PATH, fileName).toFile(); synchronized (monitor) { finalContent.set(j); DiskUtils.writeFile(file1, j.getBytes(StandardCharsets.UTF_8), false);