Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
thythm
ribbon
提交
1b30bd7e
R
ribbon
项目概览
thythm
/
ribbon
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
ribbon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
1b30bd7e
编写于
5月 20, 2019
作者:
E
elandau
提交者:
GitHub
5月 20, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #421 from elandau/bugfix/overrides
config: Fix isLoaded not set in the correct order
上级
53566908
7084f65d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
14 deletion
+79
-14
ribbon-archaius/src/main/java/com/netflix/client/config/ArchaiusPropertyResolver.java
...a/com/netflix/client/config/ArchaiusPropertyResolver.java
+2
-3
ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java
...ava/com/netflix/client/config/ReloadableClientConfig.java
+24
-11
ribbon-core/src/test/java/com/netflix/client/config/ReloadableClientConfigTest.java
...com/netflix/client/config/ReloadableClientConfigTest.java
+53
-0
未找到文件。
ribbon-archaius/src/main/java/com/netflix/client/config/ArchaiusPropertyResolver.java
浏览文件 @
1b30bd7e
...
...
@@ -44,8 +44,6 @@ public class ArchaiusPropertyResolver implements PropertyResolver {
@Override
public
<
T
>
Optional
<
T
>
get
(
String
key
,
Class
<
T
>
type
)
{
LOG
.
debug
(
"Loading property {}"
,
key
);
if
(
Integer
.
class
.
equals
(
type
))
{
return
Optional
.
ofNullable
((
T
)
config
.
getInteger
(
key
,
null
));
}
else
if
(
Boolean
.
class
.
equals
(
type
))
{
...
...
@@ -70,7 +68,8 @@ public class ArchaiusPropertyResolver implements PropertyResolver {
.
orElseThrow
(()
->
new
IllegalArgumentException
(
"Unable to convert value to desired type "
+
type
));
}
});
}
}
}
}
@Override
public
void
forEach
(
String
prefix
,
BiConsumer
<
String
,
String
>
consumer
)
{
...
...
ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java
浏览文件 @
1b30bd7e
...
...
@@ -59,12 +59,24 @@ public abstract class ReloadableClientConfig implements IClientConfig {
private
boolean
isLoaded
=
false
;
/**
* @deprecated Use {@link #ReloadableClientConfig(PropertyResolver, String, String)}
*/
@Deprecated
protected
ReloadableClientConfig
(
PropertyResolver
resolver
)
{
this
.
clientName
=
DEFAULT_CLIENT_NAME
;
this
.
resolver
=
resolver
;
this
(
resolver
,
DEFAULT_CLIENT_NAME
);
}
/**
* @deprecated Use {@link #ReloadableClientConfig(PropertyResolver, String, String)}
*/
@Deprecated
protected
ReloadableClientConfig
(
PropertyResolver
resolver
,
String
clientName
)
{
this
(
resolver
,
DEFAULT_NAMESPACE
,
DEFAULT_CLIENT_NAME
);
}
protected
ReloadableClientConfig
(
PropertyResolver
resolver
,
String
namespace
,
String
clientName
)
{
this
.
namespace
=
namespace
;
this
.
clientName
=
clientName
;
this
.
resolver
=
resolver
;
}
...
...
@@ -106,14 +118,11 @@ public abstract class ReloadableClientConfig implements IClientConfig {
@Override
public
void
loadProperties
(
String
clientName
)
{
Preconditions
.
checkState
(
isLoaded
==
false
,
"Config '{}' can only be loaded once"
,
clientName
);
if
(!
isLoaded
)
{
loadDefaultValues
();
this
.
isLoaded
=
true
;
resolver
.
onChange
(
this
::
reload
);
}
Preconditions
.
checkState
(!
isLoaded
,
"Config '{}' can only be loaded once"
,
clientName
);
this
.
clientName
=
clientName
;
this
.
isLoaded
=
true
;
loadDefaultValues
();
resolver
.
onChange
(
this
::
reload
);
}
@Override
...
...
@@ -202,8 +211,6 @@ public abstract class ReloadableClientConfig implements IClientConfig {
}
private
<
T
>
ReloadableProperty
<
T
>
getClientDynamicProperty
(
IClientConfigKey
<
T
>
key
)
{
LOG
.
debug
(
"Get dynamic property key={} ns={} client={}"
,
key
.
key
(),
getNameSpace
(),
clientName
);
return
createProperty
(
()
->
resolveFinalProperty
(
key
),
key:
:
defaultValue
);
...
...
@@ -295,11 +302,15 @@ public abstract class ReloadableClientConfig implements IClientConfig {
@Override
public
final
<
T
>
Property
<
T
>
getDynamicProperty
(
IClientConfigKey
<
T
>
key
)
{
LOG
.
debug
(
"Get dynamic property key={} ns={} client={}"
,
key
.
key
(),
getNameSpace
(),
clientName
);
return
getClientDynamicProperty
(
key
);
}
@Override
public
<
T
>
Property
<
T
>
getScopedProperty
(
IClientConfigKey
<
T
>
key
)
{
LOG
.
debug
(
"Get dynamic property key={} ns={} client={}"
,
key
.
key
(),
getNameSpace
(),
clientName
);
return
(
Property
<
T
>)
dynamicProperties
.
computeIfAbsent
(
key
,
ignore
->
createProperty
(
()
->
resolverScopedProperty
(
key
),
key:
:
defaultValue
));
...
...
@@ -307,6 +318,8 @@ public abstract class ReloadableClientConfig implements IClientConfig {
@Override
public
<
T
>
Property
<
T
>
getPrefixMappedProperty
(
IClientConfigKey
<
T
>
key
)
{
LOG
.
debug
(
"Get dynamic property key={} ns={} client={}"
,
key
.
key
(),
getNameSpace
(),
clientName
);
return
(
Property
<
T
>)
dynamicProperties
.
computeIfAbsent
(
key
,
ignore
->
createProperty
(
getPrefixedMapPropertySupplier
(
key
),
key:
:
defaultValue
));
...
...
ribbon-core/src/test/java/com/netflix/client/config/ReloadableClientConfigTest.java
0 → 100644
浏览文件 @
1b30bd7e
package
com.netflix.client.config
;
import
com.netflix.config.ConfigurationManager
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.TestName
;
public
class
ReloadableClientConfigTest
{
@Rule
public
TestName
testName
=
new
TestName
();
private
CommonClientConfigKey
<
Integer
>
testKey
;
@Before
public
void
before
()
{
this
.
testKey
=
new
CommonClientConfigKey
<
Integer
>(
testName
.
getMethodName
(),
-
1
)
{};
}
@Test
public
void
testOverrideLoadedConfig
()
{
final
DefaultClientConfigImpl
overrideconfig
=
new
DefaultClientConfigImpl
();
overrideconfig
.
set
(
testKey
,
123
);
final
DefaultClientConfigImpl
config
=
new
DefaultClientConfigImpl
();
config
.
loadDefaultValues
();
config
.
applyOverride
(
overrideconfig
);
Assert
.
assertEquals
(
123
,
config
.
get
(
testKey
).
intValue
());
}
@Test
public
void
setBeforeLoading
()
{
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ribbon."
+
testKey
.
key
(),
"123"
);
final
DefaultClientConfigImpl
config
=
new
DefaultClientConfigImpl
();
config
.
loadProperties
(
"foo"
);
Assert
.
assertEquals
(
123
,
config
.
get
(
testKey
).
intValue
());
}
@Test
public
void
setAfterLoading
()
{
final
DefaultClientConfigImpl
config
=
new
DefaultClientConfigImpl
();
config
.
loadProperties
(
"foo"
);
config
.
set
(
testKey
,
456
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ribbon."
+
testKey
.
key
(),
"123"
);
Assert
.
assertEquals
(
123
,
config
.
get
(
testKey
).
intValue
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录