You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2019/02/08 00:46:33 UTC

[geode] branch develop updated: GEODE-6370: Clean up LogWrapper between tests (#3173)

This is an automated email from the ASF dual-hosted git repository.

jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new f4c542d  GEODE-6370: Clean up LogWrapper between tests (#3173)
f4c542d is described below

commit f4c542dea7159abb0ab77a962198901d0ac5e531
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Thu Feb 7 16:46:10 2019 -0800

    GEODE-6370: Clean up LogWrapper between tests (#3173)
    
    
    - This avoids subsequent tests failing because they are checking for the
      presence of LogWrapper.
---
 .../internal/cli/shell/GfshAbstractUnitTest.java   | 24 ++++++++++++++++++++++
 .../cli/shell/GfshConsoleModeUnitTest.java}        | 16 +++++++++------
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/GfshAbstractUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/GfshAbstractUnitTest.java
index e732df2..e062264 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/GfshAbstractUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/GfshAbstractUnitTest.java
@@ -20,6 +20,11 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import java.util.Enumeration;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.shell.core.CommandResult;
@@ -36,6 +41,25 @@ public class GfshAbstractUnitTest {
     testString = "This is a test string.";
   }
 
+  @After
+  public void after() {
+    // This removes and cleans up the LogWrapper instance so that subsequent tests don't fail.
+    removeLogWrapper();
+  }
+
+  void removeLogWrapper() {
+    Logger rootLogger = LogManager.getLogManager().getLogger("");
+
+    for (Enumeration<String> enumeration = LogManager.getLogManager().getLoggerNames(); enumeration
+        .hasMoreElements();) {
+      String loggerName = enumeration.nextElement();
+      Logger logger = Logger.getLogger(loggerName);
+      if (logger.getParent() != null && logger.getParent().getName().endsWith(".LogWrapper")) {
+        logger.setParent(rootLogger);
+      }
+    }
+  }
+
   @Test
   public void testWrapTest() {
     assertThat(Gfsh.wrapText(testString, 0, -1)).isEqualTo(testString);
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/shell/GfshConsoleModeIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/GfshConsoleModeUnitTest.java
similarity index 88%
rename from geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/shell/GfshConsoleModeIntegrationTest.java
rename to geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/GfshConsoleModeUnitTest.java
index f0a5988..34d12cf 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/cli/shell/GfshConsoleModeIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/GfshConsoleModeUnitTest.java
@@ -21,18 +21,22 @@ import java.util.Enumeration;
 import java.util.logging.LogManager;
 import java.util.logging.Logger;
 
+import org.junit.Before;
 import org.junit.Test;
 
 
-public class GfshConsoleModeIntegrationTest {
+public class GfshConsoleModeUnitTest extends GfshAbstractUnitTest {
+
+  @Override
+  @Before
+  public void before() {
+    super.before();
+    gfsh = new Gfsh(true, null, new GfshConfig());
+  }
 
-  /**
-   * This test should remain an integration test as it checks the state of various Loggers.
-   * If run in conjunction with other (Gfsh) tests, these checks may fail.
-   */
   @Test
   public void consoleModeShouldRedirectOnlyJDKLoggers() {
-    Gfsh gfsh = new Gfsh(true, null, new GfshConfig());
+    gfsh = new Gfsh(true, null, new GfshConfig());
     LogManager logManager = LogManager.getLogManager();
     Enumeration<String> loggerNames = logManager.getLoggerNames();
     // when initialized in console mode, all log messages will show up in console