Skip to content
Permalink
Browse files
[JENKINS-20769] adding a test case that reproduces the problem.
  • Loading branch information
kohsuke committed Mar 27, 2014
1 parent d1e0fe0 commit e498f5aa99af88d5d2e621fbb1e85b2d6306e61f
Showing with 66 additions and 0 deletions.
  1. +66 −0 src/test/java/hudson/remoting/ProxyWriterTest.java
@@ -0,0 +1,66 @@
package hudson.remoting;

import org.jvnet.hudson.test.Bug;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;

/**
* @author Kohsuke Kawaguchi
*/
public class ProxyWriterTest extends RmiTestBase implements Serializable {
ByteArrayOutputStream log = new ByteArrayOutputStream();
StreamHandler logRecorder = new StreamHandler(log,new SimpleFormatter());
Logger logger = Logger.getLogger(Channel.class.getName());

@Override
protected void setUp() throws Exception {
super.setUp();
logger.addHandler(logRecorder);
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
logger.removeHandler(logRecorder);
}


@Bug(20769)
public void testRemoteGC() throws InterruptedException, IOException {
StringWriter sw = new StringWriter();
final RemoteWriter w = new RemoteWriter(sw);

channel.call(new Callable<Void, IOException>() {
public Void call() throws IOException {
w.write("hello");
return null;
}
});

// induce a GC. There's no good reliable way to do this,
// and if GC doesn't happen within this loop, the test can pass
// even when the underlying problem exists.
for (int i=0; i<50; i++) {
logRecorder.flush();
assertTrue("There shouldn't be any errors: " + log.toString(), log.size() == 0);

Thread.sleep(100);
channel.call(new Callable<Void, IOException>() {
public Void call() throws IOException {
System.gc();
return null;

This comment has been minimized.

Copy link
@jglick

jglick Mar 27, 2014

Member

MemoryAssert in jenkinsci/jenkins/test is more thorough.

}
});
}
}

private Object writeReplace() {
return null;
}
}

0 comments on commit e498f5a

Please sign in to comment.