@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()); }
@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 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 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); }
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(); }
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();  }