Skip to content

Commit

Permalink
Merge pull request #1872 from tfennelly/bh-pagination-daniel
Browse files Browse the repository at this point in the history
[FIX JENKINS-30899] Build History Pagination/Search fixes
  • Loading branch information
daniel-beck committed Oct 16, 2015
2 parents 6aba76d + e557880 commit 2dd658d
Show file tree
Hide file tree
Showing 12 changed files with 1,604 additions and 42 deletions.
12 changes: 4 additions & 8 deletions core/src/main/java/jenkins/widgets/HistoryPageEntry.java
Expand Up @@ -59,14 +59,10 @@ protected static long getEntryId(@Nonnull Object entry) {
return ((Queue.Item) entry).getId();
} else if (entry instanceof Run) {
Run run = (Run) entry;
long queueId = run.getQueueId();
if (queueId == Run.QUEUE_ID_UNKNOWN) {
// Backward compatibility. This is a run from before the Queue.Item IDs
// were mapped onto their resulting Run instance.
return (Integer.MIN_VALUE + run.getNumber());
} else {
return queueId;
}
return (Long.MIN_VALUE + run.getNumber());
} else if (entry instanceof Number) {
// Used for testing purposes because of JENKINS-30899 and JENKINS-30909
return (Long.MIN_VALUE + ((Number) entry).longValue());
} else {
return Run.QUEUE_ID_UNKNOWN;
}
Expand Down
16 changes: 9 additions & 7 deletions core/src/main/java/jenkins/widgets/HistoryPageFilter.java
Expand Up @@ -227,18 +227,20 @@ private long getNextBuildNumber(@Nonnull T entry) {
}

private void addQueueItem(Queue.Item item) {
updateNewestOldest(item.getId());
queueItems.add(new HistoryPageEntry(item));
HistoryPageEntry entry = new HistoryPageEntry(item);
queueItems.add(entry);
updateNewestOldest(entry.getEntryId());
}

private void addRun(Run run) {
updateNewestOldest(run.getQueueId());
runs.add(new HistoryPageEntry(run));
HistoryPageEntry entry = new HistoryPageEntry(run);
runs.add(entry);
updateNewestOldest(entry.getEntryId());
}

