Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
f8515e96
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,发现更多精彩内容 >>
提交
f8515e96
编写于
2月 04, 2011
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'HUDSON-8656' of
https://github.com/nairb774/jenkins
上级
91f79062
f134bd68
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
339 addition
and
2 deletion
+339
-2
core/src/main/java/hudson/scheduler/CronTab.java
core/src/main/java/hudson/scheduler/CronTab.java
+7
-2
core/src/test/java/hudson/scheduler/CronTabDayOfWeekLocaleTest.java
...est/java/hudson/scheduler/CronTabDayOfWeekLocaleTest.java
+287
-0
core/src/test/java/hudson/scheduler/CronTabTest.java
core/src/test/java/hudson/scheduler/CronTabTest.java
+45
-0
未找到文件。
core/src/main/java/hudson/scheduler/CronTab.java
浏览文件 @
f8515e96
...
...
@@ -218,18 +218,23 @@ public final class CronTab {
private
static
final
CalendarField
DAY_OF_WEEK
=
new
CalendarField
(
"dow"
,
Calendar
.
DAY_OF_WEEK
,
1
,-
1
,
true
,
HOUR
)
{
long
bits
(
CronTab
c
)
{
return
c
.
dayOfWeek
;
}
void
rollUp
(
Calendar
cal
,
int
i
)
{
cal
.
add
(
Calendar
.
DAY_OF_WEEK
,
7
);
cal
.
add
(
Calendar
.
DAY_OF_WEEK
,
7
*
i
);
}
@Override
void
setTo
(
Calendar
c
,
int
i
)
{
int
v
=
i
-
offset
;
int
was
=
c
.
get
(
field
);
c
.
set
(
field
,
v
);
if
(
v
<
c
.
getFirstDayOfWeek
())
{
final
int
firstDayOfWeek
=
c
.
getFirstDayOfWeek
();
if
(
v
<
firstDayOfWeek
&&
was
>=
firstDayOfWeek
)
{
// in crontab, the first DoW is always Sunday, but in Java, it can be Monday or in theory arbitrary other days.
// When first DoW is 1/2 Monday, calendar points to 1/2 Monday, setting the DoW to Sunday makes
// the calendar moves forward to 1/8 Sunday, instead of 1/1 Sunday. So we need to compensate that effect here.
addTo
(
c
,-
7
);
}
else
if
(
was
<
firstDayOfWeek
&&
firstDayOfWeek
<=
v
)
{
// If we wrap the other way around, we need to adjust in the opposite direction of above.
addTo
(
c
,
7
);
}
}
};
...
...
core/src/test/java/hudson/scheduler/CronTabDayOfWeekLocaleTest.java
0 → 100644
浏览文件 @
f8515e96
package
hudson.scheduler
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
java.text.DateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Collection
;
import
java.util.GregorianCalendar
;
import
java.util.Locale
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.junit.runners.Parameterized.Parameters
;
import
org.jvnet.hudson.test.For
;
import
org.jvnet.hudson.test.Url
;
/**
* A collection of unit tests focused around crontabs restricted to particular
* days of the week. This flexes across all the locales in the system to check
* the correctness of the {@link CronTab} class, more specifically the
* {@link CronTab#floor(Calendar)} and {@link CronTab#ceil(Calendar)} methods.
*/
@For
(
CronTab
.
class
)
@RunWith
(
Parameterized
.
class
)
public
class
CronTabDayOfWeekLocaleTest
{
@Parameters
public
static
Collection
<
Object
[]>
parameters
()
{
final
Locale
[]
locales
=
Locale
.
getAvailableLocales
();
final
Collection
<
Object
[]>
parameters
=
new
ArrayList
<
Object
[]>();
for
(
final
Locale
locale
:
locales
)
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
if
(
GregorianCalendar
.
class
.
equals
(
cal
.
getClass
()))
{
parameters
.
add
(
new
Object
[]
{
locale
});
}
}
return
parameters
;
}
private
final
Locale
locale
;
public
CronTabDayOfWeekLocaleTest
(
Locale
locale
)
{
this
.
locale
=
locale
;
}
/**
* This unit test is an slight adaptation of the unit test found in
* HUDSON-8656.
*/
@Test
@Url
(
"http://issues.hudson-ci.org/browse/HUDSON-8656"
)
public
void
hudson8658
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 23 * * 1-5"
;
// execute on weekdays @23:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
next
=
cron
.
ceil
(
cal
);
final
Calendar
expectedDate
=
Calendar
.
getInstance
();
// Expected next: Monday, Jan 17th 2011, 23:00
expectedDate
.
set
(
2011
,
0
,
17
,
23
,
0
,
0
);
compare
(
expectedDate
,
next
);
}
@Test
public
void
isSundayAndNextRunIsMonday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 1"
;
// Mondays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
ceil
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Monday, Jan 17th 2011, 00:00
expected
.
set
(
2011
,
0
,
17
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndPreviousRunIsMonday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 1"
;
// Mondays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
floor
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Monday, Jan 10th 2011, 00:00
expected
.
set
(
2011
,
0
,
10
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndNextRunIsTuesday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 2"
;
// Tuesdays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
ceil
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Tuesday, Jan 18th 2011, 00:00
expected
.
set
(
2011
,
0
,
18
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndPreviousRunIsTuesday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 2"
;
// Tuesdays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
floor
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Tuesday, Jan 11th 2011, 00:00
expected
.
set
(
2011
,
0
,
11
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndNextRunIsWednesday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 3"
;
// Wednesdays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
ceil
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Wednesday, Jan 19th 2011, 00:00
expected
.
set
(
2011
,
0
,
19
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndPreviousRunIsWednesday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 3"
;
// Wednesdays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
floor
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Wednesday, Jan 12th 2011, 00:00
expected
.
set
(
2011
,
0
,
12
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndNextRunIsThursday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 4"
;
// Thursdays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
ceil
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Thursday, Jan 20th 2011, 00:00
expected
.
set
(
2011
,
0
,
20
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndPreviousRunIsThursday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 4"
;
// Thursdays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
floor
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Thursday, Jan 13th 2011, 00:00
expected
.
set
(
2011
,
0
,
13
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndNextRunIsFriday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 5"
;
// Fridays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
ceil
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Friday, Jan 21th 2011, 00:00
expected
.
set
(
2011
,
0
,
21
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndPreviousRunIsFriday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 5"
;
// Fridays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
floor
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Friday, Jan 14th 2011, 00:00
expected
.
set
(
2011
,
0
,
14
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndNextRunIsSaturday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 6"
;
// Saturdays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
ceil
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Saturday, Jan 22th 2011, 00:00
expected
.
set
(
2011
,
0
,
22
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndPreviousRunIsSaturday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 0 * * 6"
;
// Saturdays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
floor
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Saturday, Jan 15th 2011, 00:00
expected
.
set
(
2011
,
0
,
15
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndNextRunIsNextSunday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
1
,
0
,
0
);
// Sunday, Jan 16th 2011, 01:00
final
String
cronStr
=
"0 0 * * 0"
;
// Sundays @00:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
ceil
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Sunday, Jan 22th 2011, 00:00
expected
.
set
(
2011
,
0
,
23
,
0
,
0
,
0
);
compare
(
expected
,
actual
);
}
@Test
public
void
isSundayAndNextRunIsPreviousSunday
()
throws
Exception
{
final
Calendar
cal
=
Calendar
.
getInstance
(
locale
);
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 1 * * 0"
;
// Sundays @01:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
actual
=
cron
.
floor
(
cal
);
final
Calendar
expected
=
Calendar
.
getInstance
();
// Expected next: Sunday, Jan 9th 2011, 01:00
expected
.
set
(
2011
,
0
,
9
,
1
,
0
,
0
);
compare
(
expected
,
actual
);
}
private
void
compare
(
final
Calendar
expected
,
final
Calendar
actual
)
{
final
DateFormat
f
=
DateFormat
.
getDateTimeInstance
();
final
String
msg
=
"Locale: "
+
locale
+
" FirstDayOfWeek: "
+
actual
.
getFirstDayOfWeek
()
+
" Expected: "
+
f
.
format
(
expected
.
getTime
())
+
" Actual: "
+
f
.
format
(
actual
.
getTime
());
assertEquals
(
msg
,
expected
.
get
(
Calendar
.
YEAR
),
actual
.
get
(
Calendar
.
YEAR
));
assertEquals
(
msg
,
expected
.
get
(
Calendar
.
MONTH
),
actual
.
get
(
Calendar
.
MONTH
));
assertEquals
(
msg
,
expected
.
get
(
Calendar
.
DAY_OF_MONTH
),
actual
.
get
(
Calendar
.
DAY_OF_MONTH
));
assertEquals
(
msg
,
expected
.
get
(
Calendar
.
HOUR
),
actual
.
get
(
Calendar
.
HOUR
));
assertEquals
(
msg
,
expected
.
get
(
Calendar
.
MINUTE
),
actual
.
get
(
Calendar
.
MINUTE
));
}
}
core/src/test/java/hudson/scheduler/CronTabTest.java
浏览文件 @
f8515e96
...
...
@@ -27,8 +27,11 @@ import antlr.ANTLRException;
import
java.text.DateFormat
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.Locale
;
import
junit.framework.TestCase
;
import
org.jvnet.hudson.test.Bug
;
import
org.jvnet.hudson.test.Url
;
import
static
java
.
util
.
Calendar
.
MONDAY
;
...
...
@@ -69,6 +72,48 @@ public class CronTabTest extends TestCase {
compare
(
new
GregorianCalendar
(
2010
,
7
,
1
,
0
,
0
),
x
.
ceil
(
c
));
}
/**
* Verifies that HUDSON-8656 never crops up again.
*/
@Url
(
"http://issues.hudson-ci.org/browse/HUDSON-8656"
)
public
void
testCeil4
()
throws
ANTLRException
{
final
Calendar
cal
=
Calendar
.
getInstance
(
new
Locale
(
"de"
,
"de"
));
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 23 * * 1-5"
;
// execute on weekdays @23:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
next
=
cron
.
ceil
(
cal
);
final
Calendar
expectedDate
=
Calendar
.
getInstance
();
expectedDate
.
set
(
2011
,
0
,
17
,
23
,
0
,
0
);
// Expected next: Monday, Jan 17th 2011, 23:00
assertEquals
(
expectedDate
.
get
(
Calendar
.
HOUR
),
next
.
get
(
Calendar
.
HOUR
));
assertEquals
(
expectedDate
.
get
(
Calendar
.
MINUTE
),
next
.
get
(
Calendar
.
MINUTE
));
assertEquals
(
expectedDate
.
get
(
Calendar
.
YEAR
),
next
.
get
(
Calendar
.
YEAR
));
assertEquals
(
expectedDate
.
get
(
Calendar
.
MONTH
),
next
.
get
(
Calendar
.
MONTH
));
assertEquals
(
expectedDate
.
get
(
Calendar
.
DAY_OF_MONTH
),
next
.
get
(
Calendar
.
DAY_OF_MONTH
));
// FAILS: is Monday, Jan 10th, 23:00
}
/**
* Verifies that HUDSON-8656 never crops up again.
*/
@Url
(
"http://issues.hudson-ci.org/browse/HUDSON-8656"
)
public
void
testCeil5
()
throws
ANTLRException
{
final
Calendar
cal
=
Calendar
.
getInstance
(
new
Locale
(
"de"
,
"at"
));
cal
.
set
(
2011
,
0
,
16
,
0
,
0
,
0
);
// Sunday, Jan 16th 2011, 00:00
final
String
cronStr
=
"0 23 * * 1-5"
;
// execute on weekdays @23:00
final
CronTab
cron
=
new
CronTab
(
cronStr
);
final
Calendar
next
=
cron
.
ceil
(
cal
);
final
Calendar
expectedDate
=
Calendar
.
getInstance
();
expectedDate
.
set
(
2011
,
0
,
17
,
23
,
0
,
0
);
// Expected next: Monday, Jan 17th 2011, 23:00
assertEquals
(
expectedDate
.
get
(
Calendar
.
HOUR
),
next
.
get
(
Calendar
.
HOUR
));
assertEquals
(
expectedDate
.
get
(
Calendar
.
MINUTE
),
next
.
get
(
Calendar
.
MINUTE
));
assertEquals
(
expectedDate
.
get
(
Calendar
.
YEAR
),
next
.
get
(
Calendar
.
YEAR
));
assertEquals
(
expectedDate
.
get
(
Calendar
.
MONTH
),
next
.
get
(
Calendar
.
MONTH
));
assertEquals
(
expectedDate
.
get
(
Calendar
.
DAY_OF_MONTH
),
next
.
get
(
Calendar
.
DAY_OF_MONTH
));
// FAILS: is Monday, Jan 10th, 23:00
}
public
void
testFloor1
()
throws
Exception
{
CronTab
x
=
new
CronTab
(
"30 * * * *"
);
Calendar
c
=
new
GregorianCalendar
(
2000
,
2
,
1
,
1
,
40
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录