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
ba135814
Commit
ba135814
authored
Jul 21, 2018
by
nobodyiam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactor and add ut
parent
215ebc70
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
16 deletions
+51
-16
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java
...framework/apollo/internals/LocalFileConfigRepository.java
+1
-1
apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java
...main/java/com/ctrip/framework/apollo/util/ConfigUtil.java
+13
-14
apollo-client/src/test/java/com/ctrip/framework/apollo/BaseIntegrationTest.java
.../java/com/ctrip/framework/apollo/BaseIntegrationTest.java
+1
-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/internals/LocalFileConfigRepository.java
View file @
ba135814
...
@@ -65,7 +65,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
...
@@ -65,7 +65,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
private
File
findLocalCacheDir
()
{
private
File
findLocalCacheDir
()
{
try
{
try
{
String
defaultCacheDir
=
m_configUtil
.
getLocalCacheDir
();
String
defaultCacheDir
=
m_configUtil
.
get
Default
LocalCacheDir
();
Path
path
=
Paths
.
get
(
defaultCacheDir
);
Path
path
=
Paths
.
get
(
defaultCacheDir
);
if
(!
Files
.
exists
(
path
))
{
if
(!
Files
.
exists
(
path
))
{
Files
.
createDirectories
(
path
);
Files
.
createDirectories
(
path
);
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java
View file @
ba135814
...
@@ -35,7 +35,6 @@ public class ConfigUtil {
...
@@ -35,7 +35,6 @@ public class ConfigUtil {
private
TimeUnit
configCacheExpireTimeUnit
=
TimeUnit
.
MINUTES
;
//1 minute
private
TimeUnit
configCacheExpireTimeUnit
=
TimeUnit
.
MINUTES
;
//1 minute
private
long
longPollingInitialDelayInMills
=
2000
;
//2 seconds
private
long
longPollingInitialDelayInMills
=
2000
;
//2 seconds
private
boolean
autoUpdateInjectedSpringProperties
=
true
;
private
boolean
autoUpdateInjectedSpringProperties
=
true
;
private
String
localCacheDir
=
this
.
getDefaultLocalCacheDir
();
public
ConfigUtil
()
{
public
ConfigUtil
()
{
initRefreshInterval
();
initRefreshInterval
();
...
@@ -46,7 +45,6 @@ public class ConfigUtil {
...
@@ -46,7 +45,6 @@ public class ConfigUtil {
initMaxConfigCacheSize
();
initMaxConfigCacheSize
();
initLongPollingInitialDelayInMills
();
initLongPollingInitialDelayInMills
();
initAutoUpdateInjectedSpringProperties
();
initAutoUpdateInjectedSpringProperties
();
initLocalCacheDir
();
}
}
/**
/**
...
@@ -208,25 +206,26 @@ public class ConfigUtil {
...
@@ -208,25 +206,26 @@ public class ConfigUtil {
return
onErrorRetryIntervalTimeUnit
;
return
onErrorRetryIntervalTimeUnit
;
}
}
private
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
void
initLocalCacheDir
()
{
private
String
getCustomizedCacheRoot
()
{
// 1. Get from System Property
// 1. Get from System Property
String
cacheRoot
=
System
.
getProperty
(
"apollo.
localC
acheDir"
);
String
cacheRoot
=
System
.
getProperty
(
"apollo.
c
acheDir"
);
if
(
Strings
.
isNullOrEmpty
(
cacheRoot
))
{
if
(
Strings
.
isNullOrEmpty
(
cacheRoot
))
{
// 2. Get from app.properties
// 2. Get from server.properties
cacheRoot
=
Foundation
.
app
().
getProperty
(
"apollo.localCacheDir"
,
null
);
cacheRoot
=
Foundation
.
server
().
getProperty
(
"apollo.cacheDir"
,
null
);
}
if
(!
Strings
.
isNullOrEmpty
(
cacheRoot
))
{
this
.
localCacheDir
=
String
.
format
(
cacheRoot
+
File
.
separator
+
"%s"
,
getAppId
());
}
}
}
public
String
getLocalCacheDir
()
{
return
cacheRoot
;
return
this
.
localCacheDir
;
}
}
public
boolean
isInLocalMode
()
{
public
boolean
isInLocalMode
()
{
...
...
apollo-client/src/test/java/com/ctrip/framework/apollo/BaseIntegrationTest.java
View file @
ba135814
...
@@ -178,7 +178,7 @@ public abstract class BaseIntegrationTest{
...
@@ -178,7 +178,7 @@ public abstract class BaseIntegrationTest{
}
}
@Override
@Override
public
String
getLocalCacheDir
()
{
public
String
get
Default
LocalCacheDir
()
{
return
ClassLoaderUtil
.
getClassPath
();
return
ClassLoaderUtil
.
getClassPath
();
}
}
...
...
apollo-client/src/test/java/com/ctrip/framework/apollo/util/ConfigUtilTest.java
View file @
ba135814
...
@@ -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