Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
incubator-dubbo-admin
提交
a762a0f6
I
incubator-dubbo-admin
项目概览
爱吃血肠
/
incubator-dubbo-admin
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
incubator-dubbo-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a762a0f6
编写于
1月 22, 2019
作者:
K
kezhenxu94
提交者:
min
1月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more integration tests (#267)
* add more integration tests * fix ci failure
上级
09064b74
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
286 addition
and
9 deletion
+286
-9
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ConditionRoutesControllerTest.java
...dubbo/admin/controller/ConditionRoutesControllerTest.java
+274
-0
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ManagementControllerTest.java
...ache/dubbo/admin/controller/ManagementControllerTest.java
+3
-1
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ServiceControllerTest.java
.../apache/dubbo/admin/controller/ServiceControllerTest.java
+9
-8
未找到文件。
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ConditionRoutesControllerTest.java
0 → 100644
浏览文件 @
a762a0f6
package
org.apache.dubbo.admin.controller
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
import
org.apache.dubbo.admin.AbstractSpringIntegrationTest
;
import
org.apache.dubbo.admin.common.util.YamlParser
;
import
org.apache.dubbo.admin.model.dto.ConditionRouteDTO
;
import
org.apache.dubbo.admin.model.store.RoutingRule
;
import
org.apache.dubbo.admin.service.ProviderService
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.core.ParameterizedTypeReference
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
static
org
.
hamcrest
.
Matchers
.
containsInAnyOrder
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
ConditionRoutesControllerTest
extends
AbstractSpringIntegrationTest
{
private
final
String
env
=
"whatever"
;
@MockBean
private
ProviderService
providerService
;
@After
public
void
tearDown
()
throws
Exception
{
if
(
zkClient
.
checkExists
().
forPath
(
"/dubbo"
)
!=
null
)
{
zkClient
.
delete
().
deletingChildrenIfNeeded
().
forPath
(
"/dubbo"
);
}
}
@Test
public
void
shouldThrowWhenParamInvalid
()
{
String
uuid
=
UUID
.
randomUUID
().
toString
();
ConditionRouteDTO
dto
=
new
ConditionRouteDTO
();
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
postForEntity
(
url
(
"/api/{env}/rules/route/condition"
),
dto
,
String
.
class
,
env
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
BAD_REQUEST
));
assertThat
(
responseEntity
.
getBody
(),
containsString
(
"serviceName and app is Empty!"
));
dto
.
setApplication
(
"application"
+
uuid
);
when
(
providerService
.
findVersionInApplication
(
dto
.
getApplication
())).
thenReturn
(
"2.6"
);
responseEntity
=
restTemplate
.
postForEntity
(
url
(
"/api/{env}/rules/route/condition"
),
dto
,
String
.
class
,
env
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
INTERNAL_SERVER_ERROR
));
assertThat
(
responseEntity
.
getBody
(),
containsString
(
"dubbo 2.6 does not support application scope routing rule"
));
}
@Test
public
void
shouldCreateRule
()
{
String
uuid
=
UUID
.
randomUUID
().
toString
();
String
application
=
"application"
+
uuid
;
String
service
=
"service"
+
uuid
;
List
<
String
>
conditions
=
Collections
.
singletonList
(
"=> host != 172.22.3.91"
);
ConditionRouteDTO
dto
=
new
ConditionRouteDTO
();
dto
.
setService
(
service
);
dto
.
setConditions
(
conditions
);
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
postForEntity
(
url
(
"/api/{env}/rules/route/condition"
),
dto
,
String
.
class
,
env
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
CREATED
));
dto
.
setApplication
(
application
);
when
(
providerService
.
findVersionInApplication
(
dto
.
getApplication
())).
thenReturn
(
"2.7"
);
responseEntity
=
restTemplate
.
postForEntity
(
url
(
"/api/{env}/rules/route/condition"
),
dto
,
String
.
class
,
env
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
CREATED
));
}
@Test
public
void
shouldUpdateRule
()
throws
Exception
{
String
service
=
"org.apache.dubbo.demo.DemoService"
;
String
content
=
"conditions:\n"
+
"- => host != 172.22.3.111\n"
+
"- => host != 172.22.3.112\n"
+
"enabled: true\n"
+
"force: true\n"
+
"key: "
+
service
+
"\n"
+
"priority: 0\n"
+
"runtime: false\n"
+
"scope: service"
;
String
path
=
"/dubbo/config/"
+
service
+
"/condition-router"
;
zkClient
.
create
().
creatingParentContainersIfNeeded
().
forPath
(
path
);
zkClient
.
setData
().
forPath
(
path
,
content
.
getBytes
());
List
<
String
>
newConditions
=
Arrays
.
asList
(
"=> host != 172.22.3.211"
,
"=> host != 172.22.3.212"
);
ConditionRouteDTO
dto
=
new
ConditionRouteDTO
();
dto
.
setConditions
(
newConditions
);
dto
.
setService
(
service
);
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
(
"/api/{env}/rules/route/condition/{service}"
),
HttpMethod
.
PUT
,
new
HttpEntity
<>(
dto
,
null
),
String
.
class
,
env
,
service
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
OK
));
byte
[]
bytes
=
zkClient
.
getData
().
forPath
(
path
);
String
updatedConfig
=
new
String
(
bytes
);
RoutingRule
rule
=
YamlParser
.
loadObject
(
updatedConfig
,
RoutingRule
.
class
);
assertThat
(
rule
.
getConditions
(),
containsInAnyOrder
(
newConditions
.
toArray
()));
}
@Test
public
void
shouldGetServiceRule
()
throws
Exception
{
String
service
=
"org.apache.dubbo.demo.DemoService"
;
String
content
=
"conditions:\n"
+
"- => host != 172.22.3.111\n"
+
"- => host != 172.22.3.112\n"
+
"enabled: true\n"
+
"force: true\n"
+
"key: "
+
service
+
"\n"
+
"priority: 0\n"
+
"runtime: false\n"
+
"scope: service"
;
String
path
=
"/dubbo/config/"
+
service
+
"/condition-router"
;
zkClient
.
create
().
creatingParentContainersIfNeeded
().
forPath
(
path
);
zkClient
.
setData
().
forPath
(
path
,
content
.
getBytes
());
ResponseEntity
<
List
<
ConditionRouteDTO
>>
responseEntity
=
restTemplate
.
exchange
(
url
(
"/api/{env}/rules/route/condition/?service={service}"
),
HttpMethod
.
GET
,
null
,
new
ParameterizedTypeReference
<
List
<
ConditionRouteDTO
>>()
{
},
env
,
service
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
OK
));
assertThat
(
responseEntity
.
getBody
(),
hasSize
(
1
));
List
<
String
>
conditions
=
responseEntity
.
getBody
()
.
stream
()
.
flatMap
(
it
->
it
.
getConditions
().
stream
())
.
collect
(
Collectors
.
toList
());
assertThat
(
conditions
,
hasSize
(
2
));
assertThat
(
conditions
,
containsInAnyOrder
(
"=> host != 172.22.3.111"
,
"=> host != 172.22.3.112"
));
}
@Test
public
void
shouldDeleteRule
()
throws
Exception
{
String
service
=
"org.apache.dubbo.demo.DemoService"
;
String
content
=
"conditions:\n"
+
"- => host != 172.22.3.111\n"
+
"- => host != 172.22.3.112\n"
+
"enabled: true\n"
+
"force: true\n"
+
"key: "
+
service
+
"\n"
+
"priority: 0\n"
+
"runtime: false\n"
+
"scope: service"
;
String
path
=
"/dubbo/config/"
+
service
+
"/condition-router"
;
zkClient
.
create
().
creatingParentContainersIfNeeded
().
forPath
(
path
);
zkClient
.
setData
().
forPath
(
path
,
content
.
getBytes
());
assertNotNull
(
"zk path should not be null before deleting"
,
zkClient
.
checkExists
().
forPath
(
path
));
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
(
"/api/{env}/rules/route/condition/{service}"
),
HttpMethod
.
DELETE
,
null
,
String
.
class
,
env
,
service
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
OK
));
assertNull
(
zkClient
.
checkExists
().
forPath
(
path
));
}
@Test
public
void
shouldThrowWhenDetailRouteWithUnknownId
()
{
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
getForEntity
(
url
(
"/api/{env}/rules/route/condition/{id}"
),
String
.
class
,
env
,
"non-existed-service"
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
NOT_FOUND
));
}
@Test
public
void
shouldGetRouteDetail
()
throws
Exception
{
String
service
=
"org.apache.dubbo.demo.DemoService"
;
String
content
=
"conditions:\n"
+
"- => host != 172.22.3.111\n"
+
"- => host != 172.22.3.112\n"
+
"enabled: true\n"
+
"force: true\n"
+
"key: "
+
service
+
"\n"
+
"priority: 0\n"
+
"runtime: false\n"
+
"scope: service"
;
String
path
=
"/dubbo/config/"
+
service
+
"/condition-router"
;
zkClient
.
create
().
creatingParentContainersIfNeeded
().
forPath
(
path
);
zkClient
.
setData
().
forPath
(
path
,
content
.
getBytes
());
ResponseEntity
<
ConditionRouteDTO
>
responseEntity
=
restTemplate
.
getForEntity
(
url
(
"/api/{env}/rules/route/condition/{id}"
),
ConditionRouteDTO
.
class
,
env
,
service
);
assertThat
(
responseEntity
.
getStatusCode
(),
is
(
HttpStatus
.
OK
));
ConditionRouteDTO
conditionRouteDTO
=
responseEntity
.
getBody
();
assertNotNull
(
conditionRouteDTO
);
assertThat
(
conditionRouteDTO
.
getConditions
(),
hasSize
(
2
));
assertThat
(
conditionRouteDTO
.
getConditions
(),
containsInAnyOrder
(
"=> host != 172.22.3.111"
,
"=> host != 172.22.3.112"
));
}
@Test
public
void
shouldEnableRoute
()
throws
Exception
{
String
service
=
"org.apache.dubbo.demo.DemoService"
;
String
content
=
"conditions:\n"
+
"- => host != 172.22.3.111\n"
+
"- => host != 172.22.3.112\n"
+
"enabled: false\n"
+
"force: true\n"
+
"key: "
+
service
+
"\n"
+
"priority: 0\n"
+
"runtime: false\n"
+
"scope: service"
;
String
path
=
"/dubbo/config/"
+
service
+
"/condition-router"
;
zkClient
.
create
().
creatingParentContainersIfNeeded
().
forPath
(
path
);
zkClient
.
setData
().
forPath
(
path
,
content
.
getBytes
());
byte
[]
bytes
=
zkClient
.
getData
().
forPath
(
path
);
String
updatedConfig
=
new
String
(
bytes
);
RoutingRule
rule
=
YamlParser
.
loadObject
(
updatedConfig
,
RoutingRule
.
class
);
assertFalse
(
rule
.
isEnabled
());
restTemplate
.
put
(
url
(
"/api/{env}/rules/route/condition/enable/{id}"
),
null
,
env
,
service
);
bytes
=
zkClient
.
getData
().
forPath
(
path
);
updatedConfig
=
new
String
(
bytes
);
rule
=
YamlParser
.
loadObject
(
updatedConfig
,
RoutingRule
.
class
);
assertTrue
(
rule
.
isEnabled
());
}
@Test
public
void
shouldDisableRoute
()
throws
Exception
{
String
service
=
"org.apache.dubbo.demo.DemoService"
;
String
content
=
"conditions:\n"
+
"- => host != 172.22.3.111\n"
+
"- => host != 172.22.3.112\n"
+
"enabled: true\n"
+
"force: false\n"
+
"key: "
+
service
+
"\n"
+
"priority: 0\n"
+
"runtime: false\n"
+
"scope: service"
;
String
path
=
"/dubbo/config/"
+
service
+
"/condition-router"
;
zkClient
.
create
().
creatingParentContainersIfNeeded
().
forPath
(
path
);
zkClient
.
setData
().
forPath
(
path
,
content
.
getBytes
());
byte
[]
bytes
=
zkClient
.
getData
().
forPath
(
path
);
String
updatedConfig
=
new
String
(
bytes
);
RoutingRule
rule
=
YamlParser
.
loadObject
(
updatedConfig
,
RoutingRule
.
class
);
assertTrue
(
rule
.
isEnabled
());
restTemplate
.
put
(
url
(
"/api/{env}/rules/route/condition/disable/{id}"
),
null
,
env
,
service
);
bytes
=
zkClient
.
getData
().
forPath
(
path
);
updatedConfig
=
new
String
(
bytes
);
rule
=
YamlParser
.
loadObject
(
updatedConfig
,
RoutingRule
.
class
);
assertFalse
(
rule
.
isEnabled
());
}
}
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ManagementControllerTest.java
浏览文件 @
a762a0f6
...
...
@@ -17,6 +17,7 @@
package
org.apache.dubbo.admin.controller
;
import
java.util.UUID
;
import
org.apache.dubbo.admin.AbstractSpringIntegrationTest
;
import
org.apache.dubbo.admin.common.util.Constants
;
import
org.apache.dubbo.admin.model.dto.ConfigDTO
;
...
...
@@ -64,7 +65,8 @@ public class ManagementControllerTest extends AbstractSpringIntegrationTest {
@Test
public
void
shouldCreateApplicationConfig
()
throws
Exception
{
String
application
=
"dubbo-admin"
;
String
uuid
=
UUID
.
randomUUID
().
toString
();
String
application
=
"dubbo-admin"
+
uuid
;
ConfigDTO
configDTO
=
new
ConfigDTO
();
configDTO
.
setKey
(
application
);
configDTO
.
setConfig
(
"key1=val1\nkey2=val2"
);
...
...
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/controller/ServiceControllerTest.java
浏览文件 @
a762a0f6
...
...
@@ -17,23 +17,21 @@
package
org.apache.dubbo.admin.controller
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.dubbo.admin.AbstractSpringIntegrationTest
;
import
org.apache.dubbo.admin.common.util.Constants
;
import
org.apache.dubbo.admin.model.dto.ServiceDTO
;
import
org.apache.dubbo.common.URL
;
import
org.apache.dubbo.registry.Registry
;
import
org.apache.dubbo.registry.support.AbstractRegistry
;
import
org.junit.
Before
;
import
org.junit.
After
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.ParameterizedTypeReference
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
...
...
@@ -42,11 +40,14 @@ public class ServiceControllerTest extends AbstractSpringIntegrationTest {
@Autowired
private
Registry
registry
;
@
Before
public
void
setUp
()
throws
Exception
{
@
After
public
void
tearDown
()
throws
Exception
{
final
Set
<
URL
>
registered
=
((
AbstractRegistry
)
registry
).
getRegistered
();
for
(
final
URL
url
:
registered
)
{
registry
.
unregister
(
url
);
try
{
registry
.
unregister
(
url
);
}
catch
(
Exception
ignored
)
{
}
}
TimeUnit
.
SECONDS
.
sleep
(
1
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录