Skip to content

Commit

Permalink
[FIXED JENKINS-22681] Fix of JENKINS-19418 should have used getById, …
Browse files Browse the repository at this point in the history
…not load, to avoid reloading the last build gratuitously.

(cherry picked from commit b6b7bfd)

Conflicts:
	changelog.html
  • Loading branch information
jglick authored and olivergondza committed May 14, 2014
1 parent 4c4ce9c commit 701045e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Expand Up @@ -509,7 +509,7 @@ public R get(int n) {
return getById(idOnDisk.get(lo-1));
case EXACT:
if (hi<=0) return null;
R r = load(idOnDisk.get(hi-1), null);
R r = getById(idOnDisk.get(hi-1));
if (r==null) return null;

int found = getNumberOf(r);
Expand Down
Expand Up @@ -149,6 +149,7 @@ public void search() {
assertNull(a.search(-99, Direction.DESC));
}

@Bug(19418)
@Test
public void searchExactWhenIndexedButSoftReferenceExpired() throws IOException {
final FakeMap m = localExpiredBuilder.add(1, "A").add(2, "B").make();
Expand All @@ -161,6 +162,24 @@ public void searchExactWhenIndexedButSoftReferenceExpired() throws IOException {
assertNull(m.search(0, Direction.EXACT));
}

@Bug(22681)
@Test public void exactSearchShouldNotReload() throws Exception {
FakeMap m = localBuilder.add(1, "A").add(2, "B").make();
assertNull(m.search(0, Direction.EXACT));
Build a = m.search(1, Direction.EXACT);
a.asserts(1, "A");
Build b = m.search(2, Direction.EXACT);
b.asserts(2, "B");
assertNull(m.search(0, Direction.EXACT));
assertSame(a, m.search(1, Direction.EXACT));
assertSame(b, m.search(2, Direction.EXACT));
assertNull(m.search(3, Direction.EXACT));
assertNull(m.search(0, Direction.EXACT));
assertSame(a, m.search(1, Direction.EXACT));
assertSame("#2 should not have been reloaded by searching for #3", b, m.search(2, Direction.EXACT));
assertNull(m.search(3, Direction.EXACT));
}

/**
* If load fails, search needs to gracefully handle it
*/
Expand Down
5 changes: 5 additions & 0 deletions core/src/test/java/jenkins/model/lazy/FakeMap.java
Expand Up @@ -82,4 +82,9 @@ public void asserts(int n, String id) {
assert this.n==n;
assert this.id.equals(id);
}

@Override public String toString() {
return "Build #" + n + " [" + id + "] @" + hashCode();
}

}

0 comments on commit 701045e

Please sign in to comment.