You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2015/09/01 18:48:55 UTC

[17/37] incubator-geode git commit: GEODE-232: Convert resource string to URI string for log4j2-cli.xml

GEODE-232: Convert resource string to URI string for log4j2-cli.xml

Add lots of new unit and integration tests for LogService.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/19732b2d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/19732b2d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/19732b2d

Branch: refs/heads/feature/GEODE-77
Commit: 19732b2d8060c5707448364d998ba287ccd9f727
Parents: 936065f
Author: Kirk Lund <kl...@pivotal.io>
Authored: Thu Aug 20 19:59:37 2015 -0700
Committer: Kirk Lund <kl...@pivotal.io>
Committed: Thu Aug 20 20:26:24 2015 -0700

----------------------------------------------------------------------
 .../gemfire/internal/logging/LogService.java    |  11 +-
 .../internal/logging/log4j/Configurator.java    |   8 +
 .../logging/LogServiceIntegrationJUnitTest.java | 209 +++++++++++++++++++
 .../LogServiceIntegrationTestSupport.java       |  24 +++
 .../internal/logging/LogServiceJUnitTest.java   | 190 ++++++-----------
 .../LogServiceUserDirIntegrationJUnitTest.java  |  70 +++++++
 .../logging/LoggingIntegrationTestSuite.java    |   3 +-
 .../internal/logging/LoggingUnitTestSuite.java  |   1 +
 8 files changed, 385 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19732b2d/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/LogService.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/LogService.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/LogService.java
index a4a399d..637f8ca 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/LogService.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/LogService.java
@@ -146,7 +146,15 @@ public class LogService extends LogManager {
       else {
         //If the resource can be found and in cases where the resource is in gemfire jar,
         //we set the log location to the file that was found
-        configFileInformation = "Using log4j configuration file specified by " + ConfigurationFactory.CONFIGURATION_FILE_PROPERTY + ": '" + configFileName + "'";
+
+        // must change from Java resource syntax to Java URL syntax (GEODE-232)
+        // jar:file:/export/latvia1/users/klund/dev/asf-geode/gemfire-assembly/build/install/apache-geode/lib/gemfire-core-1.0.0-incubating-SNAPSHOT.jar!/com/gemstone/gemfire/internal/logging/log4j/log4j2-cli.xml
+        
+        String configFilePropertyValue = configUrl.toString();
+        // configFileName is Java resource syntax, configFilePropertyValue is URL syntax as required by log4j2
+        
+        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configFilePropertyValue);
+        configFileInformation = "Using log4j configuration file specified by " + ConfigurationFactory.CONFIGURATION_FILE_PROPERTY + ": '" + configFilePropertyValue + "'";
         StatusLogger.getLogger().info(configFileInformation);
         return true;
       }
