use of io.netty.util.internal.ThreadLocalRandom in project netty by netty.
the class LongPriorityQueueTest method internalRemoveMustPreserveOrder.
@Test
public void internalRemoveMustPreserveOrder() {
ThreadLocalRandom tlr = ThreadLocalRandom.current();
int initialValues = tlr.nextInt(1, 30);
ArrayList<Long> values = new ArrayList<Long>();
LongPriorityQueue pq = new LongPriorityQueue();
for (int i = 0; i < initialValues; i++) {
long value = tlr.nextLong(0, Long.MAX_VALUE);
pq.offer(value);
values.add(value);
}
long toRemove = values.get(values.size() / 2);
values.remove(toRemove);
pq.remove(toRemove);
Collections.sort(values);
for (Long value : values) {
assertThat(pq.poll()).isEqualTo(value);
}
assertTrue(pq.isEmpty());
assertThat(pq.poll()).isEqualTo(LongPriorityQueue.NO_VALUE);
}
Aggregations