Class MockLog

java.lang.Object
org.elasticsearch.test.MockLog
All Implemented Interfaces:
Closeable, AutoCloseable, org.elasticsearch.core.Releasable

public class MockLog extends Object implements org.elasticsearch.core.Releasable
Test appender that can be used to verify that certain events were logged correctly
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface org.elasticsearch.core.Releasable
    • init

      public static void init()
      Initialize the mock log appender with the log4j system.
    • addExpectation

      public void addExpectation(MockLog.LoggingExpectation expectation)
    • assertAllExpectationsMatched

      public void assertAllExpectationsMatched()
    • awaitAllExpectationsMatched

      public void awaitAllExpectationsMatched()
    • capture

      public static MockLog capture(Class<?>... classes)
      Adds the list of class loggers to this MockLog. Stops and runs some checks on the MockLog once the returned object is released.
    • capture

      public static MockLog capture(String... names)
      Same as above except takes string class names of each logger.
    • assertThatLogger

      public static void assertThatLogger(Runnable action, Class<?> loggerOwner, MockLog.LoggingExpectation... expectations)
      Executes an action and verifies expectations against the provided logger
    • awaitLogger

      public static void awaitLogger(Runnable action, Class<?> loggerOwner, MockLog.LoggingExpectation... expectations)
      Executes an action and waits until the given logging expectations are satisfied.