Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
f9638163
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,发现更多精彩内容 >>
提交
f9638163
编写于
3月 21, 2013
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fromdos
上级
e94152df
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
123 addition
and
123 deletion
+123
-123
core/src/test/java/hudson/scheduler/CronTabEventualityTest.java
...rc/test/java/hudson/scheduler/CronTabEventualityTest.java
+123
-123
未找到文件。
core/src/test/java/hudson/scheduler/CronTabEventualityTest.java
浏览文件 @
f9638163
package
hudson.scheduler
;
import
antlr.ANTLRException
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.jvnet.hudson.test.Bug
;
import
org.jvnet.hudson.test.For
;
import
java.text.DateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Collection
;
import
java.util.GregorianCalendar
;
@RunWith
(
Parameterized
.
class
)
@For
({
CronTab
.
class
,
Hash
.
class
})
public
class
CronTabEventualityTest
{
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
parameters
()
{
Collection
<
Object
[]>
parameters
=
new
ArrayList
<
Object
[]>();
parameters
.
add
(
new
Object
[]{
"zero"
,
Hash
.
zero
()});
parameters
.
add
(
new
Object
[]{
"seed1"
,
Hash
.
from
(
"seed1"
)});
parameters
.
add
(
new
Object
[]{
"seed2"
,
Hash
.
from
(
"seed2"
)});
return
parameters
;
}
private
Calendar
createLimit
(
Calendar
start
,
int
field
,
int
amount
){
Calendar
limit
=
(
Calendar
)
start
.
clone
();
limit
.
add
(
field
,
amount
);
return
limit
;
}
private
String
name
;
private
Hash
hash
;
public
CronTabEventualityTest
(
String
name
,
Hash
hash
)
{
this
.
name
=
name
;
this
.
hash
=
hash
;
}
@Test
(
timeout
=
1000
)
@Bug
(
12388
)
public
void
testYearlyWillBeEventuallyTriggeredWithinOneYear
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
YEAR
,
1
);
checkEventuality
(
start
,
"@yearly"
,
limit
);
}
@Test
(
timeout
=
1000
)
@Bug
(
12388
)
public
void
testAnnuallyWillBeEventuallyTriggeredWithinOneYear
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
YEAR
,
1
);
checkEventuality
(
start
,
"@annually"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testMonthlyWillBeEventuallyTriggeredWithinOneMonth
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
MONTH
,
1
);
checkEventuality
(
start
,
"@monthly"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testWeeklyWillBeEventuallyTriggeredWithinOneWeek
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
WEEK_OF_YEAR
,
1
);
checkEventuality
(
start
,
"@weekly"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testDailyWillBeEventuallyTriggeredWithinOneDay
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
DAY_OF_MONTH
,
1
);
checkEventuality
(
start
,
"@daily"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testMidnightWillBeEventuallyTriggeredWithinOneDay
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
DAY_OF_MONTH
,
1
);
checkEventuality
(
start
,
"@midnight"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testHourlyWillBeEventuallyTriggeredWithinOneHour
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
HOUR
,
1
);
checkEventuality
(
start
,
"@hourly"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testFirstDayOfMonthWillBeEventuallyTriggeredWithinOneMonth
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
MONTH
,
1
);
checkEventuality
(
start
,
"H H 1 * *"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testFirstSundayOfMonthWillBeEventuallyTriggeredWithinOneMonthAndOneWeek
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
DAY_OF_MONTH
,
31
+
7
);
// If both day of month and day of week are specified:
// UNIX: triggered when either matches
// Jenkins: triggered when both match
checkEventuality
(
start
,
"H H 1-7 * 0"
,
limit
);
}
private
void
checkEventuality
(
Calendar
start
,
String
crontabFormat
,
Calendar
limit
)
throws
ANTLRException
{
CronTab
cron
=
new
CronTab
(
crontabFormat
,
hash
);
Calendar
next
=
cron
.
ceil
(
start
);
if
(
next
.
after
(
limit
))
{
DateFormat
f
=
DateFormat
.
getDateTimeInstance
();
String
msg
=
"Name: "
+
name
+
" Limit: "
+
f
.
format
(
limit
.
getTime
())
+
" Next: "
+
f
.
format
(
next
.
getTime
());
fail
(
msg
);
}
}
}
package
hudson.scheduler
;
import
antlr.ANTLRException
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.jvnet.hudson.test.Bug
;
import
org.jvnet.hudson.test.For
;
import
java.text.DateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Collection
;
import
java.util.GregorianCalendar
;
@RunWith
(
Parameterized
.
class
)
@For
({
CronTab
.
class
,
Hash
.
class
})
public
class
CronTabEventualityTest
{
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
parameters
()
{
Collection
<
Object
[]>
parameters
=
new
ArrayList
<
Object
[]>();
parameters
.
add
(
new
Object
[]{
"zero"
,
Hash
.
zero
()});
parameters
.
add
(
new
Object
[]{
"seed1"
,
Hash
.
from
(
"seed1"
)});
parameters
.
add
(
new
Object
[]{
"seed2"
,
Hash
.
from
(
"seed2"
)});
return
parameters
;
}
private
Calendar
createLimit
(
Calendar
start
,
int
field
,
int
amount
){
Calendar
limit
=
(
Calendar
)
start
.
clone
();
limit
.
add
(
field
,
amount
);
return
limit
;
}
private
String
name
;
private
Hash
hash
;
public
CronTabEventualityTest
(
String
name
,
Hash
hash
)
{
this
.
name
=
name
;
this
.
hash
=
hash
;
}
@Test
(
timeout
=
1000
)
@Bug
(
12388
)
public
void
testYearlyWillBeEventuallyTriggeredWithinOneYear
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
YEAR
,
1
);
checkEventuality
(
start
,
"@yearly"
,
limit
);
}
@Test
(
timeout
=
1000
)
@Bug
(
12388
)
public
void
testAnnuallyWillBeEventuallyTriggeredWithinOneYear
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
YEAR
,
1
);
checkEventuality
(
start
,
"@annually"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testMonthlyWillBeEventuallyTriggeredWithinOneMonth
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
MONTH
,
1
);
checkEventuality
(
start
,
"@monthly"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testWeeklyWillBeEventuallyTriggeredWithinOneWeek
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
WEEK_OF_YEAR
,
1
);
checkEventuality
(
start
,
"@weekly"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testDailyWillBeEventuallyTriggeredWithinOneDay
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
DAY_OF_MONTH
,
1
);
checkEventuality
(
start
,
"@daily"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testMidnightWillBeEventuallyTriggeredWithinOneDay
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
DAY_OF_MONTH
,
1
);
checkEventuality
(
start
,
"@midnight"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testHourlyWillBeEventuallyTriggeredWithinOneHour
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
HOUR
,
1
);
checkEventuality
(
start
,
"@hourly"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testFirstDayOfMonthWillBeEventuallyTriggeredWithinOneMonth
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
MONTH
,
1
);
checkEventuality
(
start
,
"H H 1 * *"
,
limit
);
}
@Test
(
timeout
=
1000
)
public
void
testFirstSundayOfMonthWillBeEventuallyTriggeredWithinOneMonthAndOneWeek
()
throws
ANTLRException
{
Calendar
start
=
new
GregorianCalendar
(
2012
,
0
,
11
,
22
,
33
);
// Jan 11th 2012 22:33
Calendar
limit
=
createLimit
(
start
,
Calendar
.
DAY_OF_MONTH
,
31
+
7
);
// If both day of month and day of week are specified:
// UNIX: triggered when either matches
// Jenkins: triggered when both match
checkEventuality
(
start
,
"H H 1-7 * 0"
,
limit
);
}
private
void
checkEventuality
(
Calendar
start
,
String
crontabFormat
,
Calendar
limit
)
throws
ANTLRException
{
CronTab
cron
=
new
CronTab
(
crontabFormat
,
hash
);
Calendar
next
=
cron
.
ceil
(
start
);
if
(
next
.
after
(
limit
))
{
DateFormat
f
=
DateFormat
.
getDateTimeInstance
();
String
msg
=
"Name: "
+
name
+
" Limit: "
+
f
.
format
(
limit
.
getTime
())
+
" Next: "
+
f
.
format
(
next
.
getTime
());
fail
(
msg
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录