Skip to content
Permalink
Browse files

Merge pull request #696 from johnou/JENKINS-15156

[FIXED JENKINS-15156] Initialize AbstractLazyLoadRunMap.dir for newly created jobs.
  • Loading branch information
jglick committed Feb 7, 2013
2 parents e43e5f3 + fe95fc5 commit 25f4c60f967da16607f4653a291c37c9383a301d
@@ -162,7 +162,7 @@
* {@link Run#getPreviousBuild()}
*/
@Restricted(NoExternalUse.class)
protected transient RunMap<R> builds = new RunMap<R>();
protected transient RunMap<R> builds;

/**
* The quiet period. Null to delegate to the system default.
@@ -271,17 +271,15 @@ public void onCreatedFromScratch() {
super.onCreatedFromScratch();
// solicit initial contributions, especially from TransientProjectActionFactory
updateTransientActions();
assert builds == null;
builds = createBuildRunMap();
}

@Override
public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
super.onLoad(parent, name);

RunMap<R> builds = new RunMap<R>(getBuildDir(), new Constructor<R>() {
public R create(File dir) throws IOException {
return loadBuild(dir);
}
});
RunMap<R> builds = createBuildRunMap();
if (this.builds!=null) {
// if we are reloading, keep all those that are still building intact
for (R r : this.builds.getLoadedBuilds().values()) {
@@ -300,6 +298,14 @@ public R create(File dir) throws IOException {
updateTransientActions();
}

private RunMap<R> createBuildRunMap() {
return new RunMap<R>(getBuildDir(), new Constructor<R>() {
public R create(File dir) throws IOException {
return loadBuild(dir);
}
});
}

private synchronized List<Trigger<?>> triggers() {
if (triggers == null) {
triggers = new Vector<Trigger<?>>();
@@ -203,8 +203,8 @@ protected void initBaseDir(File dir) {
private void loadIdOnDisk() {
String[] buildDirs = dir.list(createDirectoryFilter());
if (buildDirs==null) {
// the job may have just been created
buildDirs=EMPTY_STRING_ARRAY;
LOGGER.log(Level.WARNING, "failed to load list of builds from {0}", dir);
}
// wrap into ArrayList to enable mutation
Arrays.sort(buildDirs);
@@ -625,6 +625,7 @@ protected R load(int n, Index editInPlace) {


protected R load(String id, Index editInPlace) {
assert dir != null;
R v = load(new File(dir, id), editInPlace);
if (v==null && editInPlace!=null) {
// remember the failure.
@@ -27,6 +27,7 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
@@ -128,4 +129,20 @@ public static void assertHeapUsage(Object o, int max) throws Exception {
return elements;
}

/**
* Forces GC by causing an OOM and then verifies the given {@link WeakReference} has been garbage collected.
* @param reference object used to verify garbage collection.
*/
public static void assertGC(WeakReference<?> reference) {
Set<Object[]> objects = new HashSet<Object[]>();
while (true) {
try {
objects.add(new Object[1024]);
} catch (OutOfMemoryError ignore) {
break;
}
}
assertTrue(reference.get() == null);
}

}
@@ -41,12 +41,14 @@
import java.io.IOException;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.MemoryAssert;
import org.jvnet.hudson.test.recipes.PresetData;
import org.jvnet.hudson.test.recipes.PresetData.DataSet;

import java.io.File;
import java.util.concurrent.Future;
import org.apache.commons.io.FileUtils;
import java.lang.ref.WeakReference;

/**
* @author Kohsuke Kawaguchi
@@ -280,4 +282,12 @@ public void testSymlinkForPostBuildFailure() throws Exception {
assertSymlinkForBuild(lastSuccessful, 1);
assertSymlinkForBuild(lastStable, 1);
}

@Bug(15156)
public void testGetBuildAfterGC() throws Exception {
FreeStyleProject job = createFreeStyleProject();
job.scheduleBuild2(0, new Cause.UserIdCause()).get();
MemoryAssert.assertGC(new WeakReference(job.getLastBuild()));
assertTrue(job.getLastBuild() != null);
}
}

0 comments on commit 25f4c60

Please sign in to comment.
You can’t perform that action at this time.