Class TestLogLevel

java.lang.Object
org.apache.hadoop.hbase.http.log.TestLogLevel

@Tag("org.apache.hadoop.hbase.testclassification.MiscTests") @Tag("org.apache.hadoop.hbase.testclassification.SmallTests") public class TestLogLevel extends Object
Test LogLevel.
  • Field Details

  • Constructor Details

  • Method Details

    • setUp

      @BeforeAll public static void setUp() throws Exception
      Throws:
      Exception
    • setupMiniKdc

      private static org.apache.hadoop.minikdc.MiniKdc setupMiniKdc() throws Exception
      Sets up MiniKdc for testing security. Copied from HBaseTestingUtility#setupMiniKdc().
      Throws:
      Exception
    • isBindException

      static boolean isBindException(Throwable t)
      The Kerby-backed MiniKdc wraps a failure to bind the KDC port in a org.apache.kerby...KrbException rather than surfacing a BindException directly, so we inspect the whole cause chain plus the message to recognise a port conflict. Both checks are load-bearing across Kerby versions: kerby 1.x preserves the original BindException as the cause (caught by the cause-chain check) while kerby 2.x drops the cause and only appends the bind message (caught by the message check). The message match is lower-cased since the wording is JDK/OS specific.
    • testIsBindExceptionRecognizesKerbyWrappedBindFailure

      Deterministic regression test for the retry predicate. A port conflict raised by the Kerby-backed MiniKdc must be recognised as a bind failure whether the BindException is preserved in the cause chain or only reflected in the message; unrelated failures must not be. We model the Kerby wrapper with a plain Exception rather than constructing a real Kerby exception, so the test does not import kerby types (see HBASE-29117).
    • setupSSL

      private static void setupSSL(File base) throws Exception
      Throws:
      Exception
    • getSslConfig

      private static org.apache.hadoop.conf.Configuration getSslConfig(org.apache.hadoop.conf.Configuration conf)
      Get the SSL configuration. This method is copied from KeyStoreTestUtil#getSslConfig() in Hadoop.
      Parameters:
      conf - to pull client/server SSL settings filename from
      Returns:
      Configuration instance with ssl configs loaded.
    • tearDown

      @AfterAll public static void tearDown()
    • testCommandOptions

      @Test public void testCommandOptions() throws Exception
      Test client command line options. Does not validate server behavior.
      Throws:
      Exception - if commands return unexpected results.
    • validateCommand

      private boolean validateCommand(String[] args)
      Check to see if a command can be accepted.
      Parameters:
      args - a String array of arguments
      Returns:
      true if the command can be accepted, false if not.
    • createServer

      private org.apache.hadoop.hbase.http.HttpServer createServer(String protocol, boolean isSpnego) throws Exception
      Creates and starts a Jetty server binding at an ephemeral port to run LogLevel servlet.
      Parameters:
      protocol - "http" or "https"
      isSpnego - true if SPNEGO is enabled
      Returns:
      a created HttpServer object
      Throws:
      Exception - if unable to create or start a Jetty server
    • testGetLogLevel

      private void testGetLogLevel(TestLogLevel.Protocol protocol, boolean isSpnego, String loggerName, String expectedLevel) throws Exception
      Throws:
      Exception
    • testSetLogLevel

      private void testSetLogLevel(TestLogLevel.Protocol protocol, boolean isSpnego, String loggerName, String newLevel) throws Exception
      Throws:
      Exception
    • withLogLevelServer

      private void withLogLevelServer(TestLogLevel.Protocol protocol, boolean isSpnego, TestLogLevel.ThrowingConsumer consumer) throws Exception
      Starts a LogLevel server and executes a client action against it.
      Parameters:
      protocol - protocol configuration for client and server
      isSpnego - whether SPNEGO authentication is enabled
      consumer - client action executed with the server authority (host:port)
      Throws:
      Exception - if server setup or client execution fails
    • getLevel

      private String getLevel(String protocol, String authority, String logName) throws Exception
      Run LogLevel command line to start a client to get log level of this test class.
      Parameters:
      protocol - specify either http or https
      authority - daemon's web UI address
      Throws:
      Exception - if unable to connect
    • setLevel

      private void setLevel(String protocol, String authority, String logName, String newLevel) throws Exception
      Run LogLevel command line to start a client to set log level of this test class to debug.
      Parameters:
      protocol - specify either http or https
      authority - daemon's web UI address
      Throws:
      Exception - if unable to run or log level does not change as expected
    • extractEffectiveLevel

      private String extractEffectiveLevel(String response)
      Extract effective log level from server response.
      Parameters:
      response - server body response string
      Returns:
      the effective log level
    • testSettingProtectedLogLevel

      @Test public void testSettingProtectedLogLevel() throws Exception
      Throws:
      Exception
    • testGetDebugLogLevel

      @Test public void testGetDebugLogLevel() throws Exception
      Throws:
      Exception
    • testGetInfoLogLevel

      @Test public void testGetInfoLogLevel() throws Exception
      Throws:
      Exception
    • testSetInfoLogLevel

      @Test public void testSetInfoLogLevel() throws Exception
      Test setting log level to "Info".
      Throws:
      Exception - if client can't set log level to INFO.
    • testSetErrorLogLevel

      @Test public void testSetErrorLogLevel() throws Exception
      Test setting log level to "Error".
      Throws:
      Exception - if client can't set log level to ERROR.
    • testLogLevelByHttp

      @Test public void testLogLevelByHttp() throws Exception
      Server runs HTTP, no SPNEGO.
      Throws:
      Exception - if http client can't access http server, or http client can access https server.
    • testLogLevelByHttpWithSpnego

      @Test public void testLogLevelByHttpWithSpnego() throws Exception
      Server runs HTTP + SPNEGO.
      Throws:
      Exception - if http client can't access http server, or http client can access https server.
    • testLogLevelByHttps

      @Test public void testLogLevelByHttps() throws Exception
      Server runs HTTPS, no SPNEGO.
      Throws:
      Exception - if https client can't access https server, or https client can access http server.
    • testLogLevelByHttpsWithSpnego

      @Test public void testLogLevelByHttpsWithSpnego() throws Exception
      Server runs HTTPS + SPNEGO.
      Throws:
      Exception - if https client can't access https server, or https client can access http server.
    • testGetLogLevelAllowedInReadonlyMode

      @Test public void testGetLogLevelAllowedInReadonlyMode() throws Exception
      Test getting log level in readonly mode.
      Throws:
      Exception - if a client can't get log level.
    • testSetLogLevelDisallowedInReadonlyMode

      Test setting log level in readonly mode.
      Throws:
      Exception - if a client can set log level.
    • withMasterUIReadonly

      Throws:
      Exception
    • exceptionShouldContains

      private static void exceptionShouldContains(String substr, Throwable throwable)
      Assert that a throwable or one of its causes should contain the substr in its message. Ideally we should use GenericTestUtils.assertExceptionContains(String, Throwable) util method which asserts t.toString() contains the substr. As the original throwable may have been wrapped in Hadoop3 because of HADOOP-12897, it's required to check all the wrapped causes. After stop supporting Hadoop2, this method can be removed and assertion in tests can use t.getCause() directly, similar to HADOOP-15280.