Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
淡淡忧伤的程序员
DolphinScheduler
提交
768b5d9d
DolphinScheduler
项目概览
淡淡忧伤的程序员
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
48
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
768b5d9d
编写于
2月 12, 2020
作者:
Y
Yelli
提交者:
GitHub
2月 12, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add state null check (#1939)
add process definition UT
上级
e35e8be2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
159 addition
and
8 deletion
+159
-8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
...olphinscheduler/api/service/ProcessDefinitionService.java
+7
-0
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
...inscheduler/api/service/ProcessDefinitionServiceTest.java
+152
-8
未找到文件。
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
浏览文件 @
768b5d9d
...
...
@@ -442,6 +442,13 @@ public class ProcessDefinitionService extends BaseDAGService {
}
ReleaseState
state
=
ReleaseState
.
getEnum
(
releaseState
);
// check state
if
(
null
==
state
)
{
putMsg
(
result
,
Status
.
REQUEST_PARAMS_NOT_VALID_ERROR
,
"releaseState"
);
return
result
;
}
ProcessDefinition
processDefinition
=
processDefineMapper
.
selectById
(
id
);
switch
(
state
)
{
...
...
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
浏览文件 @
768b5d9d
...
...
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.service;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
org.apache.dolphinscheduler.api.ApiApplicationServer
;
import
org.apache.dolphinscheduler.api.dto.ProcessMeta
;
import
org.apache.dolphinscheduler.api.enums.Status
;
...
...
@@ -99,7 +100,7 @@ public class ProcessDefinitionServiceTest {
"\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"
;
@Test
public
void
queryProccessDefinitionList
()
throws
Exception
{
public
void
testQueryProccessDefinitionList
()
{
String
projectName
=
"project_test1"
;
Mockito
.
when
(
projectMapper
.
queryByName
(
projectName
)).
thenReturn
(
getProject
(
projectName
));
...
...
@@ -111,15 +112,23 @@ public class ProcessDefinitionServiceTest {
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
5
);
putMsg
(
result
,
Status
.
PROJECT_NOT_FOUNT
,
projectName
);
//project not found
Mockito
.
when
(
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectName
)).
thenReturn
(
result
);
Map
<
String
,
Object
>
map
=
processDefinitionService
.
queryProccessDefinitionList
(
loginUser
,
"project_test1"
);
Assert
.
assertEquals
(
Status
.
PROJECT_NOT_FOUNT
,
map
.
get
(
Constants
.
STATUS
));
logger
.
info
(
JSON
.
toJSONString
(
map
));
//project check auth success
putMsg
(
result
,
Status
.
SUCCESS
,
projectName
);
Mockito
.
when
(
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectName
)).
thenReturn
(
result
);
List
<
ProcessDefinition
>
resourceList
=
new
ArrayList
<>();
resourceList
.
add
(
getProcessDefinition
());
Mockito
.
when
(
processDefineMapper
.
queryAllDefinitionList
(
project
.
getId
())).
thenReturn
(
resourceList
);
Map
<
String
,
Object
>
checkSuccessRes
=
processDefinitionService
.
queryProccessDefinitionList
(
loginUser
,
"project_test1"
);
Assert
.
assertEquals
(
Status
.
SUCCESS
,
checkSuccessRes
.
get
(
Constants
.
STATUS
));
}
@Test
public
void
queryProcessDefinitionListPagingTest
()
throws
Exception
{
public
void
testQueryProcessDefinitionListPaging
()
{
String
projectName
=
"project_test1"
;
Mockito
.
when
(
projectMapper
.
queryByName
(
projectName
)).
thenReturn
(
getProject
(
projectName
));
...
...
@@ -132,12 +141,46 @@ public class ProcessDefinitionServiceTest {
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
5
);
putMsg
(
result
,
Status
.
PROJECT_NOT_FOUNT
,
projectName
);
//project not found
Mockito
.
when
(
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectName
)).
thenReturn
(
result
);
Map
<
String
,
Object
>
map
=
processDefinitionService
.
queryProcessDefinitionListPaging
(
loginUser
,
"project_test1"
,
""
,
1
,
5
,
0
);
Assert
.
assertEquals
(
Status
.
PROJECT_NOT_FOUNT
,
map
.
get
(
Constants
.
STATUS
));
}
@Test
public
void
testQueryProccessDefinitionById
()
{
String
projectName
=
"project_test1"
;
Mockito
.
when
(
projectMapper
.
queryByName
(
projectName
)).
thenReturn
(
getProject
(
projectName
));
Project
project
=
getProject
(
projectName
);
User
loginUser
=
new
User
();
loginUser
.
setId
(-
1
);
loginUser
.
setUserType
(
UserType
.
GENERAL_USER
);
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
5
);
putMsg
(
result
,
Status
.
PROJECT_NOT_FOUNT
,
projectName
);
//project check auth fail
Mockito
.
when
(
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectName
)).
thenReturn
(
result
);
Map
<
String
,
Object
>
map
=
processDefinitionService
.
queryProccessDefinitionById
(
loginUser
,
"project_test1"
,
1
);
Assert
.
assertEquals
(
Status
.
PROJECT_NOT_FOUNT
,
map
.
get
(
Constants
.
STATUS
));
logger
.
info
(
JSON
.
toJSONString
(
map
));
//project check auth success, instance not exist
putMsg
(
result
,
Status
.
SUCCESS
,
projectName
);
Mockito
.
when
(
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectName
)).
thenReturn
(
result
);
Mockito
.
when
(
processDefineMapper
.
selectById
(
1
)).
thenReturn
(
null
);
Map
<
String
,
Object
>
instanceNotexitRes
=
processDefinitionService
.
queryProccessDefinitionById
(
loginUser
,
"project_test1"
,
1
);
Assert
.
assertEquals
(
Status
.
PROCESS_INSTANCE_NOT_EXIST
,
instanceNotexitRes
.
get
(
Constants
.
STATUS
));
//instance exit
Mockito
.
when
(
processDefineMapper
.
selectById
(
46
)).
thenReturn
(
getProcessDefinition
());
Map
<
String
,
Object
>
successRes
=
processDefinitionService
.
queryProccessDefinitionById
(
loginUser
,
"project_test1"
,
46
);
Assert
.
assertEquals
(
Status
.
SUCCESS
,
successRes
.
get
(
Constants
.
STATUS
));
}
@Test
...
...
@@ -150,14 +193,115 @@ public class ProcessDefinitionServiceTest {
loginUser
.
setId
(-
1
);
loginUser
.
setUserType
(
UserType
.
GENERAL_USER
);
//project check auth fail
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
5
);
putMsg
(
result
,
Status
.
PROJECT_NOT_FOUNT
,
projectName
);
Mockito
.
when
(
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectName
)).
thenReturn
(
result
);
Map
<
String
,
Object
>
map
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
"project_test1"
,
6
);
Assert
.
assertEquals
(
Status
.
PROJECT_NOT_FOUNT
,
map
.
get
(
Constants
.
STATUS
));
//project check auth success, instance not exist
putMsg
(
result
,
Status
.
SUCCESS
,
projectName
);
Mockito
.
when
(
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectName
)).
thenReturn
(
result
);
Mockito
.
when
(
processDefineMapper
.
selectById
(
1
)).
thenReturn
(
null
);
Map
<
String
,
Object
>
instanceNotexitRes
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
"project_test1"
,
1
);
Assert
.
assertEquals
(
Status
.
PROCESS_DEFINE_NOT_EXIST
,
instanceNotexitRes
.
get
(
Constants
.
STATUS
));
ProcessDefinition
processDefinition
=
getProcessDefinition
();
//user no auth
loginUser
.
setUserType
(
UserType
.
GENERAL_USER
);
Mockito
.
when
(
processDefineMapper
.
selectById
(
46
)).
thenReturn
(
processDefinition
);
Map
<
String
,
Object
>
userNoAuthRes
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
"project_test1"
,
46
);
Assert
.
assertEquals
(
Status
.
USER_NO_OPERATION_PERM
,
userNoAuthRes
.
get
(
Constants
.
STATUS
));
//process definition online
loginUser
.
setUserType
(
UserType
.
ADMIN_USER
);
processDefinition
.
setReleaseState
(
ReleaseState
.
ONLINE
);
Mockito
.
when
(
processDefineMapper
.
selectById
(
46
)).
thenReturn
(
processDefinition
);
Map
<
String
,
Object
>
dfOnlineRes
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
"project_test1"
,
46
);
Assert
.
assertEquals
(
Status
.
PROCESS_DEFINE_STATE_ONLINE
,
dfOnlineRes
.
get
(
Constants
.
STATUS
));
//scheduler list elements > 1
processDefinition
.
setReleaseState
(
ReleaseState
.
OFFLINE
);
Mockito
.
when
(
processDefineMapper
.
selectById
(
46
)).
thenReturn
(
processDefinition
);
List
<
Schedule
>
schedules
=
new
ArrayList
<>();
schedules
.
add
(
getSchedule
());
schedules
.
add
(
getSchedule
());
Mockito
.
when
(
scheduleMapper
.
queryByProcessDefinitionId
(
46
)).
thenReturn
(
schedules
);
Map
<
String
,
Object
>
schedulerGreaterThanOneRes
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
"project_test1"
,
46
);
Assert
.
assertEquals
(
Status
.
DELETE_PROCESS_DEFINE_BY_ID_ERROR
,
schedulerGreaterThanOneRes
.
get
(
Constants
.
STATUS
));
//scheduler online
schedules
.
clear
();
Schedule
schedule
=
getSchedule
();
schedule
.
setReleaseState
(
ReleaseState
.
ONLINE
);
schedules
.
add
(
schedule
);
Mockito
.
when
(
scheduleMapper
.
queryByProcessDefinitionId
(
46
)).
thenReturn
(
schedules
);
Map
<
String
,
Object
>
schedulerOnlineRes
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
"project_test1"
,
46
);
Assert
.
assertEquals
(
Status
.
SCHEDULE_CRON_STATE_ONLINE
,
schedulerOnlineRes
.
get
(
Constants
.
STATUS
));
//delete fail
schedules
.
clear
();
schedule
.
setReleaseState
(
ReleaseState
.
OFFLINE
);
schedules
.
add
(
schedule
);
Mockito
.
when
(
scheduleMapper
.
queryByProcessDefinitionId
(
46
)).
thenReturn
(
schedules
);
Mockito
.
when
(
processDefineMapper
.
deleteById
(
46
)).
thenReturn
(
0
);
Map
<
String
,
Object
>
deleteFail
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
"project_test1"
,
46
);
Assert
.
assertEquals
(
Status
.
DELETE_PROCESS_DEFINE_BY_ID_ERROR
,
deleteFail
.
get
(
Constants
.
STATUS
));
//delte success
Mockito
.
when
(
processDefineMapper
.
deleteById
(
46
)).
thenReturn
(
1
);
Map
<
String
,
Object
>
deleteSuccess
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
"project_test1"
,
46
);
Assert
.
assertEquals
(
Status
.
SUCCESS
,
deleteSuccess
.
get
(
Constants
.
STATUS
));
}
@Test
public
void
testReleaseProcessDefinition
()
{
String
projectName
=
"project_test1"
;
Mockito
.
when
(
projectMapper
.
queryByName
(
projectName
)).
thenReturn
(
getProject
(
projectName
));
Project
project
=
getProject
(
projectName
);
User
loginUser
=
new
User
();
loginUser
.
setId
(-
1
);
loginUser
.
setUserType
(
UserType
.
GENERAL_USER
);
//project check auth fail
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
5
);
putMsg
(
result
,
Status
.
PROJECT_NOT_FOUNT
,
projectName
);
Mockito
.
when
(
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectName
)).
thenReturn
(
result
);
Map
<
String
,
Object
>
map
=
processDefinitionService
.
releaseProcessDefinition
(
loginUser
,
"project_test1"
,
6
,
ReleaseState
.
OFFLINE
.
getCode
());
Assert
.
assertEquals
(
Status
.
PROJECT_NOT_FOUNT
,
map
.
get
(
Constants
.
STATUS
));
logger
.
info
(
JSON
.
toJSONString
(
map
));
//project check auth success, processs definition online
putMsg
(
result
,
Status
.
SUCCESS
,
projectName
);
Mockito
.
when
(
processDefineMapper
.
selectById
(
46
)).
thenReturn
(
getProcessDefinition
());
Mockito
.
when
(
processDefineMapper
.
updateById
(
getProcessDefinition
())).
thenReturn
(
1
);
Map
<
String
,
Object
>
onlineRes
=
processDefinitionService
.
releaseProcessDefinition
(
loginUser
,
"project_test1"
,
46
,
ReleaseState
.
ONLINE
.
getCode
());
Assert
.
assertEquals
(
Status
.
SUCCESS
,
onlineRes
.
get
(
Constants
.
STATUS
));
//process definition offline
List
<
Schedule
>
schedules
=
new
ArrayList
<>();
Schedule
schedule
=
getSchedule
();
schedules
.
add
(
schedule
);
Mockito
.
when
(
scheduleMapper
.
selectAllByProcessDefineArray
(
new
int
[]{
46
})).
thenReturn
(
schedules
);
Mockito
.
when
(
scheduleMapper
.
updateById
(
schedule
)).
thenReturn
(
1
);
Map
<
String
,
Object
>
offlineRes
=
processDefinitionService
.
releaseProcessDefinition
(
loginUser
,
"project_test1"
,
46
,
ReleaseState
.
OFFLINE
.
getCode
());
Assert
.
assertEquals
(
Status
.
SUCCESS
,
offlineRes
.
get
(
Constants
.
STATUS
));
//release error code
Map
<
String
,
Object
>
failRes
=
processDefinitionService
.
releaseProcessDefinition
(
loginUser
,
"project_test1"
,
46
,
2
);
Assert
.
assertEquals
(
Status
.
REQUEST_PARAMS_NOT_VALID_ERROR
,
failRes
.
get
(
Constants
.
STATUS
));
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录