Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
0000211d
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
提交
0000211d
编写于
4月 08, 2015
作者:
S
Stephen Connolly
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[JENKINS-27836] Add test case
上级
9fd4c1a8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
131 addition
and
0 deletion
+131
-0
test/src/test/java/hudson/tasks/LogRotatorTest.java
test/src/test/java/hudson/tasks/LogRotatorTest.java
+131
-0
未找到文件。
test/src/test/java/hudson/tasks/LogRotatorTest.java
浏览文件 @
0000211d
...
...
@@ -23,27 +23,38 @@
*/
package
hudson.tasks
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
hudson.Launcher
;
import
hudson.model.AbstractBuild
;
import
hudson.model.BuildListener
;
import
hudson.model.Descriptor
;
import
hudson.model.FreeStyleBuild
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Result
;
import
hudson.model.Run
;
import
hudson.model.queue.QueueTaskFuture
;
import
hudson.tasks.ArtifactArchiverTest.CreateArtifact
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.FailureBuilder
;
import
org.jvnet.hudson.test.Issue
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
org.jvnet.hudson.test.TestBuilder
;
/**
* Verifies that the last successful and stable builds of a job will be kept if requested.
...
...
@@ -136,6 +147,59 @@ public class LogRotatorTest {
assertTrue
(
project
.
getBuildByNumber
(
7
).
getHasArtifacts
());
assertTrue
(
project
.
getBuildByNumber
(
8
).
getHasArtifacts
());
}
@Test
@Issue
(
"JENKINS-27836"
)
public
void
artifactsRetainedWhileBuilding
()
throws
Exception
{
j
.
getInstance
().
setNumExecutors
(
3
);
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
p
.
setBuildDiscarder
(
new
LogRotator
(-
1
,
3
,
-
1
,
1
));
StallBuilder
sync
=
new
StallBuilder
();
p
.
getBuildersList
().
replaceBy
(
Arrays
.
asList
(
new
CreateArtifact
(),
sync
));
p
.
setConcurrentBuild
(
true
);
QueueTaskFuture
<
FreeStyleBuild
>
futureRun1
=
p
.
scheduleBuild2
(
0
);
FreeStyleBuild
run1
=
futureRun1
.
waitForStart
();
sync
.
waitFor
(
run1
.
getNumber
(),
1
,
TimeUnit
.
SECONDS
);
QueueTaskFuture
<
FreeStyleBuild
>
futureRun2
=
p
.
scheduleBuild2
(
0
);
FreeStyleBuild
run2
=
futureRun2
.
waitForStart
();
sync
.
waitFor
(
run2
.
getNumber
(),
1
,
TimeUnit
.
SECONDS
);
QueueTaskFuture
<
FreeStyleBuild
>
futureRun3
=
p
.
scheduleBuild2
(
0
);
FreeStyleBuild
run3
=
futureRun3
.
waitForStart
();
sync
.
waitFor
(
run3
.
getNumber
(),
1
,
TimeUnit
.
SECONDS
);
assertThat
(
"we haven't released run1's guard"
,
run1
.
isBuilding
(),
is
(
true
));
assertThat
(
"we haven't released run2's guard"
,
run2
.
isBuilding
(),
is
(
true
));
assertThat
(
"we haven't released run3's guard"
,
run3
.
isBuilding
(),
is
(
true
));
assertThat
(
"we have artifacts in run1"
,
run1
.
getHasArtifacts
(),
is
(
true
));
assertThat
(
"we have artifacts in run2"
,
run2
.
getHasArtifacts
(),
is
(
true
));
assertThat
(
"we have artifacts in run3"
,
run3
.
getHasArtifacts
(),
is
(
true
));
sync
.
release
(
run1
.
getNumber
());
futureRun1
.
get
();
assertThat
(
"we have released run1's guard"
,
run1
.
isBuilding
(),
is
(
false
));
assertThat
(
"we haven't released run2's guard"
,
run2
.
isBuilding
(),
is
(
true
));
assertThat
(
"we haven't released run3's guard"
,
run3
.
isBuilding
(),
is
(
true
));
assertThat
(
"run1 is last stable build"
,
p
.
getLastStableBuild
(),
is
(
run1
));
assertThat
(
"run1 is last successful build"
,
p
.
getLastSuccessfulBuild
(),
is
(
run1
));
assertThat
(
"we have artifacts in run1"
,
run1
.
getHasArtifacts
(),
is
(
true
));
assertThat
(
"CRITICAL ASSERTION: we have artifacts in run2"
,
run2
.
getHasArtifacts
(),
is
(
true
));
assertThat
(
"we have artifacts in run3"
,
run3
.
getHasArtifacts
(),
is
(
true
));
sync
.
release
(
run2
.
getNumber
());
futureRun2
.
get
();
assertThat
(
"we have released run2's guard"
,
run2
.
isBuilding
(),
is
(
false
));
assertThat
(
"we haven't released run3's guard"
,
run3
.
isBuilding
(),
is
(
true
));
assertThat
(
"we have no artifacts in run1"
,
run1
.
getHasArtifacts
(),
is
(
false
));
assertThat
(
"run2 is last stable build"
,
p
.
getLastStableBuild
(),
is
(
run2
));
assertThat
(
"run2 is last successful build"
,
p
.
getLastSuccessfulBuild
(),
is
(
run2
));
assertThat
(
"we have artifacts in run2"
,
run2
.
getHasArtifacts
(),
is
(
true
));
assertThat
(
"we have artifacts in run3"
,
run3
.
getHasArtifacts
(),
is
(
true
));
sync
.
release
(
run3
.
getNumber
());
futureRun3
.
get
();
assertThat
(
"we have released run3's guard"
,
run3
.
isBuilding
(),
is
(
false
));
assertThat
(
"we have no artifacts in run1"
,
run1
.
getHasArtifacts
(),
is
(
false
));
assertThat
(
"we have no artifacts in run2"
,
run2
.
getHasArtifacts
(),
is
(
false
));
assertThat
(
"run3 is last stable build"
,
p
.
getLastStableBuild
(),
is
(
run3
));
assertThat
(
"run3 is last successful build"
,
p
.
getLastSuccessfulBuild
(),
is
(
run3
));
assertThat
(
"we have artifacts in run3"
,
run3
.
getHasArtifacts
(),
is
(
true
));
}
static
Result
build
(
FreeStyleProject
project
)
throws
Exception
{
return
project
.
scheduleBuild2
(
0
).
get
().
getResult
();
...
...
@@ -163,4 +227,71 @@ public class LogRotatorTest {
};
}
}
static
class
StallBuilder
extends
TestBuilder
{
private
int
syncBuildNumber
;
private
final
Object
syncLock
=
new
Object
();
private
int
waitBuildNumber
;
private
final
Object
waitLock
=
new
Object
();
private
final
ArtifactArchiver
archiver
=
new
ArtifactArchiver
(
"f"
);
public
@Override
boolean
perform
(
AbstractBuild
<?,?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
IOException
,
InterruptedException
{
archiver
.
perform
(
build
,
launcher
,
listener
);
Logger
.
getAnonymousLogger
().
log
(
Level
.
INFO
,
"Building #{0}"
,
build
.
getNumber
());
synchronized
(
waitLock
)
{
if
(
waitBuildNumber
<
build
.
getNumber
())
{
waitBuildNumber
=
build
.
getNumber
();
waitLock
.
notifyAll
();
}
}
Logger
.
getAnonymousLogger
().
log
(
Level
.
INFO
,
"Waiting #{0}"
,
build
.
getNumber
());
synchronized
(
syncLock
)
{
while
(
build
.
getNumber
()
>
syncBuildNumber
)
{
try
{
syncLock
.
wait
(
10
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
(
listener
.
fatalError
(
"Interrupted: %s"
,
e
.
getMessage
()));
return
false
;
}
}
}
Logger
.
getAnonymousLogger
().
log
(
Level
.
INFO
,
"Done #{0}"
,
build
.
getNumber
());
return
true
;
}
public
void
release
(
int
upToBuildNumber
)
{
synchronized
(
syncLock
)
{
if
(
syncBuildNumber
<
upToBuildNumber
)
{
Logger
.
getAnonymousLogger
().
log
(
Level
.
INFO
,
"Signal #{0}"
,
upToBuildNumber
);
syncBuildNumber
=
upToBuildNumber
;
syncLock
.
notifyAll
();
}
}
}
public
void
waitFor
(
int
buildNumber
,
long
timeout
,
TimeUnit
units
)
throws
TimeoutException
,
InterruptedException
{
long
giveUp
=
System
.
nanoTime
()
+
units
.
toNanos
(
timeout
);
synchronized
(
waitLock
)
{
while
(
waitBuildNumber
<
buildNumber
)
{
long
remaining
=
giveUp
-
System
.
nanoTime
();
if
(
remaining
<
0
)
{
throw
new
TimeoutException
();
}
waitLock
.
wait
(
remaining
/
1000000L
,
(
int
)(
remaining
%
1000000L
));
}
}
}
public
BuildStepMonitor
getRequiredMonitorService
()
{
return
BuildStepMonitor
.
NONE
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录