提交 66bf21ba 编写于 作者: K kohsuke

Merged revisions 21385-21386 via svnmerge from

https://svn.dev.java.net/svn/hudson/branches/rc

........
  r21385 | kohsuke | 2009-09-02 15:41:39 -0700 (Wed, 02 Sep 2009) | 1 line
  
  Fixed a random test failure, which was caused by PingThread detecting communication problem while it's being orderly shut down.
........
  r21386 | kohsuke | 2009-09-02 15:41:57 -0700 (Wed, 02 Sep 2009) | 1 line
  
  indentation fix.
........


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21387 71c3de6d-444a-0410-be80-ed276b4c234a
上级 cad02234
......@@ -134,5 +134,11 @@ THE SOFTWARE.
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -394,7 +394,7 @@ public class Channel implements VirtualChannel, IChannel {
*/
/*package*/ synchronized void send(Command cmd) throws IOException {
if(outClosed)
throw new IOException("already closed");
throw new ChannelClosedException();
if(logger.isLoggable(Level.FINE))
logger.fine("Send "+cmd);
Channel old = Channel.setCurrent(this);
......
package hudson.remoting;
import java.io.IOException;
/**
* Indicates that the channel is already closed.
*
* @author Kohsuke Kawaguchi
*/
public class ChannelClosedException extends IOException {
public ChannelClosedException() {
super("channel is already closed");
}
}
......@@ -74,6 +74,8 @@ public abstract class PingThread extends Thread {
while((diff=nextCheck-System.currentTimeMillis())>0)
Thread.sleep(diff);
}
} catch (ChannelClosedException e) {
LOGGER.fine(getName()+" is closed. Terminating");
} catch (IOException e) {
onDead();
} catch (InterruptedException e) {
......@@ -87,6 +89,8 @@ public abstract class PingThread extends Thread {
try {
f.get(TIME_OUT,MILLISECONDS);
} catch (ExecutionException e) {
if (e.getCause() instanceof RequestAbortedException)
return; // connection has shut down orderly.
onDead();
} catch (TimeoutException e) {
onDead();
......
......@@ -243,8 +243,10 @@ abstract class Request<RSP extends Serializable,EXC extends Throwable> extends C
if(chainCause)
rsp.createdAt.initCause(createdAt);
if(!channel.isOutClosed())
channel.send(rsp);
synchronized (channel) {// expand the synchronization block of the send() method to a check
if(!channel.isOutClosed())
channel.send(rsp);
}
} catch (IOException e) {
// communication error.
// this means the caller will block forever
......
......@@ -29,11 +29,15 @@ import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.File;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.net.URLClassLoader;
import java.net.URL;
import org.apache.commons.io.output.TeeOutputStream;
/**
* Hides the logic of starting/stopping a channel for test.
*
......@@ -120,24 +124,30 @@ interface ChannelRunner {
proc = Runtime.getRuntime().exec("java -cp "+getClasspath()+" hudson.remoting.Launcher");
copier = new Copier("copier",proc.getErrorStream(),System.err);
copier = new Copier("copier",proc.getErrorStream(),System.out);
copier.start();
executor = Executors.newCachedThreadPool();
return new Channel("north", executor, proc.getInputStream(), proc.getOutputStream());
OutputStream out = proc.getOutputStream();
if (RECORD_OUTPUT) {
File f = File.createTempFile("remoting",".log");
System.out.println("Recording to "+f);
out = new TeeOutputStream(out,new FileOutputStream(f));
}
return new Channel("north", executor, proc.getInputStream(), out);
}
public void stop(Channel channel) throws Exception {
channel.close();
channel.join(10*1000);
System.out.println("north completed");
// System.out.println("north completed");
executor.shutdown();
copier.join();
int r = proc.waitFor();
System.out.println("south completed");
// System.out.println("south completed");
Assert.assertEquals("exit code should have been 0",0,r);
}
......@@ -156,5 +166,10 @@ interface ChannelRunner {
}
return buf.toString();
}
/**
* Record the communication to the remote node. Used during debugging.
*/
private static boolean RECORD_OUTPUT = false;
}
}
......@@ -23,18 +23,11 @@
*/
package hudson.remoting;
import junit.framework.TestCase;
import hudson.remoting.ChannelRunner.InProcess;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import hudson.remoting.ChannelRunner.InProcess;
/**
* Base class for remoting tests.
*
......@@ -46,6 +39,7 @@ public abstract class RmiTestBase extends TestCase {
private ChannelRunner channelRunner = new InProcess();
protected void setUp() throws Exception {
System.out.println("Starting "+getName());
channel = channelRunner.start();
}
......
......@@ -60,7 +60,7 @@ THE SOFTWARE.
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0-rc-5</version>
<version>1.0-rc-5</version>
<executions>
<execution>
<id>preset-packager</id>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册