Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-26718] OldDataMonitor: Handle poorly written project types #1557

Merged
merged 1 commit into from Feb 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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