Skip to content

Commit

Permalink
[JENKINS-15533] testing if the lazy loading can gracefully tolerate a…
Browse files Browse the repository at this point in the history
… RuntimeException during unmarshalling.

At least in the current version this working as expected
  • Loading branch information
kohsuke committed Mar 13, 2013
1 parent 6f206be commit c7ad5e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java
Expand Up @@ -210,6 +210,16 @@ public final boolean baseDirInitialized() {
return dir != null;
}

/**
* Let go of all the loaded references.
*
* This is a bit more sophisticated version of forcing GC.
* Primarily for debugging and testing lazy loading behaviour.
*/
public void purgeCache() {
index = new Index();
}

private void loadIdOnDisk() {
String[] buildDirs = dir.list(createDirectoryFilter());
if (buildDirs==null) {
Expand Down
27 changes: 27 additions & 0 deletions test/src/test/groovy/hudson/model/RunMapTest.groovy
Expand Up @@ -3,6 +3,7 @@ package hudson.model
import org.jvnet.hudson.test.Bug
import org.jvnet.hudson.test.HudsonTestCase
import org.jvnet.hudson.test.SleepBuilder
import org.jvnet.hudson.test.TestEnvironment

import javax.xml.transform.stream.StreamSource

Expand Down Expand Up @@ -40,4 +41,30 @@ class RunMapTest extends HudsonTestCase {
assertSame b1.nextBuild,b2
assertSame b2.previousBuild,b1
}

/**
* Testing if the lazy loading can gracefully tolerate a RuntimeException during unmarshalling.
*/
@Bug(15533)
public void testRuntimeExceptionInUnmarshalling() {
def p = createFreeStyleProject()
def b = assertBuildStatusSuccess(p.scheduleBuild2(0))
b.addAction(new BombAction());
b.save()

p._getRuns().purgeCache()
assert p.getBuildByNumber(b.number)==null
assert bombed
}

public static class BombAction extends InvisibleAction {
public Object readResolve() {
TestEnvironment.get().testCase.bombed = true

This comment has been minimized.

Copy link
@jglick

jglick Mar 15, 2013

Member

Cumbersome, and will complicate migration to JUnit 4; simpler to just use a static field.

throw new NullPointerException();
}
}

boolean bombed;


}

0 comments on commit c7ad5e9

Please sign in to comment.