Search in sources :

Example 6 with ThreadLocalRandom

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);
}
Also used : ArrayList(java.util.ArrayList) ThreadLocalRandom(io.netty.util.internal.ThreadLocalRandom) Test(org.junit.jupiter.api.Test)

Aggregations

ThreadLocalRandom (io.netty.util.internal.ThreadLocalRandom)6 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)1 OfLong (java.util.PrimitiveIterator.OfLong)1 Location (org.bukkit.Location)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1