Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pentaLiker
DolphinScheduler
提交
e61586cd
DolphinScheduler
项目概览
pentaLiker
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
1
Star
1
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,发现更多精彩内容 >>
提交
e61586cd
编写于
12月 29, 2019
作者:
Q
qiaozhanwei
提交者:
khadgarmage
12月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CommandMapperTest UT modify #1465 (#1625)
* CommandMapperTest UT modify
上级
779decc9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
292 addition
and
90 deletion
+292
-90
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java
.../java/org/apache/dolphinscheduler/dao/entity/Command.java
+73
-1
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/CommandCount.java
.../org/apache/dolphinscheduler/dao/entity/CommandCount.java
+33
-7
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java
...g/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java
+3
-0
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/CommandMapperTest.java
...apache/dolphinscheduler/dao/mapper/CommandMapperTest.java
+182
-82
pom.xml
pom.xml
+1
-0
未找到文件。
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Command.java
浏览文件 @
e61586cd
...
@@ -28,7 +28,6 @@ import java.util.Date;
...
@@ -28,7 +28,6 @@ import java.util.Date;
/**
/**
* command
* command
*/
*/
@Data
@TableName
(
"t_ds_command"
)
@TableName
(
"t_ds_command"
)
public
class
Command
{
public
class
Command
{
...
@@ -265,6 +264,79 @@ public class Command {
...
@@ -265,6 +264,79 @@ public class Command {
this
.
workerGroupId
=
workerGroupId
;
this
.
workerGroupId
=
workerGroupId
;
}
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
Command
command
=
(
Command
)
o
;
if
(
id
!=
command
.
id
)
{
return
false
;
}
if
(
processDefinitionId
!=
command
.
processDefinitionId
)
{
return
false
;
}
if
(
executorId
!=
command
.
executorId
)
{
return
false
;
}
if
(
workerGroupId
!=
command
.
workerGroupId
)
{
return
false
;
}
if
(
commandType
!=
command
.
commandType
)
{
return
false
;
}
if
(
commandParam
!=
null
?
!
commandParam
.
equals
(
command
.
commandParam
)
:
command
.
commandParam
!=
null
)
{
return
false
;
}
if
(
taskDependType
!=
command
.
taskDependType
)
{
return
false
;
}
if
(
failureStrategy
!=
command
.
failureStrategy
)
{
return
false
;
}
if
(
warningType
!=
command
.
warningType
)
{
return
false
;
}
if
(
warningGroupId
!=
null
?
!
warningGroupId
.
equals
(
command
.
warningGroupId
)
:
command
.
warningGroupId
!=
null
)
{
return
false
;
}
if
(
scheduleTime
!=
null
?
!
scheduleTime
.
equals
(
command
.
scheduleTime
)
:
command
.
scheduleTime
!=
null
)
{
return
false
;
}
if
(
startTime
!=
null
?
!
startTime
.
equals
(
command
.
startTime
)
:
command
.
startTime
!=
null
)
{
return
false
;
}
if
(
processInstancePriority
!=
command
.
processInstancePriority
)
{
return
false
;
}
return
!(
updateTime
!=
null
?
!
updateTime
.
equals
(
command
.
updateTime
)
:
command
.
updateTime
!=
null
);
}
@Override
public
int
hashCode
()
{
int
result
=
id
;
result
=
31
*
result
+
(
commandType
!=
null
?
commandType
.
hashCode
()
:
0
);
result
=
31
*
result
+
processDefinitionId
;
result
=
31
*
result
+
executorId
;
result
=
31
*
result
+
(
commandParam
!=
null
?
commandParam
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
taskDependType
!=
null
?
taskDependType
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
failureStrategy
!=
null
?
failureStrategy
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
warningType
!=
null
?
warningType
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
warningGroupId
!=
null
?
warningGroupId
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
scheduleTime
!=
null
?
scheduleTime
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
startTime
!=
null
?
startTime
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
processInstancePriority
!=
null
?
processInstancePriority
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
updateTime
!=
null
?
updateTime
.
hashCode
()
:
0
);
result
=
31
*
result
+
workerGroupId
;
return
result
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Command{"
+
return
"Command{"
+
...
...
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/CommandCount.java
浏览文件 @
e61586cd
...
@@ -33,13 +33,6 @@ public class CommandCount {
...
@@ -33,13 +33,6 @@ public class CommandCount {
private
int
count
;
private
int
count
;
@Override
public
String
toString
(){
return
"command count:"
+
" commandType: "
+
commandType
.
toString
()
+
" count: "
+
count
;
}
public
CommandType
getCommandType
()
{
public
CommandType
getCommandType
()
{
return
commandType
;
return
commandType
;
}
}
...
@@ -55,4 +48,37 @@ public class CommandCount {
...
@@ -55,4 +48,37 @@ public class CommandCount {
public
void
setCount
(
int
count
)
{
public
void
setCount
(
int
count
)
{
this
.
count
=
count
;
this
.
count
=
count
;
}
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
CommandCount
that
=
(
CommandCount
)
o
;
if
(
count
!=
that
.
count
)
{
return
false
;
}
return
commandType
==
that
.
commandType
;
}
@Override
public
int
hashCode
()
{
int
result
=
commandType
!=
null
?
commandType
.
hashCode
()
:
0
;
result
=
31
*
result
+
count
;
return
result
;
}
@Override
public
String
toString
()
{
return
"CommandCount{"
+
"commandType="
+
commandType
+
", count="
+
count
+
'}'
;
}
}
}
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AlertMapperTest.java
浏览文件 @
e61586cd
...
@@ -35,6 +35,9 @@ import java.util.*;
...
@@ -35,6 +35,9 @@ import java.util.*;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.*;
/**
* alert mapper test
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
@SpringBootTest
@Transactional
@Transactional
...
...
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/CommandMapperTest.java
浏览文件 @
e61586cd
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
*/
*/
package
org.apache.dolphinscheduler.dao.mapper
;
package
org.apache.dolphinscheduler.dao.mapper
;
import
org.apache.dolphinscheduler.common.utils.DateUtils
;
import
org.apache.dolphinscheduler.dao.entity.Command
;
import
org.apache.dolphinscheduler.dao.entity.Command
;
import
org.apache.dolphinscheduler.dao.entity.CommandCount
;
import
org.apache.dolphinscheduler.dao.entity.CommandCount
;
import
org.apache.dolphinscheduler.dao.entity.ProcessDefinition
;
import
org.apache.dolphinscheduler.dao.entity.ProcessDefinition
;
...
@@ -25,13 +26,25 @@ import org.junit.Test;
...
@@ -25,13 +26,25 @@ import org.junit.Test;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
/**
* command mapper test
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
@SpringBootTest
@Transactional
@Rollback
(
true
)
public
class
CommandMapperTest
{
public
class
CommandMapperTest
{
...
@@ -41,71 +54,85 @@ public class CommandMapperTest {
...
@@ -41,71 +54,85 @@ public class CommandMapperTest {
@Autowired
@Autowired
ProcessDefinitionMapper
processDefinitionMapper
;
ProcessDefinitionMapper
processDefinitionMapper
;
/**
/**
* insert
* test insert
* @return Command
*/
*/
private
Command
insertOne
(){
@Test
//insertOne
public
void
testInsert
(){
Command
command
=
new
Command
();
Command
command
=
createCommand
();
command
.
setCommandType
(
CommandType
.
START_PROCESS
);
assertNotNull
(
command
.
getId
());
command
.
setProcessDefinitionId
(
1
);
assertThat
(
command
.
getId
(),
greaterThan
(
0
));
command
.
setExecutorId
(
4
);
command
.
setProcessInstancePriority
(
Priority
.
MEDIUM
);
command
.
setFailureStrategy
(
FailureStrategy
.
CONTINUE
);
command
.
setWorkerGroupId
(-
1
);
command
.
setWarningGroupId
(
1
);
command
.
setUpdateTime
(
new
Date
());
commandMapper
.
insert
(
command
);
return
command
;
}
}
/**
/**
* test
update
* test
select by id
*/
*/
@Test
@Test
public
void
testUpdate
(){
public
void
testSelectById
()
{
//insertOne
Command
expectedCommand
=
createCommand
();
Command
command
=
insertOne
();
//query
//update
Command
actualCommand
=
commandMapper
.
selectById
(
expectedCommand
.
getId
());
command
.
setStartTime
(
new
Date
());
int
update
=
commandMapper
.
updateById
(
command
);
assertEquals
(
expectedCommand
,
actualCommand
);
Assert
.
assertEquals
(
update
,
1
);
commandMapper
.
deleteById
(
command
.
getId
());
}
}
/**
/**
* test
dele
te
* test
upda
te
*/
*/
@Test
@Test
public
void
testDelete
(){
public
void
testUpdate
(){
Command
expectedCommand
=
createCommand
();
// update the command time if current command if recover from waiting
expectedCommand
.
setUpdateTime
(
DateUtils
.
getCurrentDate
());
commandMapper
.
updateById
(
expectedCommand
);
Command
actualCommand
=
commandMapper
.
selectById
(
expectedCommand
.
getId
());
assertEquals
(
expectedCommand
,
actualCommand
);
Command
Command
=
insertOne
();
int
delete
=
commandMapper
.
deleteById
(
Command
.
getId
());
Assert
.
assertEquals
(
delete
,
1
);
}
}
/**
/**
* test
query
* test
delete
*/
*/
@Test
@Test
public
void
testQuery
()
{
public
void
testDelete
(){
Command
command
=
insertOne
();
Command
expectedCommand
=
createCommand
();
//query
List
<
Command
>
commands
=
commandMapper
.
selectList
(
null
);
commandMapper
.
deleteById
(
expectedCommand
.
getId
());
Assert
.
assertNotEquals
(
commands
.
size
(),
0
);
commandMapper
.
deleteById
(
command
.
getId
());
Command
actualCommand
=
commandMapper
.
selectById
(
expectedCommand
.
getId
());
assertNull
(
actualCommand
);
}
}
/**
/**
* test query all
* test query all
*/
*/
@Test
@Test
public
void
testGetAll
()
{
public
void
testGetAll
()
{
Command
command
=
insertOne
();
Integer
count
=
10
;
List
<
Command
>
commands
=
commandMapper
.
selectList
(
null
);
Assert
.
assertNotEquals
(
commands
.
size
(),
0
);
Map
<
Integer
,
Command
>
commandMap
=
createCommandMap
(
count
);
commandMapper
.
deleteById
(
command
.
getId
());
List
<
Command
>
actualCommands
=
commandMapper
.
selectList
(
null
);
assertThat
(
actualCommands
.
size
(),
greaterThanOrEqualTo
(
count
));
for
(
Command
actualCommand
:
actualCommands
){
Command
expectedCommand
=
commandMap
.
get
(
actualCommand
.
getId
());
if
(
expectedCommand
!=
null
){
assertEquals
(
expectedCommand
,
actualCommand
);
}
}
}
}
/**
/**
...
@@ -113,28 +140,14 @@ public class CommandMapperTest {
...
@@ -113,28 +140,14 @@ public class CommandMapperTest {
*/
*/
@Test
@Test
public
void
testGetOneToRun
()
{
public
void
testGetOneToRun
()
{
ProcessDefinition
processDefinition
=
new
ProcessDefinition
();
processDefinition
.
setReleaseState
(
ReleaseState
.
ONLINE
);
processDefinition
.
setName
(
"ut test"
);
processDefinition
.
setProjectId
(
1
);
processDefinition
.
setFlag
(
Flag
.
YES
);
processDefinitionMapper
.
insert
(
processDefinition
);
Command
command
=
new
Command
();
ProcessDefinition
processDefinition
=
createProcessDefinition
();
command
.
setCommandType
(
CommandType
.
START_PROCESS
);
command
.
setProcessDefinitionId
(
processDefinition
.
getId
());
Command
expectedCommand
=
createCommand
(
CommandType
.
START_PROCESS
,
processDefinition
.
getId
());
command
.
setExecutorId
(
4
);
command
.
setProcessInstancePriority
(
Priority
.
MEDIUM
);
command
.
setFailureStrategy
(
FailureStrategy
.
CONTINUE
);
command
.
setWorkerGroupId
(-
1
);
command
.
setWarningGroupId
(
1
);
command
.
setUpdateTime
(
new
Date
());
commandMapper
.
insert
(
command
);
Command
command2
=
commandMapper
.
getOneToRun
();
Command
actualCommand
=
commandMapper
.
getOneToRun
();
Assert
.
assertNotEquals
(
command2
,
null
);
commandMapper
.
deleteById
(
command
.
getId
());
assertEquals
(
expectedCommand
,
actualCommand
);
processDefinitionMapper
.
deleteById
(
processDefinition
.
getId
());
}
}
/**
/**
...
@@ -142,35 +155,122 @@ public class CommandMapperTest {
...
@@ -142,35 +155,122 @@ public class CommandMapperTest {
*/
*/
@Test
@Test
public
void
testCountCommandState
()
{
public
void
testCountCommandState
()
{
Command
command
=
insertOne
();
Integer
count
=
10
;
ProcessDefinition
processDefinition
=
createProcessDefinition
();
CommandCount
expectedCommandCount
=
createCommandMap
(
count
,
CommandType
.
START_PROCESS
,
processDefinition
.
getId
());
Integer
[]
projectIdArray
=
{
processDefinition
.
getProjectId
()};
Date
startTime
=
DateUtils
.
stringToDate
(
"2019-12-29 00:10:00"
);
Date
endTime
=
DateUtils
.
stringToDate
(
"2019-12-29 23:59:59"
);
List
<
CommandCount
>
actualCommandCounts
=
commandMapper
.
countCommandState
(
0
,
startTime
,
endTime
,
projectIdArray
);
assertThat
(
actualCommandCounts
.
size
(),
greaterThanOrEqualTo
(
1
));
Boolean
flag
=
false
;
for
(
CommandCount
actualCommandCount
:
actualCommandCounts
){
if
(
actualCommandCount
.
getCommandType
().
equals
(
expectedCommandCount
.
getCommandType
())){
assertEquals
(
expectedCommandCount
,
actualCommandCount
);
flag
=
true
;
}
}
assertTrue
(
flag
);
}
//insertOne
/**
* create command map
* @param count map count
* @param commandType comman type
* @param processDefinitionId process definition id
* @return command map
*/
private
CommandCount
createCommandMap
(
Integer
count
,
CommandType
commandType
,
Integer
processDefinitionId
){
CommandCount
commandCount
=
new
CommandCount
();
for
(
int
i
=
0
;
i
<
count
;
i
++){
createCommand
(
commandType
,
processDefinitionId
);
}
commandCount
.
setCommandType
(
commandType
);
commandCount
.
setCount
(
count
);
return
commandCount
;
}
/**
* create process definition
* @return process definition
*/
private
ProcessDefinition
createProcessDefinition
(){
ProcessDefinition
processDefinition
=
new
ProcessDefinition
();
ProcessDefinition
processDefinition
=
new
ProcessDefinition
();
processDefinition
.
set
Name
(
"def 1"
);
processDefinition
.
set
ReleaseState
(
ReleaseState
.
ONLINE
);
processDefinition
.
set
ProjectId
(
1010
);
processDefinition
.
set
Name
(
"ut test"
);
processDefinition
.
set
UserId
(
10
1
);
processDefinition
.
set
ProjectId
(
1
);
processDefinition
.
set
UpdateTime
(
new
Date
()
);
processDefinition
.
set
Flag
(
Flag
.
YES
);
processDefinition
.
setCreateTime
(
new
Date
());
processDefinitionMapper
.
insert
(
processDefinition
);
processDefinitionMapper
.
insert
(
processDefinition
);
command
.
setProcessDefinitionId
(
processDefinition
.
getId
())
;
return
processDefinition
;
commandMapper
.
updateById
(
command
);
}
/**
* create command map
* @param count map count
* @return command map
*/
private
Map
<
Integer
,
Command
>
createCommandMap
(
Integer
count
){
Map
<
Integer
,
Command
>
commandMap
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
count
;
i
++){
Command
command
=
createCommand
();
commandMap
.
put
(
command
.
getId
(),
command
);
}
return
commandMap
;
}
List
<
CommandCount
>
commandCounts
=
commandMapper
.
countCommandState
(
4
,
null
,
null
,
new
Integer
[
0
]
);
Integer
[]
projectIdArray
=
new
Integer
[
2
];
/**
projectIdArray
[
0
]
=
processDefinition
.
getProjectId
();
* create command
projectIdArray
[
1
]
=
200
;
* @return
List
<
CommandCount
>
commandCounts2
=
commandMapper
.
countCommandState
(
*/
4
,
null
,
null
,
projectIdArray
private
Command
createCommand
(){
);
return
createCommand
(
CommandType
.
START_PROCESS
,
1
);
}
/**
* create command
* @return Command
*/
private
Command
createCommand
(
CommandType
commandType
,
Integer
processDefinitionId
){
Command
command
=
new
Command
();
command
.
setCommandType
(
commandType
);
command
.
setProcessDefinitionId
(
processDefinitionId
);
command
.
setExecutorId
(
4
);
command
.
setCommandParam
(
"test command param"
);
command
.
setTaskDependType
(
TaskDependType
.
TASK_ONLY
);
command
.
setFailureStrategy
(
FailureStrategy
.
CONTINUE
);
command
.
setWarningType
(
WarningType
.
ALL
);
command
.
setWarningGroupId
(
1
);
command
.
setScheduleTime
(
DateUtils
.
stringToDate
(
"2019-12-29 12:10:00"
));
command
.
setProcessInstancePriority
(
Priority
.
MEDIUM
);
command
.
setStartTime
(
DateUtils
.
stringToDate
(
"2019-12-29 10:10:00"
));
command
.
setUpdateTime
(
DateUtils
.
stringToDate
(
"2019-12-29 10:10:00"
));
command
.
setWorkerGroupId
(-
1
);
commandMapper
.
insert
(
command
);
commandMapper
.
deleteById
(
command
.
getId
());
return
command
;
processDefinitionMapper
.
deleteById
(
processDefinition
.
getId
());
Assert
.
assertNotEquals
(
commandCounts
.
size
(),
0
);
Assert
.
assertNotEquals
(
commandCounts2
.
size
(),
0
);
}
}
}
}
\ No newline at end of file
pom.xml
浏览文件 @
e61586cd
...
@@ -675,6 +675,7 @@
...
@@ -675,6 +675,7 @@
<include>
**/dao/mapper/AccessTokenMapperTest.java
</include>
<include>
**/dao/mapper/AccessTokenMapperTest.java
</include>
<include>
**/dao/mapper/AlertGroupMapperTest.java
</include>
<include>
**/dao/mapper/AlertGroupMapperTest.java
</include>
<include>
**/dao/mapper/AlertMapperTest.java
</include>
<include>
**/dao/mapper/AlertMapperTest.java
</include>
<include>
**/dao/mapper/CommandMapperTest.java
</include>
</includes>
</includes>
<!-- <skip>true</skip> -->
<!-- <skip>true</skip> -->
</configuration>
</configuration>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录