Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
apollo
Commits
612f1967
Unverified
Commit
612f1967
authored
Jul 21, 2018
by
Jason Song
Committed by
GitHub
Jul 21, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1274 from nobodyiam/config-local-cache-dir
local cache dir customizable
parents
87c65bfe
ba135814
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
1 deletion
+55
-1
apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java
...main/java/com/ctrip/framework/apollo/util/ConfigUtil.java
+19
-1
apollo-client/src/test/java/com/ctrip/framework/apollo/util/ConfigUtilTest.java
.../java/com/ctrip/framework/apollo/util/ConfigUtilTest.java
+36
-0
No files found.
apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java
View file @
612f1967
package
com
.
ctrip
.
framework
.
apollo
.
util
;
package
com
.
ctrip
.
framework
.
apollo
.
util
;
import
java.io.File
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -206,10 +207,27 @@ public class ConfigUtil {
...
@@ -206,10 +207,27 @@ public class ConfigUtil {
}
}
public
String
getDefaultLocalCacheDir
()
{
public
String
getDefaultLocalCacheDir
()
{
String
cacheRoot
=
isOSWindows
()
?
"C:\\opt\\data\\%s"
:
"/opt/data/%s"
;
String
cacheRoot
=
getCustomizedCacheRoot
();
if
(!
Strings
.
isNullOrEmpty
(
cacheRoot
))
{
return
cacheRoot
+
File
.
separator
+
getAppId
();
}
cacheRoot
=
isOSWindows
()
?
"C:\\opt\\data\\%s"
:
"/opt/data/%s"
;
return
String
.
format
(
cacheRoot
,
getAppId
());
return
String
.
format
(
cacheRoot
,
getAppId
());
}
}
private
String
getCustomizedCacheRoot
()
{
// 1. Get from System Property
String
cacheRoot
=
System
.
getProperty
(
"apollo.cacheDir"
);
if
(
Strings
.
isNullOrEmpty
(
cacheRoot
))
{
// 2. Get from server.properties
cacheRoot
=
Foundation
.
server
().
getProperty
(
"apollo.cacheDir"
,
null
);
}
return
cacheRoot
;
}
public
boolean
isInLocalMode
()
{
public
boolean
isInLocalMode
()
{
try
{
try
{
Env
env
=
getApolloEnv
();
Env
env
=
getApolloEnv
();
...
...
apollo-client/src/test/java/com/ctrip/framework/apollo/util/ConfigUtilTest.java
View file @
612f1967
...
@@ -2,10 +2,14 @@ package com.ctrip.framework.apollo.util;
...
@@ -2,10 +2,14 @@ package com.ctrip.framework.apollo.util;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
java.io.File
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
...
@@ -22,6 +26,7 @@ public class ConfigUtilTest {
...
@@ -22,6 +26,7 @@ public class ConfigUtilTest {
System
.
clearProperty
(
"apollo.configCacheSize"
);
System
.
clearProperty
(
"apollo.configCacheSize"
);
System
.
clearProperty
(
"apollo.longPollingInitialDelayInMills"
);
System
.
clearProperty
(
"apollo.longPollingInitialDelayInMills"
);
System
.
clearProperty
(
"apollo.autoUpdateInjectedSpringProperties"
);
System
.
clearProperty
(
"apollo.autoUpdateInjectedSpringProperties"
);
System
.
clearProperty
(
"apollo.cacheDir"
);
}
}
@Test
@Test
...
@@ -185,4 +190,35 @@ public class ConfigUtilTest {
...
@@ -185,4 +190,35 @@ public class ConfigUtilTest {
assertEquals
(
someAutoUpdateInjectedSpringProperties
,
assertEquals
(
someAutoUpdateInjectedSpringProperties
,
configUtil
.
isAutoUpdateInjectedSpringPropertiesEnabled
());
configUtil
.
isAutoUpdateInjectedSpringPropertiesEnabled
());
}
}
@Test
public
void
testLocalCacheDirWithSystemProperty
()
throws
Exception
{
String
someCacheDir
=
"someCacheDir"
;
String
someAppId
=
"someAppId"
;
System
.
setProperty
(
"apollo.cacheDir"
,
someCacheDir
);
ConfigUtil
configUtil
=
spy
(
new
ConfigUtil
());
doReturn
(
someAppId
).
when
(
configUtil
).
getAppId
();
assertEquals
(
someCacheDir
+
File
.
separator
+
someAppId
,
configUtil
.
getDefaultLocalCacheDir
());
}
@Test
public
void
testDefaultLocalCacheDir
()
throws
Exception
{
String
someAppId
=
"someAppId"
;
ConfigUtil
configUtil
=
spy
(
new
ConfigUtil
());
doReturn
(
someAppId
).
when
(
configUtil
).
getAppId
();
doReturn
(
true
).
when
(
configUtil
).
isOSWindows
();
assertEquals
(
"C:\\opt\\data\\"
+
someAppId
,
configUtil
.
getDefaultLocalCacheDir
());
doReturn
(
false
).
when
(
configUtil
).
isOSWindows
();
assertEquals
(
"/opt/data/"
+
someAppId
,
configUtil
.
getDefaultLocalCacheDir
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment