Skip to content

Commit

Permalink
fix: use nacos properties in CacheDirUtil (alibaba#12186)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalk authored Jun 12, 2024
1 parent d68b904 commit 7590a4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -62,7 +62,7 @@ public static String initCacheDir(String namespace, NacosClientProperties proper
+ 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ void testInitCacheDirWithDefaultRootAndWithoutCache() {
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");
Expand All @@ -54,6 +62,14 @@ void testInitCacheDirWithJmSnapshotPathRootAndWithoutCache() {
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");
Expand All @@ -62,4 +78,4 @@ void testInitCacheDirWithJmSnapshotPathRootAndWithCache() {
String actual = CacheDirUtil.initCacheDir("test", properties);
assertEquals("/home/snapshot/nacos/custom/naming/test", actual);
}
}
}

0 comments on commit 7590a4e

Please sign in to comment.