]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8335 add missing coverage on jmx log property
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 29 Nov 2016 09:50:01 +0000 (10:50 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 1 Dec 2016 11:29:39 +0000 (12:29 +0100)
server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java
server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java

index d2bc08de935693b88606c290bd9765e5a5d46ada..f16620049efbab77233b2b56625245c5056d268f 100644 (file)
@@ -246,6 +246,63 @@ public class CeProcessLoggingTest {
     verifyEsLogLevel(ctx, Level.DEBUG);
   }
 
+  @Test
+  public void jmx_logger_level_changes_with_global_property_and_is_case_insensitive() {
+    props.set("sonar.log.level", "InFO");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.INFO);
+  }
+
+  @Test
+  public void jmx_logger_level_changes_with_jmx_property_and_is_case_insensitive() {
+    props.set("sonar.log.level.ce", "TrACe");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.TRACE);
+  }
+
+  @Test
+  public void jmx_logger_level_changes_with_ce_jmx_property_and_is_case_insensitive() {
+    props.set("sonar.log.level.ce.jmx", "debug");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.DEBUG);
+  }
+
+  @Test
+  public void jmx_logger_level_is_configured_from_ce_jmx_property_over_ce_property() {
+    props.set("sonar.log.level.ce.jmx", "debug");
+    props.set("sonar.log.level.ce", "TRACE");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.DEBUG);
+  }
+
+  @Test
+  public void jmx_logger_level_is_configured_from_ce_jmx_property_over_global_property() {
+    props.set("sonar.log.level.ce.jmx", "debug");
+    props.set("sonar.log.level", "TRACE");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.DEBUG);
+  }
+
+  @Test
+  public void jmx_logger_level_is_configured_from_ce_property_over_global_property() {
+    props.set("sonar.log.level.ce", "debug");
+    props.set("sonar.log.level", "TRACE");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.DEBUG);
+  }
+
   @Test
   public void root_logger_level_defaults_to_INFO_if_ce_property_has_invalid_value() {
     props.set("sonar.log.level.ce", "DodoDouh!");
@@ -270,6 +327,14 @@ public class CeProcessLoggingTest {
     verifyEsLogLevel(ctx, Level.INFO);
   }
 
+  @Test
+  public void jmx_loggers_level_defaults_to_INFO_if_ce_jmx_property_has_invalid_value() {
+    props.set("sonar.log.level.ce.jmx", "DodoDouh!");
+
+    LoggerContext ctx = underTest.configure(props);
+    verifyJmxLogLevel(ctx, Level.INFO);
+  }
+
   @Test
   public void fail_with_IAE_if_global_property_unsupported_level() {
     props.set("sonar.log.level", "ERROR");
@@ -310,6 +375,16 @@ public class CeProcessLoggingTest {
     underTest.configure(props);
   }
 
+  @Test
+  public void fail_with_IAE_if_ce_jmx_property_unsupported_level() {
+    props.set("sonar.log.level.ce.jmx", "ERROR");
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("log level ERROR in property sonar.log.level.ce.jmx is not a supported value (allowed levels are [TRACE, DEBUG, INFO])");
+
+    underTest.configure(props);
+  }
+
   private void verifyRootLogLevel(LoggerContext ctx, Level expected) {
     assertThat(ctx.getLogger(ROOT_LOGGER_NAME).getLevel()).isEqualTo(expected);
   }
@@ -321,4 +396,16 @@ public class CeProcessLoggingTest {
   private void verifyEsLogLevel(LoggerContext ctx, Level expected) {
     assertThat(ctx.getLogger("es").getLevel()).isEqualTo(expected);
   }
+
+  private void verifyJmxLogLevel(LoggerContext ctx, Level expected) {
+    assertThat(ctx.getLogger("javax.management.remote.timeout").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("javax.management.remote.misc").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("javax.management.remote.rmi").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("javax.management.mbeanserver").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.loader").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.transport.tcp").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.transport.misc").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.server.call").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.dgc").getLevel()).isEqualTo(expected);
+  }
 }
index 5a7d401f02708bb5ae04648a6b666ca3e0fe2a9b..05b05b77f304c2d45b295d3214974cf8f610f2cb 100644 (file)
@@ -246,6 +246,63 @@ public class WebServerProcessLoggingTest {
     verifyEsLogLevel(ctx, Level.DEBUG);
   }
 
+  @Test
+  public void jmx_logger_level_changes_with_global_property_and_is_case_insensitive() {
+    props.set("sonar.log.level", "InFO");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.INFO);
+  }
+
+  @Test
+  public void jmx_logger_level_changes_with_jmx_property_and_is_case_insensitive() {
+    props.set("sonar.log.level.web", "TrACe");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.TRACE);
+  }
+
+  @Test
+  public void jmx_logger_level_changes_with_web_jmx_property_and_is_case_insensitive() {
+    props.set("sonar.log.level.web.jmx", "debug");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.DEBUG);
+  }
+
+  @Test
+  public void jmx_logger_level_is_configured_from_web_jmx_property_over_web_property() {
+    props.set("sonar.log.level.web.jmx", "debug");
+    props.set("sonar.log.level.web", "TRACE");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.DEBUG);
+  }
+
+  @Test
+  public void jmx_logger_level_is_configured_from_web_jmx_property_over_global_property() {
+    props.set("sonar.log.level.web.jmx", "debug");
+    props.set("sonar.log.level", "TRACE");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.DEBUG);
+  }
+
+  @Test
+  public void jmx_logger_level_is_configured_from_web_property_over_global_property() {
+    props.set("sonar.log.level.web", "debug");
+    props.set("sonar.log.level", "TRACE");
+
+    LoggerContext ctx = underTest.configure(props);
+
+    verifyJmxLogLevel(ctx, Level.DEBUG);
+  }
+
   @Test
   public void root_logger_level_defaults_to_INFO_if_web_property_has_invalid_value() {
     props.set("sonar.log.level.web", "DodoDouh!");
@@ -270,6 +327,14 @@ public class WebServerProcessLoggingTest {
     verifyEsLogLevel(ctx, Level.INFO);
   }
 
+  @Test
+  public void jmx_loggers_level_defaults_to_INFO_if_wedb_jmx_property_has_invalid_value() {
+    props.set("sonar.log.level.web.jmx", "DodoDouh!");
+
+    LoggerContext ctx = underTest.configure(props);
+    verifyJmxLogLevel(ctx, Level.INFO);
+  }
+
   @Test
   public void fail_with_IAE_if_global_property_unsupported_level() {
     props.set("sonar.log.level", "ERROR");
@@ -310,6 +375,16 @@ public class WebServerProcessLoggingTest {
     underTest.configure(props);
   }
 
+  @Test
+  public void fail_with_IAE_if_web_jmx_property_unsupported_level() {
+    props.set("sonar.log.level.web.jmx", "ERROR");
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("log level ERROR in property sonar.log.level.web.jmx is not a supported value (allowed levels are [TRACE, DEBUG, INFO])");
+
+    underTest.configure(props);
+  }
+
   private void verifyRootLogLevel(LoggerContext ctx, Level expected) {
     Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
     assertThat(rootLogger.getLevel()).isEqualTo(expected);
@@ -323,4 +398,16 @@ public class WebServerProcessLoggingTest {
     assertThat(ctx.getLogger("es").getLevel()).isEqualTo(expected);
   }
 
+  private void verifyJmxLogLevel(LoggerContext ctx, Level expected) {
+    assertThat(ctx.getLogger("javax.management.remote.timeout").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("javax.management.remote.misc").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("javax.management.remote.rmi").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("javax.management.mbeanserver").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.loader").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.transport.tcp").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.transport.misc").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.server.call").getLevel()).isEqualTo(expected);
+    assertThat(ctx.getLogger("sun.rmi.dgc").getLevel()).isEqualTo(expected);
+  }
+
 }