Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1557 from recampbell/JENKINS-26718
[JENKINS-26718] OldDataMonitor: Handle poorly written project types
  • Loading branch information
recampbell committed Feb 2, 2015
2 parents 144a6da + 327f778 commit d6d96e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/hudson/diagnosis/OldDataMonitor.java
Expand Up @@ -355,10 +355,12 @@ private interface SaveableReference {

private static SaveableReference referTo(Saveable s) {
if (s instanceof Run) {
return new RunSaveableReference((Run) s);
} else {
return new SimpleSaveableReference(s);
Job parent = ((Run) s).getParent();
if (Jenkins.getInstance().getItemByFullName(parent.getFullName()) == parent) {
return new RunSaveableReference((Run) s);
}
}
return new SimpleSaveableReference(s);
}

private static final class SimpleSaveableReference implements SaveableReference {
Expand Down
22 changes: 22 additions & 0 deletions test/src/test/java/hudson/diagnosis/OldDataMonitorTest.java
Expand Up @@ -41,11 +41,16 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.Saveable;
import hudson.model.listeners.SaveableListener;
import jenkins.model.Jenkins;
import jenkins.model.lazy.BuildReference;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -56,6 +61,8 @@
import org.jvnet.hudson.test.recipes.LocalData;
import org.kohsuke.stapler.Stapler;

import javax.annotation.Nonnull;

public class OldDataMonitorTest {

static {
Expand Down Expand Up @@ -149,6 +156,21 @@ public Void call() throws Exception {

}

@Issue("JENKINS-26718")
@Test public void unlocatableRun() throws Exception {
OldDataMonitor odm = OldDataMonitor.get(r.jenkins);
FreeStyleProject p = mock(FreeStyleProject.class);
when(p.getParent()).thenReturn(Jenkins.getInstance());
when(p.getFullName()).thenReturn("notfound");
FreeStyleBuild build = new FreeStyleBuild(p);
odm.report(build, (String) null);

assertEquals(Collections.singleton(build), odm.getData().keySet());
odm.doDiscard(null, null);
assertEquals(Collections.emptySet(), odm.getData().keySet());

}

public static final class BadAction extends InvisibleAction {
private Object writeReplace() {
throw new IllegalStateException("broken");
Expand Down

0 comments on commit d6d96e1

Please sign in to comment.