@Test public void resourcePoolTimestampOverflow() { Callable<Integer> task = () -> { ConcurrentLinkedQueue<Integer> queue = mock(ConcurrentLinkedQueue.class); TestResourcePool testPool = new TestResourcePool(2, queue); Integer resource1 = testPool.acquire(Long.MAX_VALUE, TimeUnit.MILLISECONDS); Integer resource2 = testPool.acquire(Long.MAX_VALUE, TimeUnit.MILLISECONDS); assertEquals(new Integer(1), resource1); assertEquals(new Integer(2), resource2); Integer resource3 = testPool.acquire(Long.MAX_VALUE, TimeUnit.MILLISECONDS); assertNull(resource3); return resource3; }; ExecutorService executor = Executors.newFixedThreadPool(1); Future<Integer> future = executor.submit(task); boolean timeout = false; try { future.get(5000, TimeUnit.MILLISECONDS); } catch (Exception ex) { timeout = true; } assertTrue(timeout); assertFalse(future.isDone()); future.cancel(true); }
@Override public T acquire() { return acquire(WAIT_INDEFINITELY, null); }
ResourcePool implements Pool<T> { @Override public T acquire() { return acquire(WAIT_INDEFINITELY, null); } }
ResourcePool implements Pool<T> { @Override public T acquire() { return acquire(WAIT_INDEFINITELY, null); } ResourcePool(int maxCapacity); protected  ResourcePool(int maxCapacity, ConcurrentLinkedQueue<T> resources); }
ResourcePool implements Pool<T> { @Override public T acquire() { return acquire(WAIT_INDEFINITELY, null); } ResourcePool(int maxCapacity); protected  ResourcePool(int maxCapacity, ConcurrentLinkedQueue<T> resources); @Override T acquire(); @Override @Nullable T acquire(long time, TimeUnit unit); @Override abstract void close(); @Override void release(T resource); @Override int size(); }
ResourcePool implements Pool<T> { @Override public T acquire() { return acquire(WAIT_INDEFINITELY, null); } ResourcePool(int maxCapacity); protected  ResourcePool(int maxCapacity, ConcurrentLinkedQueue<T> resources); @Override T acquire(); @Override @Nullable T acquire(long time, TimeUnit unit); @Override abstract void close(); @Override void release(T resource); @Override int size();  }