提交 04b15b9a 编写于 作者: K kohsuke

adding a test for pipe.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1299 71c3de6d-444a-0410-be80-ed276b4c234a
上级 d249d524
......@@ -25,8 +25,6 @@ public class Channel {
private final ObjectOutputStream oos;
/*package*/ final Executor executor;
private final ReaderThread reader;
/**
* If true, this data channel is already closed and
* no further calls are accepted.
......@@ -60,8 +58,7 @@ public class Channel {
this.executor = exec;
this.oos = new ObjectOutputStream(os);
this.ois = new ObjectInputStream(is);
this.reader = new ReaderThread(name);
reader.start();
new ReaderThread(name).start();
}
/**
......@@ -70,7 +67,8 @@ public class Channel {
/*package*/ synchronized void send(Command cmd) throws IOException {
if(closed)
throw new IOException("already closed");
logger.fine("Send "+cmd);
if(logger.isLoggable(Level.FINE))
logger.fine("Send "+cmd);
Channel old = Channel.setCurrent(this);
try {
oos.writeObject(cmd);
......@@ -207,7 +205,8 @@ public class Channel {
} finally {
Channel.setCurrent(old);
}
logger.fine("Received "+cmd);
if(logger.isLoggable(Level.FINE))
logger.fine("Received "+cmd);
cmd.execute(Channel.this);
} catch (ClassNotFoundException e) {
logger.log(Level.SEVERE, "Unabled to read a command",e);
......
......@@ -132,6 +132,10 @@ final class RemoteInvocationHandler implements InvocationHandler, Serializable {
}
return null;
}
public String toString() {
return "RPCRequest("+oid+","+methodName+")";
}
}
private static final Object[] EMPTY_ARRAY = new Object[0];
......
......@@ -41,7 +41,7 @@ final class Response<RSP,EXC extends Throwable> extends Command {
}
public String toString() {
return "Response[retVal="+toString(returnValue)+",exception="+toString(exception);
return "Response[retVal="+toString(returnValue)+",exception="+toString(exception)+"]";
}
private static String toString(Object o) {
......
package hudson.remoting;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.concurrent.Future;
/**
* @author Kohsuke Kawaguchi
*/
public class PipeTest extends RmiTestBase {
/**
* Test the "remote-write local-read" pipe.
*/
public void testRemoteWrite() throws Exception {
Pipe p = Pipe.create();
Future<Integer> f = channel.callAsync(new WritingCallable(p));
InputStream in = p.getIn();
for( int cnt=0; cnt<256*256; cnt++ )
assertEquals(cnt/256,in.read());
assertEquals(-1,in.read());
in.close();
int r = f.get();
System.out.println("result=" + r);
assertEquals(5,r);
}
private static class WritingCallable implements Callable<Integer, IOException> {
private final Pipe pipe;
public WritingCallable(Pipe pipe) {
this.pipe = pipe;
}
public Integer call() throws IOException {
OutputStream os = pipe.getOut();
byte[] buf = new byte[384];
for( int i=0; i<256; i++ ) {
Arrays.fill(buf,(byte)i);
os.write(buf,0,256);
}
os.close();
return 5;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册