@Test
  public void testRandomLog() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(baos), true);
    LogWriter logWriter = new RandomLogWriter(printWriter);

    for (int i = 0; i < 100; i++) {
      logWriter.info(String.valueOf(i));
    }

    printWriter.flush();
    printWriter.close();

    byte[] bytes = baos.toByteArray();

    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);

    StringWriter stringWriter = new StringWriter();
    printWriter = new PrintWriter(stringWriter, true);
    SortLogFile.sortLogFile(bais, printWriter);

    String sorted = stringWriter.toString();

    BufferedReader reader = new BufferedReader(new StringReader(sorted));
    LogFileParser parser = new LogFileParser(null, reader);
    String prevTimestamp = null;
    while (parser.hasMoreEntries()) {
      LogFileParser.LogEntry entry = parser.getNextEntry();
      String timestamp = entry.getTimestamp();
      if (prevTimestamp != null) {
        assertThat(prevTimestamp.compareTo(timestamp))
            .as("Prev: " + prevTimestamp + ", current: " + timestamp)
            .isLessThanOrEqualTo(0);
      }
      prevTimestamp = entry.getTimestamp();
    }
  }
Generates a "log file" whose entry timestamps are in a random order. Then it sorts the log file
and asserts that the entries are sorted order.
geode-core/src/test/java/org/apache/geode/internal/logging/SortLogFileTest.java