@@ -218,6 +226,7 @@ public class LogService extends LogManager {
   public static LogWriterLogger createLogWriterLogger(final String name, final String connectionName, final boolean isSecure) {
     return LogWriterLogger.create(name, connectionName, isSecure);
   }
+  
   /**
    * Return the Log4j Level associated with the int level.
    * 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19732b2d/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/Configurator.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/Configurator.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/Configurator.java
index ccb2639..e07f214 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/Configurator.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/Configurator.java
@@ -28,6 +28,14 @@ public class Configurator {
     //context.reconfigure();
   }*/
   
+  public static void shutdown() {
+    //LoggerContext context = (LoggerContext)LogManager.getContext(false);
+    final LoggerContext context = ((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).getContext();
+    context.stop();
+    org.apache.logging.log4j.core.config.Configurator.shutdown(context);
+  }
+
+  
   public static void setLevel(String name, Level level) {
     LoggerContext context = (LoggerContext)LogManager.getContext(false);
     LoggerConfig logConfig = getLoggerConfig(name);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19732b2d/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceIntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceIntegrationJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceIntegrationJUnitTest.java
new file mode 100755
index 0000000..6425c1f
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceIntegrationJUnitTest.java
@@ -0,0 +1,209 @@
+package com.gemstone.gemfire.internal.logging;
+
+import static com.gemstone.gemfire.internal.logging.LogServiceIntegrationTestSupport.*;
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.File;
+import java.net.URL;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExternalResource;
+import org.junit.rules.TemporaryFolder;
+
+import com.gemstone.gemfire.internal.ClassPathLoader;
+import com.gemstone.gemfire.internal.logging.log4j.Configurator;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests for LogService and how it configures and uses log4j2
+ * 
+ * @author Kirk Lund
+ */
+@Category(IntegrationTest.class)
+public class LogServiceIntegrationJUnitTest {
+  
+  private String beforeConfigFileProp;
+  private Level beforeLevel;
+  
+  @Rule
+  public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+  
+  @Rule
+  public final ExternalResource externalResource = new ExternalResource() {
+    @Override
+    protected void before() {
+      beforeConfigFileProp = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+      beforeLevel = StatusLogger.getLogger().getLevel();
+      
+      System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+      StatusLogger.getLogger().setLevel(Level.OFF);
+      
+      Configurator.shutdown();
+    }
+    @Override
+    protected void after() {
+      Configurator.shutdown();
+      
+      if (beforeConfigFileProp != null) {
+        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, beforeConfigFileProp);
+      }
+      StatusLogger.getLogger().setLevel(beforeLevel);
+      
+      LogService.reconfigure();
+      assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+    }
+  };
+  
+  private URL defaultConfigUrl;
+  private URL cliConfigUrl;
+  
+  @Before
+  public void setUp() {
+    this.defaultConfigUrl = LogService.class.getResource(LogService.DEFAULT_CONFIG);
+    this.cliConfigUrl = LogService.class.getResource(LogService.CLI_CONFIG);
+  }
+  
+  @Test
+  public void shouldPreferConfigInConfigurationFilePropertyIfSet() throws Exception {
+    final File configFile = this.temporaryFolder.newFile("log4j2.xml");
+    final String configFileName = configFile.toURI().toString();
+    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configFileName);
+    writeConfigFile(configFile, Level.DEBUG);
+    
+    LogService.reconfigure();
+    
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isFalse();
+    assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).isEqualTo(configFileName);
+    assertThat(LogService.getLogger().getName()).isEqualTo(getClass().getName());
+  }
+  
+  @Test
+  public void shouldUseDefaultConfigIfNotConfigured() throws Exception {
+    LogService.reconfigure();
+    
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+    assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).isEqualTo(this.defaultConfigUrl.toString());
+  }
+  
+  @Test
+  public void defaultConfigShouldBeLoadableAsResource() {
+    final URL configUrlFromLogService = LogService.class.getResource(LogService.DEFAULT_CONFIG);
+    final URL configUrlFromClassLoader = getClass().getClassLoader().getResource(LogService.DEFAULT_CONFIG.substring(1));
+    final URL configUrlFromClassPathLoader = ClassPathLoader.getLatest().getResource(LogService.DEFAULT_CONFIG.substring(1));
+    
+    assertThat(configUrlFromLogService).isNotNull();
+    assertThat(configUrlFromClassLoader).isNotNull();
+    assertThat(configUrlFromClassPathLoader).isNotNull();
+    assertThat(configUrlFromLogService)
+        .isEqualTo(configUrlFromClassLoader)
+        .isEqualTo(configUrlFromClassPathLoader);
+  }
+  
+  @Test
+  public void defaultConfigShouldIncludeStdout() {
+    LogService.reconfigure();
+    final Logger rootLogger = (Logger) LogService.getRootLogger();
+    
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+    assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNotNull();
+  }
+  
+  @Test
+  public void removeConsoleAppenderShouldRemoveStdout() {
+    LogService.reconfigure();
+    final Logger rootLogger = (Logger) LogService.getRootLogger();
+    
+    LogService.removeConsoleAppender();
+    
+    assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNull();
+  }
+  
+  @Test
+  public void restoreConsoleAppenderShouldRestoreStdout() {
+    LogService.reconfigure();
+    final Logger rootLogger = (Logger) LogService.getRootLogger();
+    
+    LogService.removeConsoleAppender();
+    
+    assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNull();
+    
+    LogService.restoreConsoleAppender();
+
+    assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNotNull();
+  }
+  
+  @Test
+  public void removeAndRestoreConsoleAppenderShouldAffectRootLogger() {
+    LogService.reconfigure();
+    
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+    
+    final Logger rootLogger = (Logger) LogService.getRootLogger();
+    
+    // assert "Console" is present for ROOT
+    Appender appender = rootLogger.getAppenders().get(LogService.STDOUT);
+    assertThat(appender).isNotNull();
+
+    LogService.removeConsoleAppender();
+    
+    // assert "Console" is not present for ROOT
+    appender = rootLogger.getAppenders().get(LogService.STDOUT);
+    assertThat(appender).isNull();
+    
+    LogService.restoreConsoleAppender();
+
+    // assert "Console" is present for ROOT
+    appender = rootLogger.getAppenders().get(LogService.STDOUT);
+    assertThat(appender).isNotNull();
+  }
+  
+  @Test
+  public void intializeAfterUsingLoggerShouldReconfigure() {
+    assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).as("log4j.configurationFile="+System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).isNullOrEmpty();
+    
+    Configurator.shutdown();
+    
+    LogManager.getRootLogger();
+
+    assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).as("log4j.configurationFile="+System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).isNullOrEmpty();
+    
+    LogService.reconfigure();
+    LogService.initialize();
+    
+    assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).as("log4j.configurationFile="+System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).contains(LogService.DEFAULT_CONFIG);
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+  }
+  
+  @Test
+  public void cliConfigLoadsAsResource() {
+    assertThat(this.cliConfigUrl).isNotNull();
+    assertThat(this.cliConfigUrl.toString()).contains(LogService.CLI_CONFIG);
+  }
+  
+  @Test
+  public void defaultConfigLoadsAsResource() {
+    assertThat(this.defaultConfigUrl).isNotNull();
+    assertThat(this.defaultConfigUrl.toString()).contains(LogService.DEFAULT_CONFIG);
+  }
+  
+  @Test
+  public void shouldConvertConfigurationFilePropertyValueToURL() throws Exception {
+    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, LogService.CLI_CONFIG);
+    
+    LogService.reconfigure();
+    
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isFalse();
+    assertThat(this.cliConfigUrl.toString()).contains(LogService.CLI_CONFIG);
+    assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).isEqualTo(this.cliConfigUrl.toString());
+    assertThat(LogService.getLogger().getName()).isEqualTo(getClass().getName());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19732b2d/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceIntegrationTestSupport.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceIntegrationTestSupport.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceIntegrationTestSupport.java
new file mode 100755
index 0000000..c6a5386
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceIntegrationTestSupport.java
@@ -0,0 +1,24 @@
+package com.gemstone.gemfire.internal.logging;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.logging.log4j.Level;
+
+public class LogServiceIntegrationTestSupport {
+
+  public static void writeConfigFile(final File configFile, final Level level) throws IOException {
+    final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
+    writer.write(
+        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+        "<Configuration>" +
+          "<Loggers>" +
+            "<Root level=\"" + level.name() + "\"/>" +
+          "</Loggers>" +
+         "</Configuration>"
+         );
+    writer.close();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19732b2d/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceJUnitTest.java
index ce1b6c2..8d6278a 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceJUnitTest.java
@@ -1,162 +1,94 @@
 package com.gemstone.gemfire.internal.logging;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.*;
+import static junitparams.JUnitParamsRunner.$;
+import static org.assertj.core.api.Assertions.*;
 
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.URL;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
 import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import com.gemstone.gemfire.internal.logging.log4j.AppenderContext;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
-import com.gemstone.gemfire.internal.ClassPathLoader;
-import com.gemstone.gemfire.internal.lang.SystemUtils;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
 
-@Category(IntegrationTest.class)
+/**
+ * Unit tests for LogService
+ * 
+ * @author Kirk Lund
+ */
+@Category(UnitTest.class)
+@RunWith(JUnitParamsRunner.class)
 public class LogServiceJUnitTest {
   
-  private File configFile;
-  
-  @Before
-  public void setUp() {
-    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
-  }
-  
-  @After
-  public void tearDown() {
-    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
-    LogService.reconfigure();
-    if (this.configFile != null && this.configFile.exists()) {
-      this.configFile.delete();
-    }
-  }
+  @Rule
+  public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
   
   @Test
-  public void testPropSetAndGetLogger() throws Exception {
-    this.configFile = new File(System.getProperty("java.io.tmpdir"), "log4j2.xml");
-    final String configFileName = this.configFile.toURI().toString();
-
-    writeConfigFile(this.configFile);
-    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configFileName);
-    LogService.reconfigure();
-    assertFalse(LogService.isUsingGemFireDefaultConfig());
+  public void getAppenderContextShouldHaveEmptyName() throws Exception {
+    final AppenderContext appenderContext = LogService.getAppenderContext();
     
-    // Assert that the correct log file will be found
-    assertEquals(configFileName, System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY));
-
-    // Assert that getLogger() returns a correctly named logger
-    assertEquals(this.getClass().getName(), LogService.getLogger().getName());
+    assertThat(appenderContext.getName()).isEmpty();
   }
-  
-  @Test
-  public void testInCurrentDirectory() throws Exception {
-    // if working directory is in classpath this test will fail
-    assumeFalse(SystemUtils.isInClassPath(System.getProperty("user.dir")));
-    System.out.println("Executing testInCurrentDirectory");
-    
-    this.configFile = new File(System.getProperty("user.dir"), "log4j2-test.xml");
-    String configFileURI = this.configFile.toURI().toString();
 
-    writeConfigFile(this.configFile);
-    LogService.reconfigure();
-    assertFalse(LogService.isUsingGemFireDefaultConfig());
-    ConfigurationFactory.getInstance().getConfiguration(null, null);
-    
-    assertEquals(configFileURI, System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY));
-  }
-  
   @Test
-  public void testInGemfireJar() throws Exception {
-    LogService.reconfigure();
-    assertTrue(LogService.isUsingGemFireDefaultConfig());
+  public void getAppenderContextWithNameShouldHaveName() throws Exception {
+    final String name = "someName";
+    final AppenderContext appenderContext = LogService.getAppenderContext(name);
     
-    // This ensures that the JVM isn't going to have a problem finding the config
-    // in a jar file.
-    ConfigurationFactory.getInstance().getConfiguration(null, null);
-
-    final String packagePath = LogService.class.getPackage().getName().replace('.', '/');
-    final URL configUrl = ClassPathLoader.getLatest().getResource(packagePath + "/log4j/log4j2-default.xml");
-
-    assertEquals(configUrl.toString(), System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY));
+    assertThat(appenderContext.getName()).isEqualTo(name);
   }
   
   @Test
-  public void testRemoveAddConsoleAppender() {
-    LogService.reconfigure();
-    assertTrue(LogService.isUsingGemFireDefaultConfig());
-    
-    assertEquals("", LogService.getRootLogger().getName());
-    final Logger rootLogger = (Logger) LogService.getRootLogger();
+  public void isUsingGemFireDefaultConfigShouldBeTrueIfDefaultConfig() {
+    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, LogService.DEFAULT_CONFIG);
     
-    // assert "nothing" is not present for ROOT
-    Appender appender = rootLogger.getAppenders().get("nothing");
-    assertNull(appender);
-    
-    // assert "Console" is present for ROOT
-    appender = rootLogger.getAppenders().get(LogService.STDOUT);
-    assertNotNull("Missing STDOUT: " + rootLogger.getAppenders(), appender); // fails when test is last one run
+    assertThat(LogService.isUsingGemFireDefaultConfig()).isTrue();
+  }
 
-    LogService.removeConsoleAppender();
-    
-    // assert "Console" is not present for ROOT
-    appender = rootLogger.getAppenders().get(LogService.STDOUT);
-    assertNull(appender);
+  @Test
+  public void isUsingGemFireDefaultConfigShouldBeFalseIfEmpty() {
+    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "");
     
-    LogService.restoreConsoleAppender();
-
-    // assert "Console" is present for ROOT
-    appender = rootLogger.getAppenders().get(LogService.STDOUT);
-    assertNotNull(appender);
+    assertThat(LogService.isUsingGemFireDefaultConfig()).isFalse();
   }
