### Question:
SingleConsumerNonblockingProducerDelayQueue extends SingleConsumerNonblockingProducerQueue<E> { @Override public E poll() { final E first = peek(); if (first == null || !isExpired(first)) return null; return super.poll(); } SingleConsumerNonblockingProducerDelayQueue(); @Override E poll(); @Override E take(); @Override E poll(long timeout, TimeUnit unit);  }### Answer:
@Test public void testPoll() throws Exception { q.offer(DelayedValue.instance(SEQUENCED, 3, 150)); q.offer(DelayedValue.instance(SEQUENCED, 1, 50)); q.offer(DelayedValue.instance(SEQUENCED, 2, 100)); DelayedValue dv; Thread.sleep(30); dv = q.poll(); assertThat(dv, is(nullValue())); Thread.sleep(30); dv = q.poll(); assertThat(dv.getValue(), is(1)); Thread.sleep(20); dv = q.poll(); assertThat(dv, is(nullValue())); Thread.sleep(30); dv = q.poll(); assertThat(dv.getValue(), is(2)); Thread.sleep(15); dv = q.poll(); assertThat(dv, is(nullValue())); Thread.sleep(40); dv = q.poll(); assertThat(dv.getValue(), is(3)); }
@Test public void testTimedPoll() throws Exception { q.offer(DelayedValue.instance(SEQUENCED, 2, 100)); q.offer(DelayedValue.instance(SEQUENCED, 1, 50)); q.offer(DelayedValue.instance(SEQUENCED, 3, 150)); DelayedValue dv; dv = q.poll(30, TimeUnit.MILLISECONDS); assertThat(dv, is(nullValue())); dv = q.poll(30, TimeUnit.MILLISECONDS); assertThat(dv.getValue(), is(1)); dv = q.poll(20, TimeUnit.MILLISECONDS); assertThat(dv, is(nullValue())); dv = q.poll(30, TimeUnit.MILLISECONDS); assertThat(dv.getValue(), is(2)); dv = q.poll(20, TimeUnit.MILLISECONDS); assertThat(dv, is(nullValue())); dv = q.poll(40, TimeUnit.MILLISECONDS); assertThat(dv.getValue(), is(3)); }
@Test public void testTimedPollWithSurpriseInsertions() throws Exception { DelayedValue dv; dv = q.poll(30, TimeUnit.MILLISECONDS); assertThat(dv, is(nullValue())); q.offer(DelayedValue.instance(SEQUENCED, 2, 200)); dv = q.poll(30, TimeUnit.MILLISECONDS); assertThat(dv, is(nullValue())); q.offer(DelayedValue.instance(SEQUENCED, 1, 20)); dv = q.poll(30, TimeUnit.MILLISECONDS); assertThat(dv.getValue(), is(1)); dv = q.poll(150, TimeUnit.MILLISECONDS); assertThat(dv.getValue(), is(2)); }