/** * A new queue has the indicated capacity, or Integer.MAX_VALUE if * none given */ public void testConstructor1() { assertEquals(SIZE, new LinkedBlockingQueue(SIZE).remainingCapacity()); assertEquals(Integer.MAX_VALUE, new LinkedBlockingQueue().remainingCapacity()); }
int realPollCount = Math.min(workerQueue.remainingCapacity(), pollCount); if (realPollCount <= 0) { logger.warn("All workers are busy, not polling. queue size: {}, max: {}, task:{}", workerQueue.size(), workerQueueSize, taskName);
public void realRun() throws InterruptedException { assertFalse(q.offer(three)); threadsStarted.await(); assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS)); assertEquals(0, q.remainingCapacity()); }});
public void testNewLinkedBlockingQueueCapacity() { try { Queues.newLinkedBlockingQueue(0); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { // any capacity less than 1 should throw IllegalArgumentException } assertEquals(1, Queues.newLinkedBlockingQueue(1).remainingCapacity()); assertEquals(11, Queues.newLinkedBlockingQueue(11).remainingCapacity()); }
/** * add succeeds if not full; throws IllegalStateException if full */ public void testAdd() { LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); for (int i = 0; i < SIZE; ++i) assertTrue(q.add(new Integer(i))); assertEquals(0, q.remainingCapacity()); try { q.add(new Integer(SIZE)); shouldThrow(); } catch (IllegalStateException success) {} }
/** * all elements successfully put are contained */ public void testPut() throws InterruptedException { LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); for (int i = 0; i < SIZE; ++i) { Integer x = new Integer(i); q.put(x); assertTrue(q.contains(x)); } assertEquals(0, q.remainingCapacity()); }
public void realRun() throws InterruptedException { for (int i = 0; i < SIZE; ++i) q.put(i); assertEquals(SIZE, q.size()); assertEquals(0, q.remainingCapacity()); Thread.currentThread().interrupt(); try { q.put(99); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { q.put(99); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }});
/** * iterator ordering is FIFO */ public void testIteratorOrdering() { final LinkedBlockingQueue q = new LinkedBlockingQueue(3); q.add(one); q.add(two); q.add(three); assertEquals(0, q.remainingCapacity()); int k = 0; for (Iterator it = q.iterator(); it.hasNext();) { assertEquals(++k, it.next()); } assertEquals(3, k); }
getCompressedQueries().add(new CompressedItem("\n" + logItem + "\n", decompressStatementForLog)); } else { if (getCompressedQueries().remainingCapacity() == 0) { getCompressedQueries().poll(); getQueries().add("\n" + logItem + "\n"); } else { if (getQueries().remainingCapacity() == 0) { getQueries().poll();
/** * Queue transitions from empty to full when elements added */ public void testEmptyFull() { LinkedBlockingQueue q = new LinkedBlockingQueue(2); assertTrue(q.isEmpty()); assertEquals("should have room for 2", 2, q.remainingCapacity()); q.add(one); assertFalse(q.isEmpty()); q.add(two); assertFalse(q.isEmpty()); assertEquals(0, q.remainingCapacity()); assertFalse(q.offer(three)); }
assertEquals(0, q.remainingCapacity()); assertEquals(0, q.take()); t.interrupt(); awaitTermination(t); assertEquals(0, q.remainingCapacity());
try{ int realPollCount = Math.min(workerQueue.remainingCapacity(), worker.getPollCount()); if (realPollCount <= 0) { logger.warn("All workers are busy, not polling. queue size = {}, max = {}", workerQueue.size(), workerQueueSize);
/** * Returns a new queue of given size containing consecutive * Integers 0 ... n - 1. */ private static LinkedBlockingQueue<Integer> populatedQueue(int n) { LinkedBlockingQueue<Integer> q = new LinkedBlockingQueue<>(n); assertTrue(q.isEmpty()); for (int i = 0; i < n; i++) assertTrue(q.offer(new Integer(i))); assertFalse(q.isEmpty()); assertEquals(0, q.remainingCapacity()); assertEquals(n, q.size()); assertEquals((Integer) 0, q.peek()); return q; }
awaitTermination(t); assertEquals(SIZE, q.size()); assertEquals(0, q.remainingCapacity());
/** * clear removes all elements */ public void testClear() { LinkedBlockingQueue q = populatedQueue(SIZE); q.clear(); assertTrue(q.isEmpty()); assertEquals(0, q.size()); assertEquals(SIZE, q.remainingCapacity()); q.add(one); assertFalse(q.isEmpty()); assertTrue(q.contains(one)); q.clear(); assertTrue(q.isEmpty()); }
public MapReducePool(final MapReduce mapReduce, final int poolSize) { this.pool = new LinkedBlockingQueue<>(poolSize); while (this.pool.remainingCapacity() > 0) { this.pool.add(mapReduce.clone()); } }
public VertexProgramPool(final VertexProgram vertexProgram, final int poolSize) { this.pool = new LinkedBlockingQueue<>(poolSize); while (this.pool.remainingCapacity() > 0) { this.pool.add(vertexProgram.clone()); } }
@Override public int remainingCapacity() { if (forcedRemainingCapacity != null) { // ThreadPoolExecutor.setCorePoolSize checks that // remainingCapacity==0 to allow to interrupt idle threads // I don't see why, but this hack allows to conform to this // "requirement" return forcedRemainingCapacity.intValue(); } return super.remainingCapacity(); }
public VertexProgramPool(final VertexProgram vertexProgram, final int poolSize) { this.pool = new LinkedBlockingQueue<>(poolSize); while (this.pool.remainingCapacity() > 0) { this.pool.add(vertexProgram.clone()); } }
public MapReducePool(final MapReduce mapReduce, final int poolSize) { this.pool = new LinkedBlockingQueue<>(poolSize); while (this.pool.remainingCapacity() > 0) { this.pool.add(mapReduce.clone()); } }