### Question:
H2PersistentQueue extends AbstractQueue<T> { @Override public T poll() { if (head.equals(tail)) { return null; } final long nextTail = tail.getAndIncrement(); final T tail = this.queueMap.get(nextTail); queueMap.remove(nextTail); this.metadataMap.put("tail", nextTail + 1); return tail; } H2PersistentQueue(MVStore store, String queueName); @Override Iterator<T> iterator(); @Override int size(); @Override boolean offer(T t); @Override T poll(); @Override T peek();  }### Answer:
@Test public void testPoll() { H2PersistentQueue<String> sut = new H2PersistentQueue<>(this.mvStore, "test"); sut.add("Hello"); sut.add("world"); assertEquals("Hello", sut.poll()); assertEquals("world", sut.poll()); assertTrue("after poll 2 elements inserted before, should be empty", sut.isEmpty()); }
@Ignore @Test public void testPerformance() { H2PersistentQueue<String> sut = new H2PersistentQueue<>(this.mvStore, "test"); int numIterations = 10000000; for (int i = 0; i < numIterations; i++) { sut.add("Hello"); } mvStore.commit(); for (int i = 0; i < numIterations; i++) { assertEquals("Hello", sut.poll()); } assertTrue("should be empty", sut.isEmpty()); }
@Test public void testReloadFromPersistedState() { H2PersistentQueue<String> before = new H2PersistentQueue<>(this.mvStore, "test"); before.add("Hello"); before.add("crazy"); before.add("world"); assertEquals("Hello", before.poll()); this.mvStore.commit(); this.mvStore.close(); this.mvStore = new MVStore.Builder() .fileName(BrokerConstants.DEFAULT_PERSISTENT_PATH) .autoCommitDisabled() .open(); H2PersistentQueue<String> after = new H2PersistentQueue<>(this.mvStore, "test"); assertEquals("crazy", after.poll()); assertEquals("world", after.poll()); assertTrue("should be empty", after.isEmpty()); }