private void updateNewestOldest(long queueId) {
newestOnPage = Math.max(newestOnPage, queueId);
oldestOnPage = Math.min(oldestOnPage, queueId);
private void updateNewestOldest(long entryId) {
newestOnPage = Math.max(newestOnPage, entryId);
oldestOnPage = Math.min(oldestOnPage, entryId);
}

private boolean add(T entry) {
Expand Down
43 changes: 24 additions & 19 deletions core/src/test/java/jenkins/widgets/HistoryPageFilterTest.java
Expand Up @@ -70,7 +70,7 @@ public void test_latest_partial_page() throws IOException {
itemList.addAll(newQueueItems(3, 4));

// want to make sure the list items are ordered by id in descending order
Assert.assertEquals(1, HistoryPageEntry.getEntryId(itemList.get(0)));
Assert.assertEquals(HistoryPageEntry.getEntryId(1), HistoryPageEntry.getEntryId(itemList.get(0)));
historyPageFilter.add(itemList);
Assert.assertEquals(4, HistoryPageEntry.getEntryId(itemList.get(0)));

Expand All @@ -82,9 +82,9 @@ public void test_latest_partial_page() throws IOException {
Assert.assertEquals(4, historyPageFilter.queueItems.get(0).getEntryId());
Assert.assertEquals(4, historyPageFilter.newestOnPage);
Assert.assertEquals(3, historyPageFilter.queueItems.get(1).getEntryId());
Assert.assertEquals(2, historyPageFilter.runs.get(0).getEntryId());
Assert.assertEquals(1, historyPageFilter.runs.get(1).getEntryId());
Assert.assertEquals(1, historyPageFilter.oldestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(2), historyPageFilter.runs.get(0).getEntryId());
Assert.assertEquals(HistoryPageEntry.getEntryId(1), historyPageFilter.runs.get(1).getEntryId());
Assert.assertEquals(HistoryPageEntry.getEntryId(1), historyPageFilter.oldestOnPage);
}

/**
Expand All @@ -107,7 +107,7 @@ public void test_latest_longer_list() throws IOException {

Assert.assertEquals(12, historyPageFilter.queueItems.get(0).getEntryId());
Assert.assertEquals(12, historyPageFilter.newestOnPage);
Assert.assertEquals(10, historyPageFilter.runs.get(0).getEntryId());
Assert.assertEquals(HistoryPageEntry.getEntryId(10), historyPageFilter.runs.get(0).getEntryId());
}

/**
Expand All @@ -126,8 +126,8 @@ public void test_olderThan_gt_newest() throws IOException {
Assert.assertEquals(true, historyPageFilter.hasDownPage);
Assert.assertEquals(5, historyPageFilter.runs.size());

Assert.assertEquals(10, historyPageFilter.newestOnPage);
Assert.assertEquals(6, historyPageFilter.oldestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(10), historyPageFilter.newestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(6), historyPageFilter.oldestOnPage);
}

/**
Expand Down Expand Up @@ -165,8 +165,8 @@ public void test_olderThan_leaving_part_page() throws IOException {
// Should only be 3 runs on the page (oldest 3)
Assert.assertEquals(3, historyPageFilter.runs.size());

Assert.assertEquals(3, historyPageFilter.newestOnPage);
Assert.assertEquals(1, historyPageFilter.oldestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(3), historyPageFilter.newestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(1), historyPageFilter.oldestOnPage);
}

/**
Expand All @@ -184,8 +184,8 @@ public void test_olderThan_mid_page() throws IOException {
Assert.assertEquals(true, historyPageFilter.hasDownPage);
Assert.assertEquals(5, historyPageFilter.runs.size());

Assert.assertEquals(7, historyPageFilter.newestOnPage);
Assert.assertEquals(3, historyPageFilter.oldestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(7), historyPageFilter.newestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(3), historyPageFilter.oldestOnPage);
}

/**
Expand Down Expand Up @@ -220,8 +220,8 @@ public void test_newerThan_lt_oldest() throws IOException {
Assert.assertEquals(false, historyPageFilter.hasDownPage);
Assert.assertEquals(5, historyPageFilter.runs.size());

Assert.assertEquals(5, historyPageFilter.newestOnPage);
Assert.assertEquals(1, historyPageFilter.oldestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(5), historyPageFilter.newestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(1), historyPageFilter.oldestOnPage);
}

/**
Expand All @@ -239,8 +239,8 @@ public void test_newerThan_near_oldest() throws IOException {
Assert.assertEquals(true, historyPageFilter.hasDownPage);
Assert.assertEquals(5, historyPageFilter.runs.size());

Assert.assertEquals(8, historyPageFilter.newestOnPage);
Assert.assertEquals(4, historyPageFilter.oldestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(8), historyPageFilter.newestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(4), historyPageFilter.oldestOnPage);
}

/**
Expand All @@ -260,8 +260,8 @@ public void test_newerThan_near_newest() throws IOException {
Assert.assertEquals(true, historyPageFilter.hasDownPage);
Assert.assertEquals(5, historyPageFilter.runs.size());

Assert.assertEquals(10, historyPageFilter.newestOnPage);
Assert.assertEquals(6, historyPageFilter.oldestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(10), historyPageFilter.newestOnPage);
Assert.assertEquals(HistoryPageEntry.getEntryId(6), historyPageFilter.oldestOnPage);
}

private List<ModelObject> newQueueItems(long startId, long endId) {
Expand All @@ -283,9 +283,9 @@ private List<ModelObject> newRuns(long startId, long endId) throws IOException {
private HistoryPageFilter<ModelObject> newPage(int maxEntries, Long newerThan, Long olderThan) {
HistoryPageFilter<ModelObject> pageFilter = new HistoryPageFilter<ModelObject>(maxEntries);
if (newerThan != null) {
pageFilter.setNewerThan(newerThan);
pageFilter.setNewerThan(HistoryPageEntry.getEntryId(newerThan));
} else if (olderThan != null) {
pageFilter.setOlderThan(olderThan);
pageFilter.setOlderThan(HistoryPageEntry.getEntryId(olderThan));
}
return pageFilter;
}
Expand Down Expand Up @@ -318,5 +318,10 @@ public boolean isBuilding() {
public long getQueueId() {
return queueId;
}

@Override
public int getNumber() {
return (int) queueId;
}
}
}

0 comments on commit 2dd658d

Please sign in to comment.