ArrayBlockingQueueEx extends ArrayBlockingQueue<E> implements
                                                                  NotificationBlockingQueue<E> { @Override public boolean isEmpty() { queueLock.lock(); try { while (!finishQueueingFlag && size() == 0) { try { notEmpty.await(); } catch (InterruptedException e) { return true; } } return super.isEmpty(); } finally { queueLock.unlock(); } } ArrayBlockingQueueEx(int capacity, boolean fair);  ArrayBlockingQueueEx(int capacity); @Override void finishQueueing(); @Override boolean offer(E o, long timeout, TimeUnit unit); @Override boolean offer(E o); @Override void put(E o); @Override E peek(); @Override E poll(long timeout, TimeUnit unit); @Override E poll(); @Override boolean isEmpty();  }
@Test public void testIsEmpty002() throws Exception { int capacity = 1; final ArrayBlockingQueueEx<DataValueObject> queue = new ArrayBlockingQueueEx<DataValueObject>(capacity); Thread thread01 = new Thread() { @Override public void run() { try { sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } DataValueObject obj1 = new DataValueObject("hoge"); queue.add(obj1); } }; thread01.start(); assertFalse(queue.isEmpty()); }
@Test public void testIsEmpty003() throws Exception { int capacity = 1; DataValueObject obj1 = new DataValueObject("hoge"); ArrayBlockingQueueEx<DataValueObject> queue = new ArrayBlockingQueueEx<DataValueObject>(capacity); queue.add(obj1); assertFalse(queue.isEmpty()); }
@Test public void testIsEmpty005() throws Exception { int capacity = 1; final long sleeptime = 1000; final CountDownLatch threadSync = new CountDownLatch(1); final ArrayBlockingQueueEx<DataValueObject> queue = new ArrayBlockingQueueEx<DataValueObject>(capacity); ErrorFeedBackThread thread01 = new ErrorFeedBackThread() { @Override public void doRun() throws Exception { long timeStart = System.currentTimeMillis(); threadSync.countDown(); boolean result = queue.isEmpty(); long timeEnd = System.currentTimeMillis(); assertTrue(result); long timeDiff = timeEnd - timeStart; if (timeDiff < (sleeptime - 50)) { throw new RuntimeException("An exception did not occur within a definite period of time."); } } }; thread01.start(); threadSync.await(); TimeUnit.MILLISECONDS.sleep(sleeptime); thread01.interrupt(); thread01.throwErrorOrExceptionIfThrown(); }