diff --git a/test/src/test/java/jenkins/model/lazy/LazyBuildMixInTest.java b/test/src/test/java/jenkins/model/lazy/LazyBuildMixInTest.java index 36b3890ee517bd403b759f9876dac0d31596d809..ce6dee7b36992d67aa4f3b19573dab9667eff490 100644 --- a/test/src/test/java/jenkins/model/lazy/LazyBuildMixInTest.java +++ b/test/src/test/java/jenkins/model/lazy/LazyBuildMixInTest.java @@ -26,19 +26,14 @@ package jenkins.model.lazy; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; -import java.lang.ref.SoftReference; -import java.util.ArrayList; -import java.util.List; -import static org.junit.Assert.*; - import hudson.model.listeners.RunListener; +import static org.junit.Assert.*; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.SleepBuilder; -import org.jvnet.hudson.test.TestExtension; public class LazyBuildMixInTest { @@ -58,7 +53,7 @@ public class LazyBuildMixInTest { assertEquals(null, b1.getPreviousBuild()); assertEquals(b1, b2.getPreviousBuild()); assertEquals(b2, b3.getPreviousBuild()); - assertEquals(1, BRHF.drop(b1)); + b1.getRunMixIn().createReference().clear(); b2.delete(); FreeStyleBuild b1a = b2.getPreviousBuild(); assertNotSame(b1, b1a); @@ -81,48 +76,13 @@ public class LazyBuildMixInTest { assertEquals(b1, b2.getPreviousBuild()); assertEquals(b2, b3.getPreviousBuild()); b2.delete(); - assertEquals(1, BRHF.drop(b1)); + b1.getRunMixIn().createReference().clear(); FreeStyleBuild b1a = b2.getPreviousBuild(); assertNotSame(b1, b1a); assertEquals(1, b1a.getNumber()); assertEquals(b3, b1a.getNextBuild()); } - /** - * Unlike the standard {@link SoftReference} this lets us simulate a referent disappearing at a specific time. - */ - @TestExtension public static final class BRHF implements BuildReference.HolderFactory { - private static final List> refs = new ArrayList>(); - private static final class BRH implements BuildReference.Holder { - R r; - BRH(R r) {this.r = r;} - @Override public R get() {return r;} - } - @Override public BuildReference.Holder make(R referent) { - BRH ref = new BRH(referent); - synchronized (refs) { - refs.add(ref); - } - return ref; - } - /** - * Simulates garbage collection of a referent. - * @return how many build references went null as a result - */ - static int drop(Object o) { - int count = 0; - synchronized (refs) { - for (BRH ref : refs) { - if (ref.r == o) { - ref.r = null; - count++; - } - } - } - return count; - } - } - @Bug(20662) @Test public void newRunningBuildRelationFromPrevious() throws Exception { FreeStyleProject p = r.createFreeStyleProject();