Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
ed3dd78f
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ed3dd78f
编写于
1月 25, 2017
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add constraint on bizconfig
上级
7f0fc9d4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
106 addition
and
9 deletion
+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
未找到文件。
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java
浏览文件 @
ed3dd78f
...
...
@@ -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
浏览文件 @
ed3dd78f
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
浏览文件 @
ed3dd78f
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录