@Test
  public void testBuffer() {
    MemoryBoundedLogMessageBuffer buf = new MemoryBoundedLogMessageBuffer(TEN_KB);

    for (int i = 0; i < 1000; i++) {
      buf.add("hello " + i);
    }
    assertTrue("Usage too big: " + buf.estimateHeapUsage(), buf.estimateHeapUsage() < TEN_KB);
    assertTrue("Too many retained: " + buf.getMessages().size(), buf.getMessages().size() < 100);
    StringWriter sw = new StringWriter();
    buf.dumpTo(new PrintWriter(sw));
    String dump = sw.toString();
    String eol = System.getProperty("line.separator");
    assertFalse("The early log messages should be evicted", dump.contains("hello 1" + eol));
    assertTrue("The late log messages should be retained", dump.contains("hello 999" + eol));
  }
Test case for the MemoryBoundedLogMessageBuffer utility. Ensures that it uses no more memory than
it's supposed to, and that it properly deals with multibyte encodings.
hbase-server/src/test/java/org/apache/hadoop/hbase/monitoring/TestMemoryBoundedLogMessageBuffer.java