Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
758aedf8
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,发现更多精彩内容 >>
提交
758aedf8
编写于
2月 04, 2011
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
差异文件
Merge commit '
c628bdd3
'
* commit '
c628bdd3
': First pass at a fix for JENKINS-8592.
上级
46961022
c628bdd3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
75 addition
and
1 deletion
+75
-1
remoting/src/main/java/hudson/remoting/Pipe.java
remoting/src/main/java/hudson/remoting/Pipe.java
+14
-1
remoting/src/test/java/hudson/remoting/PipeTest.java
remoting/src/test/java/hudson/remoting/PipeTest.java
+61
-0
未找到文件。
remoting/src/main/java/hudson/remoting/Pipe.java
浏览文件 @
758aedf8
...
...
@@ -23,6 +23,7 @@
*/
package
hudson.remoting
;
import
java.io.FilterInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
...
...
@@ -92,7 +93,19 @@ public final class Pipe implements Serializable {
* Gets the reading end of the pipe.
*/
public
InputStream
getIn
()
{
return
in
;
return
new
FilterInputStream
(
in
)
{
@Override
public
void
close
()
throws
IOException
{
try
{
// Since closing the reading side does not stop the writing side. We read till the stream is done.
final
byte
[]
buffer
=
new
byte
[
4096
];
while
(
read
(
buffer
)
!=
-
1
)
{
}
}
finally
{
super
.
close
();
}
}
};
}
/**
...
...
remoting/src/test/java/hudson/remoting/PipeTest.java
浏览文件 @
758aedf8
...
...
@@ -24,9 +24,13 @@
package
hudson.remoting
;
import
hudson.remoting.ChannelRunner.InProcessCompatibilityMode
;
import
hudson.remoting.FastPipedInputStream.ClosedBy
;
import
junit.framework.Test
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.output.NullOutputStream
;
import
org.jvnet.hudson.test.Bug
;
import
org.jvnet.hudson.test.For
;
import
org.jvnet.hudson.test.Url
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInputStream
;
...
...
@@ -35,6 +39,9 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.Serializable
;
import
java.util.Arrays
;
import
java.util.logging.Handler
;
import
java.util.logging.LogRecord
;
import
java.util.logging.Logger
;
/**
* Test {@link Pipe}.
...
...
@@ -55,6 +62,60 @@ public class PipeTest extends RmiTestBase implements Serializable {
System
.
out
.
println
(
"result="
+
r
);
assertEquals
(
5
,
r
);
}
/**
* Helper class for testPartialReadQuietlyConsumesPipeOnClose.
*/
private
static
class
EventCounterHandler
extends
Handler
{
int
count
=
0
;
@Override
public
void
publish
(
final
LogRecord
record
)
{
if
(
ProxyOutputStream
.
class
.
getName
().
equals
(
record
.
getLoggerName
()))
{
Throwable
thrown
=
record
.
getThrown
();
while
(
thrown
!=
null
)
{
if
(
thrown
instanceof
ClosedBy
)
{
count
+=
1
;
break
;
}
thrown
=
thrown
.
getCause
();
}
}
}
@Override
public
void
flush
()
{
}
@Override
public
void
close
()
throws
SecurityException
{
}
public
int
getCount
()
{
return
count
;
}
}
/**
* This test should be reproducing the initial bug as reported in JENKINS-8592. The assert in this test is not the
* best and is fragile, but it is the best I can come up with.
*/
@Bug
(
8592
)
@For
(
Pipe
.
class
)
@Url
(
"http://issues.jenkins-ci.org/browse/JENKINS-8592"
)
public
void
testPartialReadQuietlyConsumesPipeOnClose
()
throws
Exception
{
final
EventCounterHandler
handler
=
new
EventCounterHandler
();
final
Logger
logger
=
Logger
.
getLogger
(
ProxyOutputStream
.
class
.
getName
());
logger
.
addHandler
(
handler
);
final
Pipe
p
=
Pipe
.
createRemoteToLocal
();
final
Future
<
Integer
>
f
=
channel
.
callAsync
(
new
WritingCallable
(
p
));
final
InputStream
in
=
p
.
getIn
();
assertEquals
(
in
.
read
(),
0
);
in
.
close
();
f
.
get
();
logger
.
removeHandler
(
handler
);
assertEquals
(
0
,
handler
.
getCount
());
}
private
static
class
WritingCallable
implements
Callable
<
Integer
,
IOException
>
{
private
final
Pipe
pipe
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录