ClosableBlockingQueue { public List<E> getBatchBlocking() throws InterruptedException { lock.lock(); try { while (open && elements.isEmpty()) { nonEmpty.await(); } if (open) { ArrayList<E> result = new ArrayList<E>(elements); elements.clear(); return result; } else { throw new IllegalStateException("queue is closed"); } } finally { lock.unlock(); } } ClosableBlockingQueue();  ClosableBlockingQueue(int initialSize);  ClosableBlockingQueue(Collection<? extends E> initialElements); int size(); boolean isEmpty(); boolean isOpen(); boolean close(); boolean addIfOpen(E element); void add(E element); E peek(); E poll(); List<E> pollBatch(); E getElementBlocking(); E getElementBlocking(long timeoutMillis); List<E> getBatchBlocking(); List<E> getBatchBlocking(long timeoutMillis); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testGetBatchBlocking() { try { ClosableBlockingQueue<String> queue = new ClosableBlockingQueue<>(); assertEquals(emptyList(), queue.getBatchBlocking(1)); assertEquals(emptyList(), queue.getBatchBlocking(3)); assertEquals(emptyList(), queue.getBatchBlocking(2)); queue.add("a"); queue.add("b"); assertEquals(asList("a", "b"), queue.getBatchBlocking(900000009)); queue.add("c"); queue.add("d"); assertEquals(asList("c", "d"), queue.getBatchBlocking()); assertEquals(emptyList(), queue.getBatchBlocking(2)); queue.add("e"); assertEquals(singletonList("e"), queue.getBatchBlocking(0)); queue.add("f"); assertEquals(singletonList("f"), queue.getBatchBlocking(1000000000)); assertEquals(0, queue.size()); assertEquals(emptyList(), queue.getBatchBlocking(1)); assertEquals(emptyList(), queue.getBatchBlocking(3)); assertEquals(emptyList(), queue.getBatchBlocking(2)); assertTrue(queue.close()); try { queue.getBatchBlocking(); fail("should cause an exception"); } catch (IllegalStateException ignored) { } try { queue.getBatchBlocking(1000000000L); fail("should cause an exception"); } catch (IllegalStateException ignored) { } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }