@Test
  public void testLogRollWhileStreaming() throws Exception {
    appendToLog("1");
    // 2
    appendToLog("2");
    try (WALEntryStreamWithRetries entryStream = new WALEntryStreamWithRetries(logQueue, fs, CONF,
      0, log, new MetricsSource("1"), fakeWalGroupId)) {
      assertEquals("1", getRow(next(entryStream)));

      // 3 - comes in after reader opened
      appendToLog("3");
      // log roll happening while we're reading
      log.rollWriter();
      // 4 - this append is in the rolled log
      appendToLog("4");

      assertEquals("2", getRow(next(entryStream)));
      // we should not have dequeued yet since there's still an entry in first log
      assertEquals(2, getQueue().size());
      // if implemented improperly, this would be 4 and 3 would be skipped
      assertEquals("3", getRow(next(entryStream)));
      // 4
      assertEquals("4", getRow(next(entryStream)));
      // now we've dequeued and moved on to next log properly
      assertEquals(1, getQueue().size());

      // disable so we can get the return value immediately, otherwise we will fail with wait too
      // much time...
      entryStream.disableRetry();
      assertEquals(HasNext.RETRY, entryStream.hasNext());
    }
  }
Tests that if after a stream is opened, more entries come in and then the log is rolled, we
don't mistakenly dequeue the current log thinking we're done with it
hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestBasicWALEntryStream.java