Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-19544] Whether or not we manage to save an object with old d…
…ata, be sure to remove it from the list, and continue with other objects. Otherwise a bug like JENKINS-20950 can prevent *anything* from being saved, and holds references to all the old data.
- Loading branch information
Showing
3 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
test/src/test/java/hudson/diagnosis/OldDataMonitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2014 Jesse Glick. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package hudson.diagnosis; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import hudson.model.InvisibleAction; | ||
import java.util.Collections; | ||
import static org.junit.Assert.*; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Bug; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
public class OldDataMonitorTest { | ||
|
||
@Rule public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Bug(19544) | ||
@LocalData | ||
@Test public void robustness() throws Exception { | ||
OldDataMonitor odm = OldDataMonitor.get(r.jenkins); | ||
FreeStyleProject p = r.jenkins.getItemByFullName("busted", FreeStyleProject.class); | ||
assertNotNull(p); | ||
/* | ||
System.err.println(p.getActions()); | ||
for (Map.Entry<Saveable,OldDataMonitor.VersionRange> entry : odm.getData().entrySet()) { | ||
System.err.println(entry.getKey()); | ||
System.err.println(entry.getValue()); | ||
System.err.println(entry.getValue().extra); | ||
} | ||
*/ | ||
assertEquals(Collections.singleton(p), odm.getData().keySet()); | ||
odm.doDiscard(null, null); | ||
assertEquals(Collections.emptySet(), odm.getData().keySet()); | ||
// did not manage to save p, but at least we are not holding onto a reference to it anymore | ||
} | ||
|
||
public static final class BadAction extends InvisibleAction { | ||
private Object writeReplace() { | ||
throw new IllegalStateException("broken"); | ||
} | ||
} | ||
|
||
} |
Binary file added
BIN
+461 Bytes
test/src/test/resources/hudson/diagnosis/OldDataMonitorTest/robustness.zip
Binary file not shown.