diff --git a/core/src/test/java/hudson/FilePathTest.java b/core/src/test/java/hudson/FilePathTest.java index 1736a09075dbdad48b5f8618c90ca4cdb6fc2e91..ddac863fb2749e0e248e099aeef04891a89573d5 100644 --- a/core/src/test/java/hudson/FilePathTest.java +++ b/core/src/test/java/hudson/FilePathTest.java @@ -24,26 +24,62 @@ package hudson; import junit.framework.TestCase; +import hudson.remoting.Channel; +import hudson.util.NullStream; + +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.io.File; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; /** * @author Kohsuke Kawaguchi */ -public class FilePathTest extends /*RmiTestBase*/ TestCase { - public void testDummy() { - // TODO: figure out how to reuse test code from the remoting module. - // currently it fails because the remoting.jar is signed but - // test code is not. +public class FilePathTest extends TestCase { + /** + * Two channels that are connected to each other, but shares the same classloader. + */ + private Channel french, british; + private ExecutorService executors = Executors.newCachedThreadPool(); + + @Override + protected void setUp() throws Exception { + super.setUp(); + final PipedInputStream p1i = new PipedInputStream(); + final PipedInputStream p2i = new PipedInputStream(); + final PipedOutputStream p1o = new PipedOutputStream(p1i); + final PipedOutputStream p2o = new PipedOutputStream(p2i); + + Future f1 = executors.submit(new Callable() { + public Channel call() throws Exception { + return new Channel("This side of the channel", executors, p1i, p2o); + } + }); + Future f2 = executors.submit(new Callable() { + public Channel call() throws Exception { + return new Channel("The other side of the channel", executors, p2i, p1o); + } + }); + french = f1.get(); + british = f2.get(); + } + + @Override + protected void tearDown() throws Exception { + french.close(); + british.close(); + french.join(); + british.join(); + executors.shutdown(); + } + + public void testCopyTo() throws Exception { + File tmp = File.createTempFile("tmp",""); + FilePath f = new FilePath(french,tmp.getPath()); + f.copyTo(new NullStream()); } - ///** - // * Copy zero files. - // */ - //public void testEmptyCopy() throws Exception { - // File src = Util.createTempDir(); - // File dst = Util.createTempDir(); - // src.deleteOnExit(); - // dst.deleteOnExit(); - // - // new FilePath(src).copyRecursiveTo("**/*",new FilePath(channel,dst.getPath())); - //} } diff --git a/remoting/src/main/java/hudson/remoting/ProxyOutputStream.java b/remoting/src/main/java/hudson/remoting/ProxyOutputStream.java index cec6b5bfe380d75795f2655509c0df40454a320d..265be033969747105f1439dd26d22b49f8304f69 100644 --- a/remoting/src/main/java/hudson/remoting/ProxyOutputStream.java +++ b/remoting/src/main/java/hudson/remoting/ProxyOutputStream.java @@ -71,6 +71,8 @@ final class ProxyOutputStream extends OutputStream { synchronized void connect(Channel channel, int oid) throws IOException { if(this.channel!=null) throw new IllegalStateException("Cannot connect twice"); + if(oid==0) + throw new IllegalArgumentException("oid=0"); this.channel = channel; this.oid = oid; diff --git a/remoting/src/main/java/hudson/remoting/RemoteOutputStream.java b/remoting/src/main/java/hudson/remoting/RemoteOutputStream.java index e80272f797f7719689f3e47f856598e15c619982..ef20d970b87ec93a92007ba7057581fa9227120f 100644 --- a/remoting/src/main/java/hudson/remoting/RemoteOutputStream.java +++ b/remoting/src/main/java/hudson/remoting/RemoteOutputStream.java @@ -73,6 +73,8 @@ public final class RemoteOutputStream extends OutputStream implements Serializab private transient OutputStream core; public RemoteOutputStream(OutputStream core) { + if(core==null) + throw new IllegalArgumentException(); this.core = core; }