add endpoint cluster name for config & naming server list manager (#12253)
This commit is contained in:
parent
5d871967ea
commit
63dc87a30c
@ -35,6 +35,8 @@ public class PropertyKeyConst {
|
|||||||
|
|
||||||
public static final String ENDPOINT_CONTEXT_PATH = "endpointContextPath";
|
public static final String ENDPOINT_CONTEXT_PATH = "endpointContextPath";
|
||||||
|
|
||||||
|
public static final String ENDPOINT_CLUSTER_NAME = "endpointClusterName";
|
||||||
|
|
||||||
public static final String SERVER_NAME = "serverName";
|
public static final String SERVER_NAME = "serverName";
|
||||||
|
|
||||||
public static final String NAMESPACE = "namespace";
|
public static final String NAMESPACE = "namespace";
|
||||||
|
@ -293,7 +293,8 @@ public class ServerListManager implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initServerListName(NacosClientProperties properties) {
|
private void initServerListName(NacosClientProperties properties) {
|
||||||
String serverListNameTmp = properties.getProperty(PropertyKeyConst.CLUSTER_NAME);
|
String serverListNameTmp = properties.getProperty(PropertyKeyConst.ENDPOINT_CLUSTER_NAME,
|
||||||
|
properties.getProperty(PropertyKeyConst.CLUSTER_NAME));
|
||||||
if (!StringUtils.isBlank(serverListNameTmp)) {
|
if (!StringUtils.isBlank(serverListNameTmp)) {
|
||||||
this.serverListName = serverListNameTmp;
|
this.serverListName = serverListNameTmp;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ public class ServerListManager implements ServerListFactory, Closeable {
|
|||||||
if (!StringUtils.isBlank(contentPathTmp)) {
|
if (!StringUtils.isBlank(contentPathTmp)) {
|
||||||
this.contentPath = contentPathTmp;
|
this.contentPath = contentPathTmp;
|
||||||
}
|
}
|
||||||
String serverListNameTmp = properties.getProperty(PropertyKeyConst.CLUSTER_NAME);
|
String serverListNameTmp = properties.getProperty(PropertyKeyConst.ENDPOINT_CLUSTER_NAME);
|
||||||
if (!StringUtils.isBlank(serverListNameTmp)) {
|
if (!StringUtils.isBlank(serverListNameTmp)) {
|
||||||
this.serverListName = serverListNameTmp;
|
this.serverListName = serverListNameTmp;
|
||||||
}
|
}
|
||||||
|
@ -235,6 +235,34 @@ class ServerListManagerTest {
|
|||||||
assertTrue(serverListManager.getName().contains("endpointContextPath"));
|
assertTrue(serverListManager.getName().contains("endpointContextPath"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testWithEndpointClusterName() throws NacosException {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
String endpoint = "127.0.0.1";
|
||||||
|
properties.setProperty(PropertyKeyConst.ENDPOINT, endpoint);
|
||||||
|
String endpointPort = "9090";
|
||||||
|
properties.setProperty(PropertyKeyConst.ENDPOINT_PORT, endpointPort);
|
||||||
|
String testEndpointClusterName = "testEndpointClusterName";
|
||||||
|
properties.setProperty(PropertyKeyConst.ENDPOINT_CLUSTER_NAME, testEndpointClusterName);
|
||||||
|
String testClusterName = "testClusterName";
|
||||||
|
properties.setProperty(PropertyKeyConst.CLUSTER_NAME, testClusterName);
|
||||||
|
String endpointContextPath = "/endpointContextPath";
|
||||||
|
properties.setProperty(PropertyKeyConst.ENDPOINT_CONTEXT_PATH, endpointContextPath);
|
||||||
|
String contextPath = "/contextPath";
|
||||||
|
properties.setProperty(PropertyKeyConst.CONTEXT_PATH, contextPath);
|
||||||
|
final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
|
||||||
|
ServerListManager serverListManager = new ServerListManager(clientProperties);
|
||||||
|
assertTrue(serverListManager.addressServerUrl.contains(endpointContextPath));
|
||||||
|
assertTrue(serverListManager.getName().contains("endpointContextPath"));
|
||||||
|
|
||||||
|
assertTrue(serverListManager.addressServerUrl.contains(testEndpointClusterName));
|
||||||
|
assertTrue(serverListManager.getName().contains(testEndpointClusterName));
|
||||||
|
|
||||||
|
assertFalse(serverListManager.addressServerUrl.contains(testClusterName));
|
||||||
|
assertFalse(serverListManager.getName().contains(testClusterName));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWithoutEndpointContextPath() throws NacosException {
|
void testWithoutEndpointContextPath() throws NacosException {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
@ -199,7 +199,7 @@ class ServerListManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
void testConstructWithEndpointWithCustomPathAndName() throws Exception {
|
void testConstructWithEndpointWithCustomPathAndName() throws Exception {
|
||||||
clientProperties.setProperty(PropertyKeyConst.CONTEXT_PATH, "aaa");
|
clientProperties.setProperty(PropertyKeyConst.CONTEXT_PATH, "aaa");
|
||||||
clientProperties.setProperty(PropertyKeyConst.CLUSTER_NAME, "bbb");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CLUSTER_NAME, "bbb");
|
||||||
clientProperties.setProperty(PropertyKeyConst.ENDPOINT, "127.0.0.1");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT, "127.0.0.1");
|
||||||
Mockito.reset(nacosRestTemplate);
|
Mockito.reset(nacosRestTemplate);
|
||||||
Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/bbb"), any(), any(), any()))
|
Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/bbb"), any(), any(), any()))
|
||||||
@ -213,7 +213,7 @@ class ServerListManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
void testConstructWithEndpointWithEndpointPathAndName() throws Exception {
|
void testConstructWithEndpointWithEndpointPathAndName() throws Exception {
|
||||||
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CONTEXT_PATH, "aaa");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CONTEXT_PATH, "aaa");
|
||||||
clientProperties.setProperty(PropertyKeyConst.CLUSTER_NAME, "bbb");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CLUSTER_NAME, "bbb");
|
||||||
clientProperties.setProperty(PropertyKeyConst.ENDPOINT, "127.0.0.1");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT, "127.0.0.1");
|
||||||
Mockito.reset(nacosRestTemplate);
|
Mockito.reset(nacosRestTemplate);
|
||||||
Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/bbb"), any(), any(), any()))
|
Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/bbb"), any(), any(), any()))
|
||||||
@ -228,7 +228,7 @@ class ServerListManagerTest {
|
|||||||
void testConstructEndpointContextPathPriority() throws Exception {
|
void testConstructEndpointContextPathPriority() throws Exception {
|
||||||
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CONTEXT_PATH, "aaa");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CONTEXT_PATH, "aaa");
|
||||||
clientProperties.setProperty(PropertyKeyConst.CONTEXT_PATH, "bbb");
|
clientProperties.setProperty(PropertyKeyConst.CONTEXT_PATH, "bbb");
|
||||||
clientProperties.setProperty(PropertyKeyConst.CLUSTER_NAME, "ccc");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CLUSTER_NAME, "ccc");
|
||||||
clientProperties.setProperty(PropertyKeyConst.ENDPOINT, "127.0.0.1");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT, "127.0.0.1");
|
||||||
Mockito.reset(nacosRestTemplate);
|
Mockito.reset(nacosRestTemplate);
|
||||||
Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/ccc"), any(), any(), any()))
|
Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/ccc"), any(), any(), any()))
|
||||||
@ -243,7 +243,7 @@ class ServerListManagerTest {
|
|||||||
void testConstructEndpointContextPathIsEmpty() throws Exception {
|
void testConstructEndpointContextPathIsEmpty() throws Exception {
|
||||||
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CONTEXT_PATH, "");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CONTEXT_PATH, "");
|
||||||
clientProperties.setProperty(PropertyKeyConst.CONTEXT_PATH, "bbb");
|
clientProperties.setProperty(PropertyKeyConst.CONTEXT_PATH, "bbb");
|
||||||
clientProperties.setProperty(PropertyKeyConst.CLUSTER_NAME, "ccc");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT_CLUSTER_NAME, "ccc");
|
||||||
clientProperties.setProperty(PropertyKeyConst.ENDPOINT, "127.0.0.1");
|
clientProperties.setProperty(PropertyKeyConst.ENDPOINT, "127.0.0.1");
|
||||||
Mockito.reset(nacosRestTemplate);
|
Mockito.reset(nacosRestTemplate);
|
||||||
Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/bbb/ccc"), any(), any(), any()))
|
Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/bbb/ccc"), any(), any(), any()))
|
||||||
|
Loading…
Reference in New Issue
Block a user