ARTEMIS-4985 message priority occasionally broken

The test in this commit was distilled down from a much more complex
integration test that rarely reproduced the problem. It is short and
sweet and reproduces the problem every time.

The problem exists in the iterator's `remove()` method where it uses
`index` instead of `i` when calculating a new highest priority.
This commit is contained in:
Justin Bertram 2024-08-12 13:40:14 -05:00 committed by Timothy Bish
parent c442c9b7e6
commit ef3b5fa02c
2 changed files with 14 additions and 8 deletions

View File

@ -295,14 +295,8 @@ public class PriorityLinkedListImpl<E> implements PriorityLinkedList<E> {
lastIter.remove();
// This next statement would be the equivalent of:
// if (index == highestPriority && levels[index].size() == 0)
// However we have to keep checking all the previous levels
// otherwise we would cache a max that will not exist
// what would make us eventually having hasNext() returning false
// as a bug
// Part of the fix for HORNETQ-705
for (int i = index; i >= 0 && levels[index].size() == 0; i--) {
// If the last message in the current priority is removed then find the next highest
for (int i = index; i >= 0 && levels[i].size() == 0; i--) {
highestPriority = i;
}

View File

@ -881,6 +881,18 @@ public final class PriorityLinkedListTest {
iter.remove();
}
@Test
public void testMixupIterator3() {
list.addTail(b, 4);
list.addTail(c, 9);
LinkedListIterator<Wibble> iter = list.iterator();
assertTrue(iter.hasNext());
assertEquals(c, iter.next());
iter.remove();
list.addTail(a, 0);
assertTrue(iter.hasNext());
assertEquals(b, iter.next());
}
@Test
public void testPeek() {