Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
thythm
ribbon
提交
dac19329
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,发现更多精彩内容 >>
提交
dac19329
编写于
2月 13, 2014
作者:
A
allenxwang
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #75 from zarfide/master
remove forceclientporttest
上级
2807d9f0
a50d935f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
171 deletion
+0
-171
build.gradle
build.gradle
+0
-1
ribbon-httpclient/src/test/java/com/netflix/niws/client/http/ForceClientPortTest.java
...ava/com/netflix/niws/client/http/ForceClientPortTest.java
+0
-170
未找到文件。
build.gradle
浏览文件 @
dac19329
...
...
@@ -57,7 +57,6 @@ project(':ribbon-httpclient') {
testCompile
'commons-io:commons-io:2.0.1'
testCompile
'com.sun.jersey:jersey-server:1.11'
testCompile
'com.google.mockwebserver:mockwebserver:20130505'
testCompile
project
(
':ribbon-eureka'
)
}
}
...
...
ribbon-httpclient/src/test/java/com/netflix/niws/client/http/ForceClientPortTest.java
已删除
100644 → 0
浏览文件 @
2807d9f0
/*
*
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
com.netflix.niws.client.http
;
import
com.netflix.appinfo.AmazonInfo
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.client.ClientFactory
;
import
com.netflix.client.http.HttpRequest
;
import
com.netflix.client.http.HttpResponse
;
import
com.netflix.config.ConfigurationManager
;
import
com.netflix.discovery.DiscoveryClient
;
import
com.netflix.discovery.DiscoveryManager
;
import
com.netflix.loadbalancer.DynamicServerListLoadBalancer
;
import
com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
;
import
org.easymock.EasyMock
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.powermock.api.easymock.PowerMock
;
import
org.powermock.core.classloader.annotations.PowerMockIgnore
;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
easymock
.
EasyMock
.
expect
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
powermock
.
api
.
easymock
.
PowerMock
.
createMock
;
import
static
org
.
powermock
.
api
.
easymock
.
PowerMock
.
replay
;
import
static
org
.
powermock
.
api
.
easymock
.
PowerMock
.
verify
;
/**
*
* This is essentially a 'live' test variant of {@link com.netflix.niws.loadbalancer.DiscoveryEnabledLoadBalancerSupportsPortOverrideTest}
* with all of the plumbing working together.
*
* Created by jzarfoss on 1/7/14.
*/
@RunWith
(
PowerMockRunner
.
class
)
@PrepareForTest
(
{
DiscoveryManager
.
class
,
DiscoveryClient
.
class
}
)
@PowerMockIgnore
({
"javax.management.*"
,
"org.apache.http.conn.ssl.*"
})
public
class
ForceClientPortTest
{
@Before
public
void
setupMock
(){
PowerMock
.
mockStatic
(
DiscoveryManager
.
class
);
PowerMock
.
mockStatic
(
DiscoveryClient
.
class
);
DiscoveryClient
mockedDiscoveryClient
=
createMock
(
DiscoveryClient
.
class
);
DiscoveryManager
mockedDiscoveryManager
=
createMock
(
DiscoveryManager
.
class
);
expect
(
DiscoveryClient
.
getZone
((
InstanceInfo
)
EasyMock
.
anyObject
())).
andReturn
(
"dummyZone"
).
anyTimes
();
expect
(
DiscoveryManager
.
getInstance
()).
andReturn
(
mockedDiscoveryManager
).
anyTimes
();
expect
(
mockedDiscoveryManager
.
getDiscoveryClient
()).
andReturn
(
mockedDiscoveryClient
).
anyTimes
();
// I'm only testing non-secure ports here, since the ssl libraries are full of static libraries and they were
// giving me some headaches with all of the mocks
expect
(
mockedDiscoveryClient
.
getInstancesByVipAddress
(
"google"
,
false
,
"region"
)).
andReturn
(
getDummyGoogleInstanceInfo
(
"google"
,
80
)).
anyTimes
();
expect
(
mockedDiscoveryClient
.
getInstancesByVipAddress
(
"badGoogle"
,
false
,
"region"
)).
andReturn
(
getDummyGoogleInstanceInfo
(
"badGoogle"
,
81
)).
anyTimes
();
replay
(
DiscoveryManager
.
class
);
replay
(
DiscoveryClient
.
class
);
replay
(
mockedDiscoveryManager
);
replay
(
mockedDiscoveryClient
);
}
@After
public
void
afterMock
(){
verify
(
DiscoveryManager
.
class
);
verify
(
DiscoveryClient
.
class
);
}
@Test
(
expected
=
com
.
netflix
.
client
.
ClientException
.
class
)
public
void
negativeTest
()
throws
Exception
{
// establish that actually using port 81 doesn't work
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.negativeTest.ribbon.DeploymentContextBasedVipAddresses"
,
"badGoogle"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.negativeTest.ribbon.TargetRegion"
,
"region"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.negativeTest.ribbon.NFLoadBalancerClassName"
,
DynamicServerListLoadBalancer
.
class
.
getName
());
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.negativeTest.ribbon.NIWSServerListClassName"
,
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
RestClient
client
=
(
RestClient
)
ClientFactory
.
getNamedClient
(
"ForceClientPortTest.negativeTest"
);
HttpRequest
request
=
HttpRequest
.
newBuilder
().
uri
(
new
URI
(
"/"
)).
build
();
client
.
executeWithLoadBalancer
(
request
);
}
@Test
public
void
testDefaultHonorsServerPortDefinition
()
throws
Exception
{
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testDefaultHonorsServerPortDefinition.ribbon.DeploymentContextBasedVipAddresses"
,
"google"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testDefaultHonorsServerPortDefinition.ribbon.TargetRegion"
,
"region"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testDefaultHonorsServerPortDefinition.ribbon.IsSecure"
,
"false"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testDefaultHonorsServerPortDefinition.ribbon.Port"
,
"81"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testDefaultHonorsServerPortDefinition.ribbon.NIWSServerListClassName"
,
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
RestClient
client
=
(
RestClient
)
ClientFactory
.
getNamedClient
(
"ForceClientPortTest.testDefaultHonorsServerPortDefinition"
);
HttpRequest
request
=
HttpRequest
.
newBuilder
().
uri
(
new
URI
(
"/"
)).
build
();
HttpResponse
response
=
client
.
executeWithLoadBalancer
(
request
);
assertEquals
(
200
,
response
.
getStatus
());
}
@Test
public
void
testOverrideForcesClientPort
()
throws
Exception
{
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testOverrideForcesClientPort.ribbon.DeploymentContextBasedVipAddresses"
,
"badGoogle"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testOverrideForcesClientPort.ribbon.TargetRegion"
,
"region"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testOverrideForcesClientPort.ribbon.IsSecure"
,
"false"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testOverrideForcesClientPort.ribbon.Port"
,
"80"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testOverrideForcesClientPort.ribbon.ForceClientPortConfiguration"
,
"true"
);
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"ForceClientPortTest.testOverrideForcesClientPort.ribbon.NIWSServerListClassName"
,
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
RestClient
client
=
(
RestClient
)
ClientFactory
.
getNamedClient
(
"ForceClientPortTest.testOverrideForcesClientPort"
);
HttpRequest
request
=
HttpRequest
.
newBuilder
().
uri
(
new
URI
(
"/"
)).
build
();
HttpResponse
response
=
client
.
executeWithLoadBalancer
(
request
);
assertEquals
(
200
,
response
.
getStatus
());
}
protected
static
List
<
InstanceInfo
>
getDummyGoogleInstanceInfo
(
String
appName
,
int
port
){
List
<
InstanceInfo
>
list
=
new
ArrayList
<
InstanceInfo
>();
InstanceInfo
info
=
InstanceInfo
.
Builder
.
newBuilder
().
setAppName
(
appName
)
.
setHostName
(
"www.google.com"
)
.
setPort
(
port
)
.
setDataCenterInfo
(
AmazonInfo
.
Builder
.
newBuilder
().
build
())
.
build
();
list
.
add
(
info
);
return
list
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录