Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #12185]fix: use nacos properties in CacheDirUtil #12186

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading