Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-20769] adding a test case that reproduces the problem.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Sorry, something went wrong. |
||
} | ||
}); | ||
} | ||
} | ||
|
||
private Object writeReplace() { | ||
return null; | ||
} | ||
} |
MemoryAssert
injenkinsci/jenkins/test
is more thorough.