fix: use nacos properties in CacheDirUtil (#12186)
This commit is contained in:
parent
d68b904f93
commit
7590a4eb12
@ -49,7 +49,7 @@ public class CacheDirUtil {
|
||||
*/
|
||||
public static String initCacheDir(String namespace, NacosClientProperties properties) {
|
||||
|
||||
String jmSnapshotPath = System.getProperty(JM_SNAPSHOT_PATH_PROPERTY);
|
||||
String jmSnapshotPath = properties.getProperty(JM_SNAPSHOT_PATH_PROPERTY);
|
||||
|
||||
String namingCacheRegistryDir = "";
|
||||
if (properties.getProperty(PropertyKeyConst.NAMING_CACHE_REGISTRY_DIR) != null) {
|
||||
@ -62,7 +62,7 @@ public class CacheDirUtil {
|
||||
+ FILE_PATH_NAMING + File.separator + namespace;
|
||||
} else {
|
||||
cacheDir =
|
||||
System.getProperty(USER_HOME_PROPERTY) + File.separator + FILE_PATH_NACOS + namingCacheRegistryDir
|
||||
properties.getProperty(USER_HOME_PROPERTY) + File.separator + FILE_PATH_NACOS + namingCacheRegistryDir
|
||||
+ File.separator + FILE_PATH_NAMING + File.separator + namespace;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,14 @@ class CacheDirUtilTest {
|
||||
assertEquals("/home/admin/nacos/naming/test", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitCacheDirWithDefaultRootAndWithoutCache2() {
|
||||
NacosClientProperties properties = NacosClientProperties.PROTOTYPE.derive();
|
||||
properties.setProperty("user.home", "/home/test");
|
||||
String actual = CacheDirUtil.initCacheDir("test", properties);
|
||||
assertEquals("/home/test/nacos/naming/test", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitCacheDirWithDefaultRootAndWithCache() {
|
||||
System.setProperty("user.home", "/home/admin");
|
||||
@ -54,6 +62,14 @@ class CacheDirUtilTest {
|
||||
assertEquals("/home/snapshot/nacos/naming/test", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitCacheDirWithJmSnapshotPathRootAndWithoutCache2() {
|
||||
NacosClientProperties properties = NacosClientProperties.PROTOTYPE.derive();
|
||||
properties.setProperty("JM.SNAPSHOT.PATH", "/home/custom/snapshot");
|
||||
String actual = CacheDirUtil.initCacheDir("test", properties);
|
||||
assertEquals("/home/custom/snapshot/nacos/naming/test", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitCacheDirWithJmSnapshotPathRootAndWithCache() {
|
||||
System.setProperty("user.home", "/home/snapshot");
|
||||
@ -62,4 +78,4 @@ class CacheDirUtilTest {
|
||||
String actual = CacheDirUtil.initCacheDir("test", properties);
|
||||
assertEquals("/home/snapshot/nacos/custom/naming/test", actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user