### Question:
ConcurrentQ { public void add(Collection<I> items) { lock.lock(); try { queue.addAll(items); tracker.itemsAdded(items.size()); fillOpenProcessingSlots(); } finally { lock.unlock(); } } ConcurrentQ(String name, QCallback<I, R> callback);  ConcurrentQ(QCallback<I, R> callback, Queue<I> queue, GThreadPool threadPool,
			QItemListener<I, R> listener, boolean collectResults, int maxInProgress,
			boolean jobsReportProgress); synchronized void addProgressListener(QProgressListener<I> listener); synchronized void removeProgressListener(QProgressListener<I> listener); void setMonitor(TaskMonitor monitor, boolean cancelClearsAllItems); void add(Collection<I> items); void add(Iterator<I> iterator); void offer(Iterator<I> iterator); void add(I item); boolean isEmpty(); Collection<QResult<I, R>> waitForResults(); QResult<I, R> waitForNextResult(); void waitUntilDone(); Collection<QResult<I, R>> waitForResults(long timeout, TimeUnit unit); List<I> cancelAllTasks(boolean interruptRunningTasks); List<I> removeUnscheduledJobs(); void cancelScheduledJobs(); void dispose(); boolean waitUntilDone(long timeout, TimeUnit unit);  }### Answer:
@Test public void testWaitUntilDoneWithExceptionBeforeWait() throws Exception { List<TestItem> workList = new ArrayList<>(); workList.add(new TestItem("1", FAST_EXECUTION, true)); workList.add(new TestItem("2", FAST_EXECUTION)); q.add(workList); waitForEmptyQueue(); CheckpointRunner checkpointRunner = new CheckpointRunner(new WaitUntilDoneCallable()); try { checkpointRunner.waitForFinish(3000); Assert.fail("Did not get an exception while blocking on waitUntilDone()"); } catch (Exception e) { } }
@Test public void testWaitUntilDoneWithExceptionWhileWaiting() throws Exception { CountDownLatch waitLatch = new CountDownLatch(1); List<TestItem> workList = new ArrayList<>(); String exceptionItemName = "BillyBobDies"; workList.add(new LatchTestExceptionItem(exceptionItemName, waitLatch, FAST_EXECUTION)); workList.add(new TestItem("2", FAST_EXECUTION)); q.add(workList); CheckpointRunner checkpointRunner = new CheckpointRunner(new WaitUntilDoneCallable()); assertTrue("Thread did not start", checkpointRunner.waitForStart(500)); assertTrue("waitUntilDone() call did not wait for all items", !checkpointRunner.hasFinished()); try { waitLatch.countDown(); assertFalse( "Timed-out waiting for Thread to finish. It must be blocking on an empty queue", checkpointRunner.waitForFinish(100)); Assert.fail("Did not get an exception while blocking on waitUntilDone()"); } catch (Exception e) { assertTrue("Got the wrong exception!", e.getMessage().endsWith(exceptionItemName)); } }
@Test public void testWaitForNextResultExceptionDoesNotStop() throws Exception { CountDownLatch waitLatch = new CountDownLatch(1); List<TestItem> workList = new ArrayList<>(); workList.add(new LatchTestItem("1", waitLatch, FAST_EXECUTION)); workList.add(new TestItem("2", FAST_EXECUTION)); q.add(workList); CheckpointRunner checkpointRunner = new CheckpointRunner(new WaitForNextCallable()); QResult<TestItem, TestResult> result = checkpointRunner.getResult(); assertEquals("2", result.getResult().getItemName()); waitLatch.countDown(); checkpointRunner = new CheckpointRunner(new WaitForNextCallable()); result = checkpointRunner.getResult(); assertEquals("1", result.getResult().getItemName()); }