Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
9b419100
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,发现更多精彩内容 >>
未验证
提交
9b419100
编写于
12月 08, 2017
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AtmostOneTaskExecutorTest
上级
a8251f66
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
66 deletion
+49
-66
core/pom.xml
core/pom.xml
+0
-19
core/src/test/groovy/jenkins/util/AtmostOneTaskExecutorTest.groovy
...test/groovy/jenkins/util/AtmostOneTaskExecutorTest.groovy
+0
-47
core/src/test/java/jenkins/util/AtmostOneTaskExecutorTest.java
...src/test/java/jenkins/util/AtmostOneTaskExecutorTest.java
+49
-0
未找到文件。
core/pom.xml
浏览文件 @
9b419100
...
...
@@ -796,25 +796,6 @@ THE SOFTWARE.
</archive>
</configuration>
</plugin>
<plugin>
<!-- run unit test in src/test/java -->
<groupId>
org.codehaus.gmaven
</groupId>
<artifactId>
gmaven-plugin
</artifactId>
<executions>
<execution>
<goals>
<goal>
generateTestStubs
</goal>
<goal>
testCompile
</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>
org.codehaus.groovy
</groupId>
<artifactId>
groovy-all
</artifactId>
<version>
${groovy.version}
</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
findbugs-maven-plugin
</artifactId>
...
...
core/src/test/groovy/jenkins/util/AtmostOneTaskExecutorTest.groovy
已删除
100644 → 0
浏览文件 @
a8251f66
package
jenkins.util
import
hudson.util.OneShotEvent
import
org.junit.Test
import
java.util.concurrent.Callable
import
java.util.concurrent.Executors
import
java.util.concurrent.atomic.AtomicInteger
/**
*
*
* @author Kohsuke Kawaguchi
*/
class
AtmostOneTaskExecutorTest
{
def
counter
=
new
AtomicInteger
()
def
lock
=
new
OneShotEvent
()
@Test
public
void
doubleBooking
()
{
def
f1
,
f2
;
def
base
=
Executors
.
newCachedThreadPool
()
def
es
=
new
AtmostOneTaskExecutor
(
base
,
{
->
counter
.
incrementAndGet
()
lock
.
block
()
}
as
Callable
);
f1
=
es
.
submit
()
while
(
counter
.
get
()
==
0
)
;
// spin lock until executor gets to the choking point
f2
=
es
.
submit
()
// this should hang
Thread
.
sleep
(
500
)
// make sure the 2nd task is hanging
assert
counter
.
get
()
==
1
assert
!
f2
.
isDone
()
lock
.
signal
()
// let the first one go
f1
.
get
();
// first one should complete
// now 2nd one gets going and hits the choke point
f2
.
get
()
assert
counter
.
get
()==
2
}
}
core/src/test/java/jenkins/util/AtmostOneTaskExecutorTest.java
0 → 100644
浏览文件 @
9b419100
package
jenkins.util
;
import
hudson.util.OneShotEvent
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
public
class
AtmostOneTaskExecutorTest
{
@SuppressWarnings
(
"empty-statement"
)
@Test
public
void
doubleBooking
()
throws
Exception
{
AtomicInteger
counter
=
new
AtomicInteger
();
OneShotEvent
lock
=
new
OneShotEvent
();
Future
<?>
f1
,
f2
;
ExecutorService
base
=
Executors
.
newCachedThreadPool
();
AtmostOneTaskExecutor
<?>
es
=
new
AtmostOneTaskExecutor
<
Void
>(
base
,
()
->
{
counter
.
incrementAndGet
();
try
{
lock
.
block
();
}
catch
(
InterruptedException
x
)
{
assert
false
:
x
;
}
return
null
;
});
f1
=
es
.
submit
();
while
(
counter
.
get
()
==
0
)
{
// spin lock until executor gets to the choking point
}
f2
=
es
.
submit
();
// this should hang
Thread
.
sleep
(
500
);
// make sure the 2nd task is hanging
assertEquals
(
1
,
counter
.
get
());
assertFalse
(
f2
.
isDone
());
lock
.
signal
();
// let the first one go
f1
.
get
();
// first one should complete
// now 2nd one gets going and hits the choke point
f2
.
get
();
assertEquals
(
2
,
counter
.
get
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录