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
4e129e70
Commit
4e129e70
authored
Jan 25, 2017
by
张乐
Committed by
GitHub
Jan 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #532 from nobodyiam/fix
add constraint on bizconfig
parents
7f0fc9d4
ed3dd78f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
9 deletions
+106
-9
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java
...java/com/ctrip/framework/apollo/biz/config/BizConfig.java
+23
-8
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AllTests.java
...rc/test/java/com/ctrip/framework/apollo/biz/AllTests.java
+3
-1
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java
.../com/ctrip/framework/apollo/biz/config/BizConfigTest.java
+80
-0
No files found.
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java
View file @
4e129e70
...
...
@@ -44,15 +44,18 @@ public class BizConfig extends RefreshableConfig {
}
public
int
grayReleaseRuleScanInterval
()
{
return
getIntProperty
(
"apollo.gray-release-rule-scan.interval"
,
60
);
int
interval
=
getIntProperty
(
"apollo.gray-release-rule-scan.interval"
,
60
);
return
checkInt
(
interval
,
1
,
Integer
.
MAX_VALUE
,
60
);
}
public
int
itemKeyLengthLimit
()
{
return
getIntProperty
(
"item.key.length.limit"
,
128
);
int
limit
=
getIntProperty
(
"item.key.length.limit"
,
128
);
return
checkInt
(
limit
,
5
,
Integer
.
MAX_VALUE
,
128
);
}
public
int
itemValueLengthLimit
()
{
return
getIntProperty
(
"item.value.length.limit"
,
20000
);
int
limit
=
getIntProperty
(
"item.value.length.limit"
,
20000
);
return
checkInt
(
limit
,
5
,
Integer
.
MAX_VALUE
,
20000
);
}
public
Map
<
Long
,
Integer
>
namespaceValueLengthLimitOverride
()
{
...
...
@@ -82,7 +85,8 @@ public class BizConfig extends RefreshableConfig {
}
public
int
appNamespaceCacheScanInterval
()
{
return
getIntProperty
(
"apollo.app-namespace-cache-scan.interval"
,
1
);
int
interval
=
getIntProperty
(
"apollo.app-namespace-cache-scan.interval"
,
1
);
return
checkInt
(
interval
,
1
,
Integer
.
MAX_VALUE
,
1
);
}
public
TimeUnit
appNamespaceCacheScanIntervalTimeUnit
()
{
...
...
@@ -90,7 +94,8 @@ public class BizConfig extends RefreshableConfig {
}
public
int
appNamespaceCacheRebuildInterval
()
{
return
getIntProperty
(
"apollo.app-namespace-cache-rebuild.interval"
,
60
);
int
interval
=
getIntProperty
(
"apollo.app-namespace-cache-rebuild.interval"
,
60
);
return
checkInt
(
interval
,
1
,
Integer
.
MAX_VALUE
,
60
);
}
public
TimeUnit
appNamespaceCacheRebuildIntervalTimeUnit
()
{
...
...
@@ -98,7 +103,8 @@ public class BizConfig extends RefreshableConfig {
}
public
int
releaseMessageCacheScanInterval
()
{
return
getIntProperty
(
"apollo.release-message-cache-scan.interval"
,
1
);
int
interval
=
getIntProperty
(
"apollo.release-message-cache-scan.interval"
,
1
);
return
checkInt
(
interval
,
1
,
Integer
.
MAX_VALUE
,
1
);
}
public
TimeUnit
releaseMessageCacheScanIntervalTimeUnit
()
{
...
...
@@ -106,10 +112,19 @@ public class BizConfig extends RefreshableConfig {
}
public
int
releaseMessageNotificationBatch
()
{
return
getIntProperty
(
"apollo.release-message.notification.batch"
,
100
);
int
batch
=
getIntProperty
(
"apollo.release-message.notification.batch"
,
100
);
return
checkInt
(
batch
,
1
,
Integer
.
MAX_VALUE
,
100
);
}
public
int
releaseMessageNotificationBatchIntervalInMilli
()
{
return
getIntProperty
(
"apollo.release-message.notification.batch.interval"
,
100
);
int
interval
=
getIntProperty
(
"apollo.release-message.notification.batch.interval"
,
100
);
return
checkInt
(
interval
,
1
,
Integer
.
MAX_VALUE
,
100
);
}
int
checkInt
(
int
value
,
int
min
,
int
max
,
int
defaultValue
)
{
if
(
value
>=
min
&&
value
<=
max
)
{
return
value
;
}
return
defaultValue
;
}
}
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/AllTests.java
View file @
4e129e70
package
com
.
ctrip
.
framework
.
apollo
.
biz
;
import
com.ctrip.framework.apollo.biz.config.BizConfigTest
;
import
com.ctrip.framework.apollo.biz.grayReleaseRule.GrayReleaseRulesHolderTest
;
import
com.ctrip.framework.apollo.biz.message.DatabaseMessageSenderTest
;
import
com.ctrip.framework.apollo.biz.message.ReleaseMessageScannerTest
;
...
...
@@ -38,7 +39,8 @@ import org.junit.runners.Suite.SuiteClasses;
NamespaceBranchServiceTest
.
class
,
ReleaseCreationTest
.
class
,
NamespacePublishInfoTest
.
class
,
NamespaceServiceTest
.
class
NamespaceServiceTest
.
class
,
BizConfigTest
.
class
})
public
class
AllTests
{
...
...
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java
0 → 100644
View file @
4e129e70
package
com
.
ctrip
.
framework
.
apollo
.
biz
.
config
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
BizConfigTest
{
@Mock
private
ConfigurableEnvironment
environment
;
private
BizConfig
bizConfig
;
@Before
public
void
setUp
()
throws
Exception
{
bizConfig
=
new
BizConfig
();
ReflectionTestUtils
.
setField
(
bizConfig
,
"environment"
,
environment
);
}
@Test
public
void
testReleaseMessageNotificationBatch
()
throws
Exception
{
int
someBatch
=
20
;
when
(
environment
.
getProperty
(
"apollo.release-message.notification.batch"
)).
thenReturn
(
String
.
valueOf
(
someBatch
));
assertEquals
(
someBatch
,
bizConfig
.
releaseMessageNotificationBatch
());
}
@Test
public
void
testReleaseMessageNotificationBatchWithDefaultValue
()
throws
Exception
{
int
defaultBatch
=
100
;
assertEquals
(
defaultBatch
,
bizConfig
.
releaseMessageNotificationBatch
());
}
@Test
public
void
testReleaseMessageNotificationBatchWithInvalidNumber
()
throws
Exception
{
int
someBatch
=
-
20
;
int
defaultBatch
=
100
;
when
(
environment
.
getProperty
(
"apollo.release-message.notification.batch"
)).
thenReturn
(
String
.
valueOf
(
someBatch
));
assertEquals
(
defaultBatch
,
bizConfig
.
releaseMessageNotificationBatch
());
}
@Test
public
void
testReleaseMessageNotificationBatchWithNAN
()
throws
Exception
{
String
someNAN
=
"someNAN"
;
int
defaultBatch
=
100
;
when
(
environment
.
getProperty
(
"apollo.release-message.notification.batch"
)).
thenReturn
(
someNAN
);
assertEquals
(
defaultBatch
,
bizConfig
.
releaseMessageNotificationBatch
());
}
@Test
public
void
testCheckInt
()
throws
Exception
{
int
someInvalidValue
=
1
;
int
anotherInvalidValue
=
2
;
int
someValidValue
=
3
;
int
someDefaultValue
=
10
;
int
someMin
=
someInvalidValue
+
1
;
int
someMax
=
anotherInvalidValue
-
1
;
assertEquals
(
someDefaultValue
,
bizConfig
.
checkInt
(
someInvalidValue
,
someMin
,
Integer
.
MAX_VALUE
,
someDefaultValue
));
assertEquals
(
someDefaultValue
,
bizConfig
.
checkInt
(
anotherInvalidValue
,
Integer
.
MIN_VALUE
,
someMax
,
someDefaultValue
));
assertEquals
(
someValidValue
,
bizConfig
.
checkInt
(
someValidValue
,
Integer
.
MIN_VALUE
,
Integer
.
MAX_VALUE
,
someDefaultValue
));
}
}
\ No newline at end of file
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