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.
This commit is contained in:
parent
c717538bd7
commit
4f827ca0d9
@ -23,12 +23,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
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
|
* @author by jiangmin.wu on 2020/12/30
|
||||||
*/
|
*/
|
||||||
class FileTypeEnum_ITCase {
|
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
|
||||||
|
class FileTypeEnumCoreITCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fileTypeEnum_test1() {
|
void fileTypeEnumTest1() {
|
||||||
for (FileTypeEnum value : FileTypeEnum.values()) {
|
for (FileTypeEnum value : FileTypeEnum.values()) {
|
||||||
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(value.name());
|
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(value.name());
|
||||||
assertEquals(fileTypeEnum, value);
|
assertEquals(fileTypeEnum, value);
|
||||||
@ -36,7 +41,7 @@ class FileTypeEnum_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fileTypeEnum_test2() {
|
void fileTypeEnumTest2() {
|
||||||
for (FileTypeEnum value : FileTypeEnum.values()) {
|
for (FileTypeEnum value : FileTypeEnum.values()) {
|
||||||
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(value.getFileType());
|
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(value.getFileType());
|
||||||
assertNotNull(fileTypeEnum);
|
assertNotNull(fileTypeEnum);
|
||||||
@ -44,7 +49,7 @@ class FileTypeEnum_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fileTypeEnum_test3() {
|
void fileTypeEnumTest3() {
|
||||||
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType("t");
|
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType("t");
|
||||||
assertEquals(FileTypeEnum.TEXT, fileTypeEnum);
|
assertEquals(FileTypeEnum.TEXT, fileTypeEnum);
|
||||||
|
|
@ -48,49 +48,51 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
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
|
* @author mai.jh
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
|
||||||
@TestMethodOrder(MethodName.class)
|
@TestMethodOrder(MethodName.class)
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@SpringBootTest(classes = Nacos.class, properties = {
|
@SpringBootTest(classes = Nacos.class, properties = {
|
||||||
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
"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 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
|
@LocalServerPort
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
private NacosAsyncRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(
|
|
||||||
LoggerFactory.getLogger(NacosAsyncRestTemplate_ITCase.class));
|
|
||||||
|
|
||||||
private NacosAsyncRestTemplate processorRestTemplate = null;
|
private NacosAsyncRestTemplate processorRestTemplate = null;
|
||||||
|
|
||||||
private String IP = null;
|
private String ip = null;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init() throws NacosException {
|
void init() throws NacosException {
|
||||||
IP = String.format("http://localhost:%d", port);
|
ip = String.format("http://localhost:%d", port);
|
||||||
EnvUtil.setEnvironment((ConfigurableEnvironment) environment);
|
EnvUtil.setEnvironment((ConfigurableEnvironment) environment);
|
||||||
processorRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(PROCESSOR_ASYNC_HTTP_CLIENT_FACTORY);
|
processorRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(PROCESSOR_ASYNC_HTTP_CLIENT_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_post_form() throws Exception {
|
void testUrlPostForm() throws Exception {
|
||||||
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
|
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("serviceName", "app-test");
|
param.put("serviceName", "app-test");
|
||||||
param.put("port", "8080");
|
param.put("port", "8080");
|
||||||
param.put("ip", "11.11.11.11");
|
param.put("ip", "11.11.11.11");
|
||||||
CallbackMap<String> callbackMap = new CallbackMap<>();
|
CallbackMap<String> callbackMap = new CallbackMap<>();
|
||||||
|
String url = ip + CONFIG_INSTANCE_PATH + "/instance";
|
||||||
nacosRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap);
|
nacosRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap);
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
HttpRestResult<String> restResult = callbackMap.getRestResult();
|
HttpRestResult<String> restResult = callbackMap.getRestResult();
|
||||||
@ -100,14 +102,15 @@ class NacosAsyncRestTemplate_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_post_form_by_processor() throws Exception {
|
void testUrlPostFormByProcessor() throws Exception {
|
||||||
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
|
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("serviceName", "app-test2");
|
param.put("serviceName", "app-test2");
|
||||||
param.put("port", "8080");
|
param.put("port", "8080");
|
||||||
param.put("ip", "11.11.11.11");
|
param.put("ip", "11.11.11.11");
|
||||||
CallbackMap<String> callbackMap = new CallbackMap<>();
|
CallbackMap<String> 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);
|
Thread.sleep(2000);
|
||||||
HttpRestResult<String> restResult = callbackMap.getRestResult();
|
HttpRestResult<String> restResult = callbackMap.getRestResult();
|
||||||
System.out.println(restResult.getData());
|
System.out.println(restResult.getData());
|
||||||
@ -116,13 +119,13 @@ class NacosAsyncRestTemplate_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_put_form() throws Exception {
|
void testUrlPutForm() throws Exception {
|
||||||
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
|
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("serviceName", "app-test-change");
|
param.put("serviceName", "app-test-change");
|
||||||
param.put("port", "8080");
|
param.put("port", "8080");
|
||||||
param.put("ip", "11.11.11.11");
|
param.put("ip", "11.11.11.11");
|
||||||
CallbackMap<String> callbackMap = new CallbackMap<>();
|
CallbackMap<String> callbackMap = new CallbackMap<>();
|
||||||
|
String url = ip + CONFIG_INSTANCE_PATH + "/instance";
|
||||||
nacosRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap);
|
nacosRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap);
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
HttpRestResult<String> restResult = callbackMap.getRestResult();
|
HttpRestResult<String> restResult = callbackMap.getRestResult();
|
||||||
@ -132,13 +135,13 @@ class NacosAsyncRestTemplate_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_get() throws Exception {
|
void testUrlGet() throws Exception {
|
||||||
String url = IP + CONFIG_INSTANCE_PATH + "/instance/list";
|
String url = ip + CONFIG_INSTANCE_PATH + "/instance/list";
|
||||||
Query query = Query.newInstance().addParam("serviceName", "app-test");
|
Query query = Query.newInstance().addParam("serviceName", "app-test");
|
||||||
CallbackMap<Map> callbackMap = new CallbackMap<>();
|
CallbackMap<Map<String, String>> callbackMap = new CallbackMap<>();
|
||||||
nacosRestTemplate.get(url, Header.newInstance(), query, Map.class, callbackMap);
|
nacosRestTemplate.get(url, Header.newInstance(), query, Map.class, callbackMap);
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
HttpRestResult<Map> restResult = callbackMap.getRestResult();
|
HttpRestResult<Map<String, String>> restResult = callbackMap.getRestResult();
|
||||||
System.out.println(restResult.getData());
|
System.out.println(restResult.getData());
|
||||||
System.out.println(restResult.getHeader());
|
System.out.println(restResult.getHeader());
|
||||||
assertTrue(restResult.ok());
|
assertTrue(restResult.ok());
|
||||||
@ -146,14 +149,14 @@ class NacosAsyncRestTemplate_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_by_map() throws Exception {
|
void testUrlByMap() throws Exception {
|
||||||
String url = IP + CONFIG_INSTANCE_PATH + "/instance/list";
|
String url = ip + CONFIG_INSTANCE_PATH + "/instance/list";
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("serviceName", "app-test");
|
param.put("serviceName", "app-test");
|
||||||
CallbackMap<Map> callbackMap = new CallbackMap<>();
|
CallbackMap<Map<String, String>> callbackMap = new CallbackMap<>();
|
||||||
nacosRestTemplate.get(url, Header.newInstance(), Query.newInstance().initParams(param), Map.class, callbackMap);
|
nacosRestTemplate.get(url, Header.newInstance(), Query.newInstance().initParams(param), Map.class, callbackMap);
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
HttpRestResult<Map> restResult = callbackMap.getRestResult();
|
HttpRestResult<Map<String, String>> restResult = callbackMap.getRestResult();
|
||||||
System.out.println(restResult.getData());
|
System.out.println(restResult.getData());
|
||||||
System.out.println(restResult.getHeader());
|
System.out.println(restResult.getHeader());
|
||||||
assertTrue(restResult.ok());
|
assertTrue(restResult.ok());
|
||||||
@ -161,9 +164,10 @@ class NacosAsyncRestTemplate_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_delete() throws Exception {
|
void testUrlDelete() throws Exception {
|
||||||
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
|
String url = ip + CONFIG_INSTANCE_PATH + "/instance";
|
||||||
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080").addParam("serviceName", "app-test");
|
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080")
|
||||||
|
.addParam("serviceName", "app-test");
|
||||||
CallbackMap<String> callbackMap = new CallbackMap<>();
|
CallbackMap<String> callbackMap = new CallbackMap<>();
|
||||||
nacosRestTemplate.delete(url, Header.newInstance(), query, String.class, callbackMap);
|
nacosRestTemplate.delete(url, Header.newInstance(), query, String.class, callbackMap);
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
@ -173,7 +177,7 @@ class NacosAsyncRestTemplate_ITCase {
|
|||||||
assertTrue(restResult.ok());
|
assertTrue(restResult.ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CallbackMap<T> implements Callback<T> {
|
private static class CallbackMap<T> implements Callback<T> {
|
||||||
|
|
||||||
private HttpRestResult<T> restResult;
|
private HttpRestResult<T> restResult;
|
||||||
|
|
@ -44,36 +44,38 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
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
|
* @author mai.jh
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@SpringBootTest(classes = Nacos.class, properties = {
|
@SpringBootTest(classes = Nacos.class, properties = {
|
||||||
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
@TestMethodOrder(MethodName.class)
|
@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
|
@LocalServerPort
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
private NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate(
|
private String ip = null;
|
||||||
LoggerFactory.getLogger(NacosRestTemplate_ITCase.class));
|
|
||||||
|
|
||||||
private String IP = null;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init() throws NacosException {
|
void init() throws NacosException {
|
||||||
IP = String.format("http://localhost:%d", port);
|
ip = String.format("http://localhost:%d", port);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_post_config() throws Exception {
|
void testUrlPostConfig() throws Exception {
|
||||||
String url = IP + CONFIG_PATH + "/configs";
|
String url = ip + CONFIG_PATH + "/configs";
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("dataId", "test-1");
|
param.put("dataId", "test-1");
|
||||||
param.put("group", "DEFAULT_GROUP");
|
param.put("group", "DEFAULT_GROUP");
|
||||||
@ -85,9 +87,10 @@ class NacosRestTemplate_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_get_return_restResult() throws Exception {
|
void testUrlGetReturnRestResult() throws Exception {
|
||||||
String url = IP + CONFIG_PATH + "/configs";
|
String url = ip + CONFIG_PATH + "/configs";
|
||||||
Query query = Query.newInstance().addParam("beta", true).addParam("dataId", "test-1").addParam("group", "DEFAULT_GROUP");
|
Query query = Query.newInstance().addParam("beta", true).addParam("dataId", "test-1")
|
||||||
|
.addParam("group", "DEFAULT_GROUP");
|
||||||
HttpRestResult<ConfigInfo4Beta> restResult = nacosRestTemplate.get(url, Header.newInstance(), query,
|
HttpRestResult<ConfigInfo4Beta> restResult = nacosRestTemplate.get(url, Header.newInstance(), query,
|
||||||
new TypeReference<RestResult<ConfigInfo4Beta>>() {
|
new TypeReference<RestResult<ConfigInfo4Beta>>() {
|
||||||
}.getType());
|
}.getType());
|
||||||
@ -96,10 +99,9 @@ class NacosRestTemplate_ITCase {
|
|||||||
System.out.println(restResult.getHeader());
|
System.out.println(restResult.getHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_post_form() throws Exception {
|
void testUrlPostForm() throws Exception {
|
||||||
String url = IP + INSTANCE_PATH + "/instance";
|
String url = ip + INSTANCE_PATH + "/instance";
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("serviceName", "app-test");
|
param.put("serviceName", "app-test");
|
||||||
param.put("port", "8080");
|
param.put("port", "8080");
|
||||||
@ -111,8 +113,8 @@ class NacosRestTemplate_ITCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled("new version can't update instance when service and instance is not exist")
|
@Disabled("new version can't update instance when service and instance is not exist")
|
||||||
void test_url_put_from() throws Exception {
|
void testUrlPutFrom() throws Exception {
|
||||||
String url = IP + INSTANCE_PATH + "/instance";
|
String url = ip + INSTANCE_PATH + "/instance";
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("serviceName", "app-test-change");
|
param.put("serviceName", "app-test-change");
|
||||||
param.put("port", "8080");
|
param.put("port", "8080");
|
||||||
@ -123,30 +125,33 @@ class NacosRestTemplate_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_get() throws Exception {
|
void testUrlGet() throws Exception {
|
||||||
String url = IP + INSTANCE_PATH + "/instance/list";
|
String url = ip + INSTANCE_PATH + "/instance/list";
|
||||||
Query query = Query.newInstance().addParam("serviceName", "app-test");
|
Query query = Query.newInstance().addParam("serviceName", "app-test");
|
||||||
HttpRestResult<Map> restResult = nacosRestTemplate.get(url, Header.newInstance(), query, Map.class);
|
HttpRestResult<Map<String, String>> restResult = nacosRestTemplate.get(url, Header.newInstance(), query,
|
||||||
|
Map.class);
|
||||||
assertTrue(restResult.ok());
|
assertTrue(restResult.ok());
|
||||||
assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name"));
|
assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name"));
|
||||||
System.out.println(restResult.getData());
|
System.out.println(restResult.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_get_by_map() throws Exception {
|
void testUrlGetByMap() throws Exception {
|
||||||
String url = IP + INSTANCE_PATH + "/instance/list";
|
String url = ip + INSTANCE_PATH + "/instance/list";
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("serviceName", "app-test");
|
param.put("serviceName", "app-test");
|
||||||
HttpRestResult<Map> restResult = nacosRestTemplate.get(url, Header.newInstance(), Query.newInstance().initParams(param), Map.class);
|
HttpRestResult<Map<String, String>> restResult = nacosRestTemplate.get(url, Header.newInstance(),
|
||||||
|
Query.newInstance().initParams(param), Map.class);
|
||||||
assertTrue(restResult.ok());
|
assertTrue(restResult.ok());
|
||||||
assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name"));
|
assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name"));
|
||||||
System.out.println(restResult.getData());
|
System.out.println(restResult.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_delete() throws Exception {
|
void testUrlDelete() throws Exception {
|
||||||
String url = IP + INSTANCE_PATH + "/instance";
|
String url = ip + INSTANCE_PATH + "/instance";
|
||||||
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080").addParam("serviceName", "app-test");
|
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080")
|
||||||
|
.addParam("serviceName", "app-test");
|
||||||
HttpRestResult<String> restResult = nacosRestTemplate.delete(url, Header.newInstance(), query, String.class);
|
HttpRestResult<String> restResult = nacosRestTemplate.delete(url, Header.newInstance(), query, String.class);
|
||||||
assertTrue(restResult.ok());
|
assertTrue(restResult.ok());
|
||||||
System.out.println(restResult);
|
System.out.println(restResult);
|
@ -39,42 +39,45 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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
|
* @author mai.jh
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@SpringBootTest(classes = Nacos.class, properties = {
|
@SpringBootTest(classes = Nacos.class, properties = {
|
||||||
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
@TestMethodOrder(MethodName.class)
|
@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
|
@LocalServerPort
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
private NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate(
|
private String ip = null;
|
||||||
LoggerFactory.getLogger(NacosRestTemplate_Interceptors_ITCase.class));
|
|
||||||
|
|
||||||
private String IP = null;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init() throws NacosException {
|
void init() throws NacosException {
|
||||||
nacosRestTemplate.setInterceptors(Arrays.asList(new TerminationInterceptor()));
|
nacosRestTemplate.setInterceptors(Collections.singletonList(new TerminationInterceptor()));
|
||||||
IP = String.format("http://localhost:%d", port);
|
ip = String.format("http://localhost:%d", port);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_url_post_config() throws Exception {
|
void testUrlPostConfig() throws Exception {
|
||||||
String url = IP + CONFIG_PATH + "/configs";
|
String url = ip + CONFIG_PATH + "/configs";
|
||||||
Map<String, String> param = new HashMap<>();
|
Map<String, String> param = new HashMap<>();
|
||||||
param.put("dataId", "test-1");
|
param.put("dataId", "test-1");
|
||||||
param.put("group", "DEFAULT_GROUP");
|
param.put("group", "DEFAULT_GROUP");
|
||||||
@ -86,7 +89,7 @@ class NacosRestTemplate_Interceptors_ITCase {
|
|||||||
System.out.println(restResult.getHeader());
|
System.out.println(restResult.getHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TerminationInterceptor implements HttpClientRequestInterceptor {
|
private static class TerminationInterceptor implements HttpClientRequestInterceptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpClientResponse intercept() {
|
public HttpClientResponse intercept() {
|
@ -43,35 +43,39 @@ import java.util.function.Consumer;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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 <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
||||||
*/
|
*/
|
||||||
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();
|
final Object monitor = new Object();
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void beforeCls() throws Exception {
|
static void beforeCls() throws Exception {
|
||||||
DiskUtils.deleteDirThenMkdir(path);
|
DiskUtils.deleteDirThenMkdir(PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
static void afterCls() throws Exception {
|
static void afterCls() throws Exception {
|
||||||
DiskUtils.deleteDirectory(path);
|
DiskUtils.deleteDirectory(PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The last file change must be notified
|
// The last file change must be notified
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_high_concurrency_modify() throws Exception {
|
void testHighConcurrencyModify() throws Exception {
|
||||||
AtomicInteger count = new AtomicInteger(0);
|
AtomicInteger count = new AtomicInteger(0);
|
||||||
Set<String> set = new ConcurrentHashSet<>();
|
Set<String> set = new ConcurrentHashSet<>();
|
||||||
|
|
||||||
final String fileName = "test2_file_change";
|
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 -> {
|
func(fileName, file, content -> {
|
||||||
set.add(content);
|
set.add(content);
|
||||||
@ -82,14 +86,14 @@ class WatchFileCenter_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_modify_file_much() throws Exception {
|
void testModifyFileMuch() throws Exception {
|
||||||
final String fileName = "modify_file_much";
|
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);
|
CountDownLatch latch = new CountDownLatch(3);
|
||||||
AtomicInteger count = new AtomicInteger(0);
|
AtomicInteger count = new AtomicInteger(0);
|
||||||
|
|
||||||
WatchFileCenter.registerWatcher(path, new FileWatcher() {
|
WatchFileCenter.registerWatcher(PATH, new FileWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(FileChangeEvent event) {
|
public void onChange(FileChangeEvent event) {
|
||||||
try {
|
try {
|
||||||
@ -118,16 +122,16 @@ class WatchFileCenter_ITCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_multi_file_modify() throws Exception {
|
void testMultiFileModify() throws Exception {
|
||||||
CountDownLatch latch = new CountDownLatch(10);
|
CountDownLatch latch = new CountDownLatch(10);
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
AtomicInteger count = new AtomicInteger(0);
|
AtomicInteger count = new AtomicInteger(0);
|
||||||
Set<String> set = new ConcurrentHashSet<>();
|
Set<String> set = new ConcurrentHashSet<>();
|
||||||
|
|
||||||
final String fileName = "test2_file_change_" + i;
|
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 {
|
try {
|
||||||
func(fileName, file, content -> {
|
func(fileName, file, content -> {
|
||||||
set.add(content);
|
set.add(content);
|
||||||
@ -148,10 +152,10 @@ class WatchFileCenter_ITCase {
|
|||||||
private void func(final String fileName, final File file, final Consumer<String> consumer) throws Exception {
|
private void func(final String fileName, final File file, final Consumer<String> consumer) throws Exception {
|
||||||
CountDownLatch latch = new CountDownLatch(100);
|
CountDownLatch latch = new CountDownLatch(100);
|
||||||
DiskUtils.touch(file);
|
DiskUtils.touch(file);
|
||||||
WatchFileCenter.registerWatcher(path, new FileWatcher() {
|
WatchFileCenter.registerWatcher(PATH, new FileWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(FileChangeEvent event) {
|
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);
|
final String content = DiskUtils.readFile(file);
|
||||||
consumer.accept(content);
|
consumer.accept(content);
|
||||||
}
|
}
|
||||||
@ -165,10 +169,10 @@ class WatchFileCenter_ITCase {
|
|||||||
final AtomicInteger id = new AtomicInteger(0);
|
final AtomicInteger id = new AtomicInteger(0);
|
||||||
final AtomicReference<String> finalContent = new AtomicReference<>(null);
|
final AtomicReference<String> finalContent = new AtomicReference<>(null);
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
executor.execute(() -> {
|
EXECUTOR.execute(() -> {
|
||||||
final String j = fileName + "_" + id.incrementAndGet();
|
final String j = fileName + "_" + id.incrementAndGet();
|
||||||
try {
|
try {
|
||||||
final File file1 = Paths.get(path, fileName).toFile();
|
final File file1 = Paths.get(PATH, fileName).toFile();
|
||||||
synchronized (monitor) {
|
synchronized (monitor) {
|
||||||
finalContent.set(j);
|
finalContent.set(j);
|
||||||
DiskUtils.writeFile(file1, j.getBytes(StandardCharsets.UTF_8), false);
|
DiskUtils.writeFile(file1, j.getBytes(StandardCharsets.UTF_8), false);
|
Loading…
Reference in New Issue
Block a user