From c6b088cd91918fab76e4b50ee8715f370be8ad47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BF=8A=20SionYang?= Date: Tue, 15 Oct 2024 11:53:46 +0800 Subject: [PATCH] Add log for server list manager and split constructor and start. (#12736) --- .../address/AbstractServerListManager.java | 46 +++++++++++++------ .../config/impl/ConfigServerListManager.java | 8 ++-- .../naming/NacosNamingMaintainService.java | 1 + .../naming/core/NamingServerListManager.java | 13 ++++-- .../remote/NamingClientProxyDelegate.java | 1 + .../client/config/NacosConfigServiceTest.java | 7 ++- .../config/http/ServerHttpAgentTest.java | 1 + .../impl/ConfigServerListManagerTest.java | 20 +++++++- .../core/NamingServerListManagerTest.java | 21 +++++++-- 9 files changed, 87 insertions(+), 31 deletions(-) diff --git a/client/src/main/java/com/alibaba/nacos/client/address/AbstractServerListManager.java b/client/src/main/java/com/alibaba/nacos/client/address/AbstractServerListManager.java index 5226f4dc26d..06cb728c7f7 100644 --- a/client/src/main/java/com/alibaba/nacos/client/address/AbstractServerListManager.java +++ b/client/src/main/java/com/alibaba/nacos/client/address/AbstractServerListManager.java @@ -42,7 +42,7 @@ public abstract class AbstractServerListManager implements ServerListFactory, Cl protected ServerListProvider serverListProvider; - private NacosClientProperties properties; + protected NacosClientProperties properties; public AbstractServerListManager(NacosClientProperties properties) throws NacosException { this(properties, null); @@ -54,24 +54,12 @@ public AbstractServerListManager(NacosClientProperties properties, String namesp return; } if (StringUtils.isNotBlank(namespace)) { + // To avoid set operation affect the original properties. + properties = properties.derive(); properties.setProperty(PropertyKeyConst.NAMESPACE, namespace); } properties.setProperty(PropertyKeyConst.CLIENT_MODULE_TYPE, getModuleName()); this.properties = properties; - Collection serverListProviders = NacosServiceLoader.load(ServerListProvider.class); - Collection sorted = serverListProviders.stream() - .sorted((a, b) -> b.getOrder() - a.getOrder()).collect(Collectors.toList()); - for (ServerListProvider each : sorted) { - if (each.match(properties)) { - this.serverListProvider = each; - break; - } - } - if (null == serverListProvider) { - LOGGER.error("no server list provider found"); - return; - } - this.serverListProvider.init(properties, getNacosRestTemplate()); } @Override @@ -90,6 +78,32 @@ public void shutdown() throws NacosException { LOGGER.info("{} do shutdown stop", className); } + /** + * Start server list manager. + * + * @throws NacosException during start and initialize. + */ + public void start() throws NacosException { + Collection serverListProviders = NacosServiceLoader.load(ServerListProvider.class); + Collection sorted = serverListProviders.stream() + .sorted((a, b) -> b.getOrder() - a.getOrder()).collect(Collectors.toList()); + for (ServerListProvider each : sorted) { + boolean matchResult = each.match(properties); + LOGGER.info("Load and match ServerListProvider {}, match result: {}", each.getClass().getCanonicalName(), + matchResult); + if (matchResult) { + this.serverListProvider = each; + LOGGER.info("Will use {} as ServerListProvider", this.serverListProvider.getClass().getCanonicalName()); + break; + } + } + if (null == serverListProvider) { + LOGGER.error("no server list provider found"); + return; + } + this.serverListProvider.init(properties, getNacosRestTemplate()); + } + public NacosClientProperties getProperties() { return properties; } @@ -116,12 +130,14 @@ public boolean isFixed() { /** * get module name. + * * @return module name */ public abstract String getModuleName(); /** * get nacos rest template. + * * @return nacos rest template */ public abstract NacosRestTemplate getNacosRestTemplate(); diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigServerListManager.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigServerListManager.java index 9edd643db10..e6f0c611559 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigServerListManager.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigServerListManager.java @@ -43,7 +43,7 @@ public class ConfigServerListManager extends AbstractServerListManager { /** * The name of the different environment. */ - private final String name; + private String name; private String tenant = ""; @@ -53,7 +53,6 @@ public class ConfigServerListManager extends AbstractServerListManager { public ConfigServerListManager(NacosClientProperties properties) throws NacosException { super(properties); - this.name = initServerName(properties); String namespace = properties.getProperty(PropertyKeyConst.NAMESPACE); if (StringUtils.isNotBlank(namespace)) { this.tenant = namespace; @@ -70,7 +69,10 @@ public NacosRestTemplate getNacosRestTemplate() { return ConfigHttpClientManager.getInstance().getNacosRestTemplate(); } - public void start() { + @Override + public void start() throws NacosException { + super.start(); + this.name = initServerName(properties); iterator = iterator(); currentServerAddr = iterator.next(); } diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingMaintainService.java b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingMaintainService.java index 07a8033c5c5..85351f12d5f 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingMaintainService.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingMaintainService.java @@ -80,6 +80,7 @@ private void init(Properties properties) throws NacosException { InitUtils.initSerialization(); InitUtils.initWebRootContext(nacosClientProperties); serverListManager = new NamingServerListManager(nacosClientProperties, namespace); + serverListManager.start(); securityProxy = new SecurityProxy(serverListManager.getServerList(), NamingHttpClientManager.getInstance().getNacosRestTemplate()); initSecurityProxy(properties); diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/core/NamingServerListManager.java b/client/src/main/java/com/alibaba/nacos/client/naming/core/NamingServerListManager.java index 5a9c8a57320..c35b2879c66 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/core/NamingServerListManager.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/core/NamingServerListManager.java @@ -23,6 +23,7 @@ import com.alibaba.nacos.client.env.NacosClientProperties; import com.alibaba.nacos.client.naming.remote.http.NamingHttpClientManager; import com.alibaba.nacos.client.utils.LogUtils; +import com.alibaba.nacos.common.JustForTest; import com.alibaba.nacos.common.http.client.NacosRestTemplate; import org.slf4j.Logger; @@ -46,16 +47,18 @@ public class NamingServerListManager extends AbstractServerListManager { private boolean isDomain; + @JustForTest public NamingServerListManager(Properties properties) throws NacosException { - this(NacosClientProperties.PROTOTYPE.derive(properties)); - } - - public NamingServerListManager(NacosClientProperties properties) throws NacosException { - this(properties, ""); + this(NacosClientProperties.PROTOTYPE.derive(properties), ""); } public NamingServerListManager(NacosClientProperties properties, String namespace) throws NacosException { super(properties, namespace); + } + + @Override + public void start() throws NacosException { + super.start(); List serverList = getServerList(); if (serverList.isEmpty()) { throw new NacosLoadException("serverList is empty,please check configuration"); diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/remote/NamingClientProxyDelegate.java b/client/src/main/java/com/alibaba/nacos/client/naming/remote/NamingClientProxyDelegate.java index ac87ac9a193..beef78ad036 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/remote/NamingClientProxyDelegate.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/remote/NamingClientProxyDelegate.java @@ -72,6 +72,7 @@ public NamingClientProxyDelegate(String namespace, ServiceInfoHolder serviceInfo this.serviceInfoUpdateService = new ServiceInfoUpdateService(properties, serviceInfoHolder, this, changeNotifier); this.serverListManager = new NamingServerListManager(properties, namespace); + this.serverListManager.start(); this.serviceInfoHolder = serviceInfoHolder; this.securityProxy = new SecurityProxy(this.serverListManager.getServerList(), NamingHttpClientManager.getInstance().getNacosRestTemplate()); diff --git a/client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java b/client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java index dd9e2f8b89e..e5287eadee5 100644 --- a/client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java +++ b/client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java @@ -188,7 +188,9 @@ public void receiveConfigInfo(String configInfo) { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, "aaa"); final NacosClientProperties nacosProperties = NacosClientProperties.PROTOTYPE.derive(properties); - Mockito.when(mockWoker.getAgent()).thenReturn(new ConfigTransportClient(nacosProperties, new ConfigServerListManager(nacosProperties)) { + ConfigServerListManager mgr = new ConfigServerListManager(nacosProperties); + mgr.start(); + ConfigTransportClient client = new ConfigTransportClient(nacosProperties, mgr) { @Override public void startInternal() throws NacosException { // NOOP @@ -235,7 +237,8 @@ public boolean publishConfig(String dataId, String group, String tenant, String public boolean removeConfig(String dataId, String group, String tenant, String tag) throws NacosException { return false; } - }); + }; + Mockito.when(mockWoker.getAgent()).thenReturn(client); final String config = nacosConfigService.getConfigAndSignListener(dataId, group, timeout, listener); assertEquals(content, config); diff --git a/client/src/test/java/com/alibaba/nacos/client/config/http/ServerHttpAgentTest.java b/client/src/test/java/com/alibaba/nacos/client/config/http/ServerHttpAgentTest.java index d73f2ede288..ee471513b9e 100644 --- a/client/src/test/java/com/alibaba/nacos/client/config/http/ServerHttpAgentTest.java +++ b/client/src/test/java/com/alibaba/nacos/client/config/http/ServerHttpAgentTest.java @@ -146,6 +146,7 @@ void testGetterAndSetter() throws Exception { when(mockedProperties.getProperty(PropertyKeyConst.ENDPOINT)).thenReturn("aaa"); when(mockedProperties.getProperty(PropertyKeyConst.NAMESPACE)).thenReturn("namespace1"); ConfigServerListManager server = new ConfigServerListManager(mockedProperties); + server.start(); final ServerHttpAgent serverHttpAgent = new ServerHttpAgent(server, new Properties()); final String appname = ServerHttpAgent.getAppname(); diff --git a/client/src/test/java/com/alibaba/nacos/client/config/impl/ConfigServerListManagerTest.java b/client/src/test/java/com/alibaba/nacos/client/config/impl/ConfigServerListManagerTest.java index 1cce63b0c4f..006aff12357 100644 --- a/client/src/test/java/com/alibaba/nacos/client/config/impl/ConfigServerListManagerTest.java +++ b/client/src/test/java/com/alibaba/nacos/client/config/impl/ConfigServerListManagerTest.java @@ -43,8 +43,8 @@ import static com.alibaba.nacos.common.constant.RequestUrlConstants.HTTP_PREFIX; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.contains; @@ -104,6 +104,7 @@ void testGetter() throws NacosException { when(mockedProperties.getProperty(PropertyKeyConst.SERVER_ADDR)).thenReturn("1.1.1.1"); when(mockedProperties.getProperty(PropertyKeyConst.NAMESPACE)).thenReturn("namespace"); final ConfigServerListManager mgr = new ConfigServerListManager(mockedProperties); + mgr.start(); assertEquals("nacos", mgr.getContextPath()); assertEquals("Config-fixed-namespace-1.1.1.1_8848", mgr.getName()); assertEquals("namespace", mgr.getTenant()); @@ -119,6 +120,7 @@ void testGetter() throws NacosException { final NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties); final ConfigServerListManager mgr2 = new ConfigServerListManager(nacosClientProperties); + mgr2.start(); assertEquals("aaa", mgr2.getContextPath()); } @@ -129,6 +131,7 @@ void testGetter() throws NacosException { properties.put(PropertyKeyConst.SERVER_ADDR, "https://1.1.1.1:8848"); final NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties); final ConfigServerListManager mgr2 = new ConfigServerListManager(nacosClientProperties); + mgr2.start(); assertEquals("aaa", mgr2.getContextPath()); assertEquals("[https://1.1.1.1:8848]", mgr2.getServerList().toString()); } @@ -140,6 +143,7 @@ void testGetter() throws NacosException { final NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties2); final ConfigServerListManager mgr3 = new ConfigServerListManager(nacosClientProperties); + mgr3.start(); assertEquals(1, mgr3.getServerList().size()); assertEquals("1.1.1.1:8848", mgr3.getServerList().get(0)); assertEquals("[1.1.1.1:8848]", mgr3.getUrlString()); @@ -154,6 +158,7 @@ void testGetter() throws NacosException { final NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties3); final ConfigServerListManager mgr4 = new ConfigServerListManager(nacosClientProperties); + mgr4.start(); assertEquals(2, mgr4.getServerList().size()); assertEquals("1.1.1.1:8848", mgr4.getServerList().get(0)); assertEquals("2.2.2.2:8848", mgr4.getServerList().get(1)); @@ -169,6 +174,7 @@ void testGetter() throws NacosException { final NacosClientProperties nacosClientProperties = NacosClientProperties.PROTOTYPE.derive(properties4); final ConfigServerListManager mgr5 = new ConfigServerListManager(nacosClientProperties); + mgr5.start(); assertEquals(2, mgr5.getServerList().size()); assertEquals("1.1.1.1:8848", mgr5.getServerList().get(0)); assertEquals("2.2.2.2:8848", mgr5.getServerList().get(1)); @@ -185,15 +191,18 @@ void testIterator() throws NacosException { when(mockedProperties.getProperty(PropertyKeyConst.SERVER_ADDR)).thenReturn("1.1.1.1:8848"); when(mockedProperties.getProperty(PropertyKeyConst.NAMESPACE)).thenReturn("aaa"); final ConfigServerListManager mgr = new ConfigServerListManager(mockedProperties); + mgr.start(); // new iterator final Iterator it = mgr.iterator(); assertTrue(it.hasNext()); assertEquals("1.1.1.1:8848", it.next()); - assertNull(mgr.getIterator()); + Iterator initIterator = mgr.getIterator(); + assertNotNull(initIterator); mgr.refreshCurrentServerAddr(); assertNotNull(mgr.getIterator()); + assertNotEquals(initIterator, mgr.getIterator()); final String currentServerAddr = mgr.getCurrentServer(); assertEquals("1.1.1.1:8848", currentServerAddr); @@ -215,6 +224,7 @@ void testAddressServerBaseServerAddrsStr() throws NacosException { properties.setProperty(PropertyKeyConst.CONTEXT_PATH, endpointContextPath); final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties); ConfigServerListManager serverListManager = new ConfigServerListManager(clientProperties); + serverListManager.start(); assertEquals(1, serverListManager.getServerList().size()); assertTrue(serverListManager.getServerList().contains(serverAddrStr)); } @@ -230,6 +240,7 @@ void testAddressServerBaseEndpoint() throws NacosException { properties.setProperty(PropertyKeyConst.ENDPOINT_CONTEXT_PATH, endpointContextPath); final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties); ConfigServerListManager serverListManager = new ConfigServerListManager(clientProperties); + serverListManager.start(); assertTrue(serverListManager.getAddressSource().startsWith( HTTP_PREFIX + endpoint + ":" + endpointPort + endpointContextPath)); } @@ -247,6 +258,7 @@ void testInitParam() throws NacosException, NoSuchFieldException, IllegalAccessE properties.setProperty(PropertyKeyConst.CONTEXT_PATH, contextPath); final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties); ConfigServerListManager serverListManager = new ConfigServerListManager(clientProperties); + serverListManager.start(); Field providerField = AbstractServerListManager.class.getDeclaredField("serverListProvider"); providerField.setAccessible(true); ServerListProvider serverListProvider = (ServerListProvider) providerField.get(serverListManager); @@ -285,6 +297,7 @@ void testWithEndpointContextPath() throws NacosException { properties.setProperty(PropertyKeyConst.CONTEXT_PATH, contextPath); final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties); ConfigServerListManager serverListManager = new ConfigServerListManager(clientProperties); + serverListManager.start(); assertTrue(serverListManager.getAddressSource().contains(endpointContextPath)); assertTrue(serverListManager.getName().contains("endpointContextPath")); } @@ -306,6 +319,7 @@ void testWithEndpointClusterName() throws NacosException { properties.setProperty(PropertyKeyConst.CONTEXT_PATH, contextPath); final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties); ConfigServerListManager serverListManager = new ConfigServerListManager(clientProperties); + serverListManager.start(); String addressSource = serverListManager.getAddressSource(); assertTrue(addressSource.contains(endpointContextPath)); assertTrue(serverListManager.getName().contains("endpointContextPath")); @@ -329,6 +343,7 @@ void testWithoutEndpointContextPath() throws NacosException { properties.setProperty(PropertyKeyConst.CONTEXT_PATH, contextPath); final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties); ConfigServerListManager serverListManager = new ConfigServerListManager(clientProperties); + serverListManager.start(); String endpointContextPath = "/endpointContextPath"; assertFalse(serverListManager.getAddressSource().contains(endpointContextPath)); @@ -346,6 +361,7 @@ void testUseEndpointParsingRule() throws NacosException { properties.setProperty(PropertyKeyConst.ENDPOINT_PORT, "9090"); final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties); ConfigServerListManager serverListManager = new ConfigServerListManager(clientProperties); + serverListManager.start(); String addressServerUrl = serverListManager.getAddressSource(); assertTrue(addressServerUrl.startsWith("http://1.1.1.1")); } diff --git a/client/src/test/java/com/alibaba/nacos/client/naming/core/NamingServerListManagerTest.java b/client/src/test/java/com/alibaba/nacos/client/naming/core/NamingServerListManagerTest.java index 0b9b3e9df2f..2f542249922 100644 --- a/client/src/test/java/com/alibaba/nacos/client/naming/core/NamingServerListManagerTest.java +++ b/client/src/test/java/com/alibaba/nacos/client/naming/core/NamingServerListManagerTest.java @@ -99,6 +99,7 @@ void testConstructWithAddr() throws NacosException { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848,127.0.0.1:8849"); serverListManager = new NamingServerListManager(properties); + serverListManager.start(); final List serverList = serverListManager.getServerList(); assertEquals(2, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -110,6 +111,7 @@ void testConstructWithAddrTryToRefresh() throws Exception { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848,127.0.0.1:8849"); serverListManager = new NamingServerListManager(properties); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(2, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -125,6 +127,7 @@ void testConstructWithEndpointAndRefresh() throws Exception { Properties properties = new Properties(); properties.put(PropertyKeyConst.ENDPOINT, "127.0.0.1"); serverListManager = new NamingServerListManager(properties); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(1, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -142,6 +145,7 @@ void testConstructWithEndpointAndTimedNotNeedRefresh() throws Exception { Properties properties = new Properties(); properties.put(PropertyKeyConst.ENDPOINT, "127.0.0.1"); serverListManager = new NamingServerListManager(properties); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(1, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -157,6 +161,7 @@ void testConstructWithEndpointAndRefreshEmpty() throws Exception { Properties properties = new Properties(); properties.put(PropertyKeyConst.ENDPOINT, "127.0.0.1"); serverListManager = new NamingServerListManager(properties); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(1, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -172,6 +177,7 @@ void testConstructWithEndpointAndRefreshException() throws Exception { Properties properties = new Properties(); properties.put(PropertyKeyConst.ENDPOINT, "127.0.0.1"); serverListManager = new NamingServerListManager(properties); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(1, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -190,7 +196,8 @@ void testConstructWithEndpointWithCustomPathAndName() throws Exception { Mockito.reset(nacosRestTemplate); Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/bbb"), any(), any(), any())) .thenReturn(httpRestResult); - serverListManager = new NamingServerListManager(clientProperties); + serverListManager = new NamingServerListManager(clientProperties, ""); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(1, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -204,7 +211,8 @@ void testConstructWithEndpointWithEndpointPathAndName() throws Exception { Mockito.reset(nacosRestTemplate); Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/bbb"), any(), any(), any())) .thenReturn(httpRestResult); - serverListManager = new NamingServerListManager(clientProperties); + serverListManager = new NamingServerListManager(clientProperties, ""); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(1, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -219,7 +227,8 @@ void testConstructEndpointContextPathPriority() throws Exception { Mockito.reset(nacosRestTemplate); Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/aaa/ccc"), any(), any(), any())) .thenReturn(httpRestResult); - serverListManager = new NamingServerListManager(clientProperties); + serverListManager = new NamingServerListManager(clientProperties, ""); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(1, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -234,7 +243,8 @@ void testConstructEndpointContextPathIsEmpty() throws Exception { Mockito.reset(nacosRestTemplate); Mockito.when(nacosRestTemplate.get(eq("http://127.0.0.1:8080/bbb/ccc"), any(), any(), any())) .thenReturn(httpRestResult); - serverListManager = new NamingServerListManager(clientProperties); + serverListManager = new NamingServerListManager(clientProperties, ""); + serverListManager.start(); List serverList = serverListManager.getServerList(); assertEquals(1, serverList.size()); assertEquals("127.0.0.1:8848", serverList.get(0)); @@ -245,6 +255,7 @@ void testIsDomain() throws Exception { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848"); serverListManager = new NamingServerListManager(properties); + serverListManager.start(); // todo //assertTrue(serverListManager.isDomain()); // assertEquals("127.0.0.1:8848", serverListManager()); @@ -255,6 +266,7 @@ void testGetCurrentServer() throws NacosException { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848"); final NamingServerListManager serverListManager = new NamingServerListManager(properties); + serverListManager.start(); assertEquals("127.0.0.1:8848", serverListManager.getCurrentServer()); assertEquals("127.0.0.1:8848", serverListManager.genNextServer()); } @@ -264,6 +276,7 @@ void testShutdown() throws NacosException { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848"); final NamingServerListManager serverListManager = new NamingServerListManager(properties); + serverListManager.start(); Assertions.assertDoesNotThrow(() -> { serverListManager.shutdown(); });