Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
thythm
ribbon
提交
9e553409
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,发现更多精彩内容 >>
提交
9e553409
编写于
2月 13, 2014
作者:
J
Jay Zarfoss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upgrade eureka client, copy instance info when doing port override, test changes
上级
426b6089
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
89 addition
and
16 deletion
+89
-16
build.gradle
build.gradle
+1
-1
ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/DiscoveryEnabledNIWSServerList.java
...lix/niws/loadbalancer/DiscoveryEnabledNIWSServerList.java
+7
-2
ribbon-eureka/src/test/java/com/netflix/niws/loadbalancer/DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java
...DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java
+81
-13
未找到文件。
build.gradle
浏览文件 @
9e553409
...
...
@@ -64,7 +64,7 @@ project(':ribbon-httpclient') {
project
(
':ribbon-eureka'
)
{
dependencies
{
compile
project
(
':ribbon-core'
)
compile
'com.netflix.eureka:eureka-client:1.1.1
07
'
compile
'com.netflix.eureka:eureka-client:1.1.1
26
'
}
}
...
...
ribbon-eureka/src/main/java/com/netflix/niws/loadbalancer/DiscoveryEnabledNIWSServerList.java
浏览文件 @
9e553409
...
...
@@ -127,10 +127,15 @@ public class DiscoveryEnabledNIWSServerList extends AbstractServerList<Discovery
logger
.
debug
(
"Overriding port on client name: "
+
clientName
+
" to "
+
overridePort
);
}
// copy is necessary since the InstanceInfo builder just uses the original reference,
// and we don't want to corrupt the global eureka copy of the object which may be
// used by other clients in our system
InstanceInfo
copy
=
new
InstanceInfo
(
ii
);
if
(
isSecure
){
ii
=
new
InstanceInfo
.
Builder
(
ii
).
setSecurePort
(
overridePort
).
build
();
ii
=
new
InstanceInfo
.
Builder
(
copy
).
setSecurePort
(
overridePort
).
build
();
}
else
{
ii
=
new
InstanceInfo
.
Builder
(
ii
).
setPort
(
overridePort
).
build
();
ii
=
new
InstanceInfo
.
Builder
(
copy
).
setPort
(
overridePort
).
build
();
}
}
...
...
ribbon-eureka/src/test/java/com/netflix/niws/loadbalancer/DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.java
浏览文件 @
9e553409
...
...
@@ -68,6 +68,10 @@ public class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest {
@Before
public
void
setupMock
(){
List
<
InstanceInfo
>
dummyII
=
getDummyInstanceInfo
(
"dummy"
,
"http://www.host.com"
,
8001
);
List
<
InstanceInfo
>
secureDummyII
=
getDummyInstanceInfo
(
"secureDummy"
,
"http://www.host.com"
,
8002
);
PowerMock
.
mockStatic
(
DiscoveryManager
.
class
);
PowerMock
.
mockStatic
(
DiscoveryClient
.
class
);
...
...
@@ -79,8 +83,8 @@ public class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest {
expect
(
mockedDiscoveryManager
.
getDiscoveryClient
()).
andReturn
(
mockedDiscoveryClient
).
anyTimes
();
expect
(
mockedDiscoveryClient
.
getInstancesByVipAddress
(
"dummy"
,
false
,
"region"
)).
andReturn
(
getDummyInstanceInfo
(
"dummy"
,
"http://www.host.com"
,
8001
)
).
anyTimes
();
expect
(
mockedDiscoveryClient
.
getInstancesByVipAddress
(
"secureDummy"
,
true
,
"region"
)).
andReturn
(
getDummyInstanceInfo
(
"secureDummy"
,
"http://www.host.com"
,
8002
)
).
anyTimes
();
expect
(
mockedDiscoveryClient
.
getInstancesByVipAddress
(
"dummy"
,
false
,
"region"
)).
andReturn
(
dummyII
).
anyTimes
();
expect
(
mockedDiscoveryClient
.
getInstancesByVipAddress
(
"secureDummy"
,
true
,
"region"
)).
andReturn
(
secureDummyII
).
anyTimes
();
replay
(
DiscoveryManager
.
class
);
replay
(
DiscoveryClient
.
class
);
...
...
@@ -183,8 +187,6 @@ public class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest {
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testSecureVipPortCanBeOverriden.ribbon.ForceClientPortConfiguration"
,
"true"
);
DiscoveryEnabledNIWSServerList
deList
=
new
DiscoveryEnabledNIWSServerList
();
DefaultClientConfigImpl
clientConfig
=
DefaultClientConfigImpl
.
class
.
newInstance
();
...
...
@@ -200,19 +202,85 @@ public class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest {
}
protected
static
List
<
InstanceInfo
>
getDummyInstanceInfo
(
String
appName
,
String
host
,
int
port
){
/**
* Tests case where two different clients want to use the same instance, one with overriden ports and one without
*
* @throws Exception for anything unexpected
*/
@Test
public
void
testTwoInstancesDontStepOnEachOther
()
throws
Exception
{
// setup override client
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.DeploymentContextBasedVipAddresses"
,
"dummy"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.IsSecure"
,
"false"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.Port"
,
"6001"
);
// override from 8001
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.TargetRegion"
,
"region"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.NIWSServerListClassName"
,
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.ForceClientPortConfiguration"
,
"true"
);
// setup non override client
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.DeploymentContextBasedVipAddresses"
,
"dummy"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.IsSecure"
,
"false"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.Port"
,
"6001"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.TargetRegion"
,
"region"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.NIWSServerListClassName"
,
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.ForceClientPortConfiguration"
,
"false"
);
// check override client
DiscoveryEnabledNIWSServerList
deList1
=
new
DiscoveryEnabledNIWSServerList
();
DefaultClientConfigImpl
clientConfig1
=
DefaultClientConfigImpl
.
class
.
newInstance
();
clientConfig1
.
loadProperties
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1"
);
deList1
.
initWithNiwsConfig
(
clientConfig1
);
List
<
DiscoveryEnabledServer
>
serverList1
=
deList1
.
getInitialListOfServers
();
Assert
.
assertEquals
(
1
,
serverList1
.
size
());
Assert
.
assertEquals
(
6001
,
serverList1
.
get
(
0
).
getPort
());
// client property overridden
Assert
.
assertEquals
(
6001
,
serverList1
.
get
(
0
).
getInstanceInfo
().
getPort
());
// client property overridden
Assert
.
assertEquals
(
7002
,
serverList1
.
get
(
0
).
getInstanceInfo
().
getSecurePort
());
// 7002 is the secure default
List
<
InstanceInfo
>
list
=
new
ArrayList
<
InstanceInfo
>();
// check non-override client
InstanceInfo
info
=
InstanceInfo
.
Builder
.
newBuilder
().
setAppName
(
appName
)
.
setHostName
(
host
)
.
setPort
(
port
)
.
build
();
DiscoveryEnabledNIWSServerList
deList2
=
new
DiscoveryEnabledNIWSServerList
();
list
.
add
(
info
);
DefaultClientConfigImpl
clientConfig2
=
DefaultClientConfigImpl
.
class
.
newInstance
();
clientConfig2
.
loadProperties
(
"DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2"
);
deList2
.
initWithNiwsConfig
(
clientConfig2
);
return
list
;
List
<
DiscoveryEnabledServer
>
serverList2
=
deList2
.
getInitialListOfServers
()
;
}
Assert
.
assertEquals
(
1
,
serverList2
.
size
());
Assert
.
assertEquals
(
8001
,
serverList2
.
get
(
0
).
getPort
());
// client property indicated in ii
Assert
.
assertEquals
(
8001
,
serverList2
.
get
(
0
).
getInstanceInfo
().
getPort
());
// client property indicated in ii
Assert
.
assertEquals
(
7002
,
serverList2
.
get
(
0
).
getInstanceInfo
().
getSecurePort
());
// 7002 is the secure default
}
protected
static
List
<
InstanceInfo
>
getDummyInstanceInfo
(
String
appName
,
String
host
,
int
port
){
List
<
InstanceInfo
>
list
=
new
ArrayList
<
InstanceInfo
>();
InstanceInfo
info
=
InstanceInfo
.
Builder
.
newBuilder
().
setAppName
(
appName
)
.
setHostName
(
host
)
.
setPort
(
port
)
.
build
();
list
.
add
(
info
);
return
list
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录