mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-14 20:42:21 +00:00
test case for BulkChange
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11519 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
a0a6779fcb
commit
91156a3b4c
1 file changed
+92
@@ -0,0 +1,92 @@
|
||||
package hudson;
|
||||
|
||||
import hudson.model.Saveable;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Tests {@link BulkChange}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class BulkChangeTest extends TestCase {
|
||||
|
||||
private class Point implements Saveable {
|
||||
/**
|
||||
* Don't actually do any save, but just remember how many the actual I/O would have happened.
|
||||
*/
|
||||
int saveCount = 0;
|
||||
|
||||
int x,y;
|
||||
|
||||
public void setX(int x) throws IOException {
|
||||
this.x = x;
|
||||
save();
|
||||
}
|
||||
|
||||
public void setY(int y) throws IOException {
|
||||
this.y = y;
|
||||
save();
|
||||
}
|
||||
|
||||
public void set(int x, int y) throws IOException {
|
||||
setX(x);
|
||||
setY(y);
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
if(BulkChange.contains(this)) return;
|
||||
saveCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is no BulkChange, we should see two saves.
|
||||
*/
|
||||
public void testNoBulkChange() throws Exception {
|
||||
Point pt = new Point();
|
||||
pt.set(0,0);
|
||||
assertEquals(2,pt.saveCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* With a {@link BulkChange}, this will become just one save.
|
||||
*/
|
||||
public void testBulkChange() throws Exception {
|
||||
Point pt = new Point();
|
||||
BulkChange bc = new BulkChange(pt);
|
||||
try {
|
||||
pt.set(0,0);
|
||||
} finally {
|
||||
bc.commit();
|
||||
}
|
||||
assertEquals(1,pt.saveCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BulkChange}s can be nested.
|
||||
*/
|
||||
public void testNestedBulkChange() throws Exception {
|
||||
Point pt = new Point();
|
||||
Point _ = new Point();
|
||||
BulkChange bc1 = new BulkChange(pt);
|
||||
try {
|
||||
BulkChange bc2 = new BulkChange(_);
|
||||
try {
|
||||
BulkChange bc3 = new BulkChange(pt);
|
||||
try {
|
||||
pt.set(0,0);
|
||||
} finally {
|
||||
bc3.commit();
|
||||
}
|
||||
} finally {
|
||||
bc2.commit();
|
||||
}
|
||||
pt.set(0,0);
|
||||
} finally {
|
||||
bc1.commit();
|
||||
}
|
||||
assertEquals(1,pt.saveCount);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user