@Test public void testPriorityQueue() throws InterruptedException { PriorityCompactionQueue pq = new PriorityCompactionQueue(); HRegion r1 = new DummyHRegion("r1"); HRegion r2 = new DummyHRegion("r2"); HRegion r3 = new DummyHRegion("r3"); HRegion r4 = new DummyHRegion("r4"); HRegion r5 = new DummyHRegion("r5"); addRegion(pq, r1, 0); addRegion(pq, r2, 0); addRegion(pq, r3, 0); addRegion(pq, r4, 0); addRegion(pq, r5, 0); getAndCheckRegion(pq, r1); getAndCheckRegion(pq, r2); getAndCheckRegion(pq, r3); getAndCheckRegion(pq, r4); getAndCheckRegion(pq, r5); addRegion(pq, r1, 0); addRegion(pq, r2, CompactSplitThread.PRIORITY_USER); addRegion(pq, r3, 0); addRegion(pq, r4, CompactSplitThread.PRIORITY_USER); addRegion(pq, r5, 0); getAndCheckRegion(pq, r1); getAndCheckRegion(pq, r3); getAndCheckRegion(pq, r5); getAndCheckRegion(pq, r2); getAndCheckRegion(pq, r4); addRegion(pq, r1, CompactSplitThread.PRIORITY_USER); addRegion(pq, r2, CompactSplitThread.PRIORITY_USER); addRegion(pq, r3, CompactSplitThread.PRIORITY_USER); addRegion(pq, r4, CompactSplitThread.PRIORITY_USER); addRegion(pq, r5, 0); getAndCheckRegion(pq, r5); getAndCheckRegion(pq, r1); getAndCheckRegion(pq, r2); getAndCheckRegion(pq, r3); getAndCheckRegion(pq, r4); addRegion(pq, r1, CompactSplitThread.PRIORITY_USER); addRegion(pq, r2, 0); addRegion(pq, r3, CompactSplitThread.PRIORITY_USER); Thread.sleep(1000); addRegion(pq, r4, CompactSplitThread.PRIORITY_USER); addRegion(pq, r5, 0); getAndCheckRegion(pq, r2); getAndCheckRegion(pq, r5); getAndCheckRegion(pq, r1); getAndCheckRegion(pq, r3); getAndCheckRegion(pq, r4); pq = new PriorityCompactionQueue(); addRegion(pq, r1, CompactSplitThread.PRIORITY_USER); addRegion(pq, r2, CompactSplitThread.PRIORITY_USER); addRegion(pq, r3, CompactSplitThread.PRIORITY_USER); addRegion(pq, r4, CompactSplitThread.PRIORITY_USER); addRegion(pq, r5, CompactSplitThread.PRIORITY_USER); addRegion(pq, r3, 0); getAndCheckRegion(pq, r3); getAndCheckRegion(pq, r1); getAndCheckRegion(pq, r2); getAndCheckRegion(pq, r4); getAndCheckRegion(pq, r5); Assert.assertTrue("Queue should be empty.", pq.size() == 0); addRegion(pq, r1, CompactSplitThread.PRIORITY_USER); addRegion(pq, r2, CompactSplitThread.PRIORITY_USER); addRegion(pq, r3, CompactSplitThread.PRIORITY_USER); addRegion(pq, r4, CompactSplitThread.PRIORITY_USER); addRegion(pq, r5, CompactSplitThread.PRIORITY_USER); addRegion(pq, r1, CompactSplitThread.PRIORITY_USER); addRegion(pq, r2, CompactSplitThread.PRIORITY_USER); addRegion(pq, r3, CompactSplitThread.PRIORITY_USER); addRegion(pq, r4, CompactSplitThread.PRIORITY_USER); addRegion(pq, r5, CompactSplitThread.PRIORITY_USER); getAndCheckRegion(pq, r1); getAndCheckRegion(pq, r2); getAndCheckRegion(pq, r3); getAndCheckRegion(pq, r4); getAndCheckRegion(pq, r5); Assert.assertTrue("Queue should be empty.", pq.size() == 0); addRegion(pq, r1, CompactSplitThread.PRIORITY_USER); addRegion(pq, r2, -1); addRegion(pq, r3, 0); addRegion(pq, r4, -2); getAndCheckRegion(pq, r4); getAndCheckRegion(pq, r2); getAndCheckRegion(pq, r3); getAndCheckRegion(pq, r1); Assert.assertTrue("Queue should be empty.", pq.size() == 0); }
@Override public int size() { return queue.size(); }
PriorityCompactionQueue implements BlockingQueue<HRegion> { @Override public int size() { return queue.size(); } }
PriorityCompactionQueue implements BlockingQueue<HRegion> { @Override public int size() { return queue.size(); } PriorityCompactionQueue(); }
PriorityCompactionQueue implements BlockingQueue<HRegion> { @Override public int size() { return queue.size(); } PriorityCompactionQueue(); boolean add(HRegion e, int p); @Override boolean add(HRegion e); boolean offer(HRegion e, int p); @Override boolean offer(HRegion e); void put(HRegion e, int p); @Override void put(HRegion e); boolean offer(HRegion e, int p, long timeout, TimeUnit unit); @Override boolean offer(HRegion e, long timeout, TimeUnit unit); @Override HRegion take(); @Override HRegion poll(long timeout, TimeUnit unit); @Override boolean remove(Object r); @Override HRegion remove(); @Override HRegion poll(); @Override int remainingCapacity(); @Override boolean contains(Object r); @Override HRegion element(); @Override HRegion peek(); @Override int size(); @Override boolean isEmpty(); @Override void clear(); @Override Iterator<HRegion> iterator(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends HRegion> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int drainTo(Collection<? super HRegion> c); @Override int drainTo(Collection<? super HRegion> c, int maxElements); }
PriorityCompactionQueue implements BlockingQueue<HRegion> { @Override public int size() { return queue.size(); } PriorityCompactionQueue(); boolean add(HRegion e, int p); @Override boolean add(HRegion e); boolean offer(HRegion e, int p); @Override boolean offer(HRegion e); void put(HRegion e, int p); @Override void put(HRegion e); boolean offer(HRegion e, int p, long timeout, TimeUnit unit); @Override boolean offer(HRegion e, long timeout, TimeUnit unit); @Override HRegion take(); @Override HRegion poll(long timeout, TimeUnit unit); @Override boolean remove(Object r); @Override HRegion remove(); @Override HRegion poll(); @Override int remainingCapacity(); @Override boolean contains(Object r); @Override HRegion element(); @Override HRegion peek(); @Override int size(); @Override boolean isEmpty(); @Override void clear(); @Override Iterator<HRegion> iterator(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends HRegion> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int drainTo(Collection<? super HRegion> c); @Override int drainTo(Collection<? super HRegion> c, int maxElements);  }