-  
+
   @Test
-  public void testInitializeAfterLogManager() {
-    LogManager.getRootLogger();
-    LogService.reconfigure();
-    LogService.initialize();
-    assertTrue(LogService.isUsingGemFireDefaultConfig());
+  public void isUsingGemFireDefaultConfigShouldBeFalseIfNull() {
+    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "");
+    
+    assertThat(LogService.isUsingGemFireDefaultConfig()).isFalse();
   }
-  
+
   @Test
-  public void cliConfigLoadsAsResource() {
-    URL configUrl = LogService.class.getResource(LogService.CLI_CONFIG);
-    assertNotNull(configUrl);
-    String configFilePropertyValue = configUrl.toString();
-    assertTrue(configFilePropertyValue.contains(LogService.CLI_CONFIG));
+  public void isUsingGemFireDefaultConfigShouldBeFalseIfCliConfig() {
+    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, LogService.CLI_CONFIG);
+    
+    assertThat(LogService.isUsingGemFireDefaultConfig()).isFalse();
   }
   
   @Test
-  public void defaultConfigLoadsAsResource() {
-    URL configUrl = LogService.class.getResource(LogService.CLI_CONFIG);
-    assertNotNull(configUrl);
-    String configFilePropertyValue = configUrl.toString();
-    assertTrue(configFilePropertyValue.contains(LogService.CLI_CONFIG));
+  @Parameters(method = "getToLevelParameters")
+  public void toLevelShouldReturnMatchingLog4jLevel(final int intLevel, final Level level) {
+    assertThat(LogService.toLevel(intLevel)).isSameAs(level);
   }
-  
-  private static void writeConfigFile(final File configFile) throws IOException {
-    final BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
-    writer.write(
-        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
-        "<Configuration>" +
-          "<Loggers>" +
-            "<Root level=\"DEBUG\"/>" +
-          "</Loggers>" +
-         "</Configuration>"
-         );
-    writer.close();
+
+  @SuppressWarnings("unused")
+  private static final Object[] getToLevelParameters() {
+    return $(
+        new Object[] { 0, Level.OFF },
+        new Object[] { 100, Level.FATAL },
+        new Object[] { 200, Level.ERROR },
+        new Object[] { 300, Level.WARN },
+        new Object[] { 400, Level.INFO },
+        new Object[] { 500, Level.DEBUG },
+        new Object[] { 600, Level.TRACE },
+        new Object[] { Integer.MAX_VALUE, Level.ALL }
+    );
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19732b2d/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceUserDirIntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceUserDirIntegrationJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceUserDirIntegrationJUnitTest.java
new file mode 100755
index 0000000..4d83c22
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LogServiceUserDirIntegrationJUnitTest.java
@@ -0,0 +1,70 @@
+package com.gemstone.gemfire.internal.logging;
+
+import static com.gemstone.gemfire.internal.logging.LogServiceIntegrationTestSupport.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assume.assumeFalse;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.ClearSystemProperties;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExternalResource;
+
+import com.gemstone.gemfire.internal.lang.SystemUtils;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Tests LogService when a log4j2 config file is in the user.dir
+ * 
+ * @author Kirk Lund
+ */
+@Category(IntegrationTest.class)
+public class LogServiceUserDirIntegrationJUnitTest {
+
+  @Rule
+  public final ClearSystemProperties clearConfigFileProperty = new ClearSystemProperties(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+  
+  @Rule
+  public final ExternalResource externalResource = new ExternalResource() {
+    @Override
+    protected void after() {
+      LogService.reconfigure();
+      assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+    }
+  };
+  
+  private File configFile;
+  
+  @Before
+  public void setUp() throws Exception {
+    this.configFile = new File(System.getProperty("user.dir"), "log4j2-test.xml");
+    writeConfigFile(this.configFile, Level.DEBUG);
+    LogService.reconfigure();
+  }
+  
+  @After
+  public void tearDown() {
+    this.configFile.delete();
+  }
+  
+  @Test
+  public void shouldPreferConfigInCurrentDirectoryIfFound() throws Exception {
+    // if working directory is in classpath this test will fail
+    assumeFalse(isUserDirInClassPath());
+    
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isFalse();
+    //ConfigurationFactory.getInstance().getConfiguration(null, null); TODO: delete
+    assertThat(System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY)).isEqualTo(this.configFile.toURI().toString());
+  }
+  
+  private static boolean isUserDirInClassPath() throws MalformedURLException {
+    return SystemUtils.isInClassPath(System.getProperty("user.dir"));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19732b2d/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingIntegrationTestSuite.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingIntegrationTestSuite.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingIntegrationTestSuite.java
index 1efaa59..dd9504b 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingIntegrationTestSuite.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingIntegrationTestSuite.java
@@ -7,7 +7,8 @@ import org.junit.runners.Suite;
 @Suite.SuiteClasses({
   DistributedSystemLogFileJUnitTest.class,
   LocatorLogFileJUnitTest.class,
-  LogServiceJUnitTest.class,
+  LogServiceIntegrationJUnitTest.class,
+  LogServiceUserDirIntegrationJUnitTest.class,
   MergeLogFilesJUnitTest.class,
 })
 public class LoggingIntegrationTestSuite {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19732b2d/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingUnitTestSuite.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingUnitTestSuite.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingUnitTestSuite.java
index cd39a9d..6b7b73e 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingUnitTestSuite.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/logging/LoggingUnitTestSuite.java
@@ -5,6 +5,7 @@ import org.junit.runners.Suite;
 
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
+  LogServiceJUnitTest.class,
   LogWriterImplJUnitTest.class,
   SortLogFileJUnitTest.class
 })