Skip to content

Commit

Permalink
Fail when trying to add more than 2 entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpountz committed Dec 16, 2024
1 parent 19f1b88 commit 40def5a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ public DisiWrapper topList() {
public DisiWrapper add(DisiWrapper entry) {
if (top == null) {
return top = entry;
} else {
} else if (top2 == null) {
top2 = entry;
return updateTop();
} else {
throw new IllegalStateException("Trying to add a 3rd element to a DisiPriorityQueue configured with a max size of 2");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void testDisiPriorityQueue2() throws IOException {
Random r = random();
DisiWrapper w1 = wrapper(randomDisi(r));
DisiWrapper w2 = wrapper(randomDisi(r));
DisiWrapper w3 = wrapper(randomDisi(r));

DisiPriorityQueue pq = DisiPriorityQueue.ofMaxSize(2);
w1.doc = 1;
Expand All @@ -42,6 +43,7 @@ public void testDisiPriorityQueue2() throws IOException {
assertSame(w2, pq.add(w2));
assertSame(w2, pq.top());
assertEquals(2, pq.size());
expectThrows(IllegalStateException.class, () -> pq.add(w3));

w2.doc = 1;
assertSame(w2, pq.updateTop());
Expand Down

0 comments on commit 40def5a

Please sign in to comment.