Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
e4643cf1
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4643cf1
编写于
5月 11, 2016
作者:
I
Ing. Pavel Janousek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modified based on Oliver's feedback
Slighty optimized and better legible asserts
上级
ff2992ed
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
43 deletion
+42
-43
test/src/test/java/hudson/cli/DeleteBuildsCommandTest.java
test/src/test/java/hudson/cli/DeleteBuildsCommandTest.java
+31
-39
test/src/test/java/hudson/model/ExecutorTest.java
test/src/test/java/hudson/model/ExecutorTest.java
+11
-4
未找到文件。
test/src/test/java/hudson/cli/DeleteBuildsCommandTest.java
浏览文件 @
e4643cf1
...
...
@@ -24,6 +24,7 @@
package
hudson.cli
;
import
hudson.model.ExecutorTest
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Job
;
import
hudson.model.Run
;
...
...
@@ -41,6 +42,7 @@ import static hudson.cli.CLICommandInvoker.Matcher.succeeded;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
/**
* @author pjanouse
...
...
@@ -88,7 +90,7 @@ public class DeleteBuildsCommandTest {
@Test
public
void
deleteBuildsShouldFailIfJobNameIsEmpty
()
throws
Exception
{
j
.
createFreeStyleProject
(
"aProject"
).
scheduleBuild2
(
0
).
get
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
1
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
1
));
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
...
...
@@ -100,19 +102,19 @@ public class DeleteBuildsCommandTest {
@Test
public
void
deleteBuildsShouldSuccess
()
throws
Exception
{
j
.
createFreeStyleProject
(
"aProject"
).
scheduleBuild2
(
0
).
get
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
1
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
1
));
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
}
@Test
public
void
deleteBuildsShouldSuccessIfBuildDoesNotExist
()
throws
Exception
{
j
.
createFreeStyleProject
(
"aProject"
).
scheduleBuild2
(
0
).
get
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
1
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
1
));
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
...
...
@@ -123,7 +125,7 @@ public class DeleteBuildsCommandTest {
@Test
public
void
deleteBuildsShouldSuccessIfBuildNumberZeroSpecified
()
throws
Exception
{
j
.
createFreeStyleProject
(
"aProject"
).
scheduleBuild2
(
0
).
get
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
1
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
1
));
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
...
...
@@ -134,31 +136,21 @@ public class DeleteBuildsCommandTest {
@Test
public
void
deleteBuildsShouldSuccessEvenTheBuildIsRunning
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1\nsleep 10s"
));
assertThat
(
"Job wasn't scheduled properly"
,
project
.
scheduleBuild
(
0
),
equalTo
(
true
));
// Wait until project is started (at least 1s)
while
(!
project
.
isBuilding
())
{
System
.
out
.
println
(
"Waiting for build to start and sleep 1s..."
);
Thread
.
sleep
(
1000
);
}
// Wait for the first sleep
if
(!
project
.
getBuildByNumber
(
1
).
getLog
().
contains
(
"echo 1"
))
{
Thread
.
sleep
(
1000
);
}
ExecutorTest
.
startBlockingBuild
(
project
);
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
(),
hasSize
(
1
));
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
assertThat
(
project
.
isBuilding
(),
equalTo
(
false
));
}
@Test
public
void
deleteBuildsShouldSuccessEvenTheBuildIsStuckInTheQueue
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1
\nsleep 10s
"
));
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project
.
setAssignedLabel
(
new
LabelAtom
(
"never_created"
));
assertThat
(
"Job wasn't scheduled properly"
,
project
.
scheduleBuild
(
0
),
equalTo
(
true
));
Thread
.
sleep
(
1000
);
...
...
@@ -170,12 +162,12 @@ public class DeleteBuildsCommandTest {
.
invokeWithArgs
(
"aProject"
,
"1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 0 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
isBuilding
(),
equalTo
(
false
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
isInQueue
(),
equalTo
(
true
));
Jenkins
.
getInstance
().
getQueue
().
cancel
(
project
);
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
isBuilding
(),
equalTo
(
false
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
isInQueue
(),
equalTo
(
false
));
}
...
...
@@ -187,63 +179,63 @@ public class DeleteBuildsCommandTest {
project
.
scheduleBuild2
(
0
).
get
();
project
.
scheduleBuild2
(
0
).
get
();
project
.
scheduleBuild2
(
0
).
get
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
5
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
5
));
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1,2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 2 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
3
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
3
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"3-5"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 3 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
}
@Test
public
void
deleteBuildsManyShouldSuccessEvenABuildIsSpecifiedTwice
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
scheduleBuild2
(
0
).
get
();
project
.
scheduleBuild2
(
0
).
get
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
2
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
2
));
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1,1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
1
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
1
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1-1,1-2,2-2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
}
@Test
public
void
deleteBuildsManyShouldSuccessEvenLastBuildDoesNotExist
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
scheduleBuild2
(
0
).
get
();
project
.
scheduleBuild2
(
0
).
get
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
2
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
2
));
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1,3"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
1
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
1
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"2-3"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
}
@Test
public
void
deleteBuildsManyShouldSuccessEvenMiddleBuildDoesNotExist
()
throws
Exception
{
...
...
@@ -256,21 +248,21 @@ public class DeleteBuildsCommandTest {
project
.
scheduleBuild2
(
0
).
get
();
project
.
getBuildByNumber
(
2
).
delete
();
project
.
getBuildByNumber
(
5
).
delete
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
4
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
4
));
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1,2,3"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 2 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
2
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
2
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"4-6"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 2 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
}
@Test
public
void
deleteBuildsManyShouldSuccessEvenFirstBuildDoesNotExist
()
throws
Exception
{
...
...
@@ -279,21 +271,21 @@ public class DeleteBuildsCommandTest {
project
.
scheduleBuild2
(
0
).
get
();
project
.
scheduleBuild2
(
0
).
get
();
project
.
getBuildByNumber
(
1
).
delete
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
2
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
2
));
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1,2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
1
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
1
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"2-3"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
}
@Test
public
void
deleteBuildsManyShouldSuccessEvenTheFirstAndLastBuildDoesNotExist
()
throws
Exception
{
...
...
@@ -306,20 +298,20 @@ public class DeleteBuildsCommandTest {
project
.
getBuildByNumber
(
1
).
delete
();
project
.
getBuildByNumber
(
3
).
delete
();
project
.
getBuildByNumber
(
5
).
delete
();
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
2
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
2
));
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"1,2,3"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
1
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
1
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Run
.
DELETE
)
.
invokeWithArgs
(
"aProject"
,
"3-5"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Deleted 1 builds"
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
.
size
(),
equalTo
(
0
));
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
()
,
hasSize
(
0
));
}
}
test/src/test/java/hudson/model/ExecutorTest.java
浏览文件 @
e4643cf1
...
...
@@ -144,14 +144,21 @@ public class ExecutorTest {
assertThat
(
log
,
containsString
(
"Disconnected by Johnny : Taking offline to break your buil"
));
}
private
Future
<
FreeStyleBuild
>
startBlockingBuild
(
FreeStyleProject
p
)
throws
Exception
{
/**
* Start a project with an infinite build step
*
* @param project {@link FreeStyleProject} to start
* @return A {@link Future} object represents the started build
* @throws Exception if somethink wrong happened
*/
public
static
Future
<
FreeStyleBuild
>
startBlockingBuild
(
FreeStyleProject
project
)
throws
Exception
{
final
OneShotEvent
e
=
new
OneShotEvent
();
p
.
getBuildersList
().
add
(
new
BlockingBuilder
(
e
));
p
roject
.
getBuildersList
().
add
(
new
BlockingBuilder
(
e
));
Future
<
FreeStyleBuild
>
r
=
p
.
scheduleBuild2
(
0
);
Future
<
FreeStyleBuild
>
r
=
p
roject
.
scheduleBuild2
(
0
);
e
.
block
();
// wait until we are safe to interrupt
assertTrue
(
p
.
getLastBuild
().
isBuilding
());
assertTrue
(
p
roject
.
getLastBuild
().
isBuilding
());
return
r
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录