geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [04/14] incubator-geode git commit: GEODE-1255: Add test coverage for using a custom log4j2.xml with Geode
Date Thu, 05 May 2016 22:48:43 GMT
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
new file mode 100755
index 0000000..25e9528
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherTest.java
@@ -0,0 +1,898 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.distributed;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import edu.umd.cs.mtc.MultithreadedTestCase;
+import edu.umd.cs.mtc.TestFramework;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.lib.concurrent.Synchroniser;
+import org.jmock.lib.legacy.ClassImposteriser;
+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.rules.TestName;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.server.CacheServer;
+import com.gemstone.gemfire.distributed.ServerLauncher.Builder;
+import com.gemstone.gemfire.distributed.ServerLauncher.Command;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.support.DistributedSystemAdapter;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+/**
+ * The ServerLauncherTest class is a test suite of unit tests testing the contract, functionality and invariants
+ * of the ServerLauncher class.
+ *
+ * @see com.gemstone.gemfire.distributed.ServerLauncher
+ * @see com.gemstone.gemfire.distributed.ServerLauncher.Builder
+ * @see com.gemstone.gemfire.distributed.ServerLauncher.Command
+ * @see org.junit.Assert
+ * @see org.junit.Test
+ * @since 7.0
+ */
+@SuppressWarnings({"deprecation", "unused"})
+@Category(UnitTest.class)
+public class ServerLauncherTest {
+
+  private Mockery mockContext;
+
+  @Rule
+  public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+  
+  @Rule
+  public final TestName testName = new TestName();
+  
+  @Before
+  public void setup() {
+    mockContext = new Mockery() {{
+      setImposteriser(ClassImposteriser.INSTANCE);
+      setThreadingPolicy(new Synchroniser());
+    }};
+  }
+
+  @After
+  public void tearDown() {
+    mockContext.assertIsSatisfied();
+    mockContext = null;
+  }
+
+  @Test
+  public void testParseCommand() {
+    Builder builder = new Builder();
+
+    assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+
+    builder.parseCommand((String[]) null);
+
+    assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+
+    builder.parseCommand(); // empty String array
+
+    assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+
+    builder.parseCommand(Command.START.getName());
+
+    assertEquals(Command.START, builder.getCommand());
+
+    builder.parseCommand("Status");
+
+    assertEquals(Command.STATUS, builder.getCommand());
+
+    builder.parseCommand("sToP");
+
+    assertEquals(Command.STOP, builder.getCommand());
+
+    builder.parseCommand("--opt", "START", "-o", Command.STATUS.getName());
+
+    assertEquals(Command.START, builder.getCommand());
+
+    builder.setCommand(null);
+    builder.parseCommand("badCommandName", "--start", "stat");
+
+    assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+  }
+
+  @Test
+  public void testParseMemberName() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getMemberName());
+
+    builder.parseMemberName((String[]) null);
+
+    assertNull(builder.getMemberName());
+
+    builder.parseMemberName(); // empty String array
+
+    assertNull(builder.getMemberName());
+
+    builder.parseMemberName(Command.START.getName(), "--opt", "-o");
+
+    assertNull(builder.getMemberName());
+
+    builder.parseMemberName("memberOne");
+
+    assertEquals("memberOne", builder.getMemberName());
+  }
+
+  @Test
+  public void testSetAndGetCommand() {
+    Builder builder = new Builder();
+
+    assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+    assertSame(builder, builder.setCommand(Command.STATUS));
+    assertEquals(Command.STATUS, builder.getCommand());
+    assertSame(builder, builder.setCommand(null));
+    assertEquals(Builder.DEFAULT_COMMAND, builder.getCommand());
+  }
+
+  @Test
+  public void testSetAndGetMemberName() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getMemberName());
+    assertSame(builder, builder.setMemberName("serverOne"));
+    assertEquals("serverOne", builder.getMemberName());
+    assertSame(builder, builder.setMemberName(null));
+    assertNull(builder.getMemberName());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetMemberNameToBlankString() {
+    try {
+      new Builder().setMemberName("  ");
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_ERROR_MESSAGE.toLocalizedString("Server"),
+        expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetMemberNameToEmptyString() {
+    try {
+      new Builder().setMemberName("");
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_ERROR_MESSAGE.toLocalizedString("Server"),
+        expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetPid() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getPid());
+    assertSame(builder, builder.setPid(0));
+    assertEquals(0, builder.getPid().intValue());
+    assertSame(builder, builder.setPid(1));
+    assertEquals(1, builder.getPid().intValue());
+    assertSame(builder, builder.setPid(1024));
+    assertEquals(1024, builder.getPid().intValue());
+    assertSame(builder, builder.setPid(12345));
+    assertEquals(12345, builder.getPid().intValue());
+    assertSame(builder, builder.setPid(null));
+    assertNull(builder.getPid());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetPidToInvalidValue() {
+    try {
+      new Builder().setPid(-1);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals(LocalizedStrings.Launcher_Builder_PID_ERROR_MESSAGE.toLocalizedString(), expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetServerBindAddress() throws Exception {
+    Builder builder = new Builder();
+
+    assertNull(builder.getServerBindAddress());
+    assertSame(builder, builder.setServerBindAddress(null));
+    assertNull(builder.getServerBindAddress());
+    assertSame(builder, builder.setServerBindAddress(""));
+    assertNull(builder.getServerBindAddress());
+    assertSame(builder, builder.setServerBindAddress("  "));
+    assertNull(builder.getServerBindAddress());
+    assertSame(builder, builder.setServerBindAddress(InetAddress.getLocalHost().getCanonicalHostName()));
+    assertEquals(InetAddress.getLocalHost(), builder.getServerBindAddress());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetServerBindAddressToUnknownHost() {
+    try {
+      new Builder().setServerBindAddress("badHostName.badCompany.com");
+    }
+    catch (IllegalArgumentException expected) {
+      final String expectedMessage1 = LocalizedStrings.Launcher_Builder_UNKNOWN_HOST_ERROR_MESSAGE.toLocalizedString("Server");
+      final String expectedMessage2 = "badHostName.badCompany.com is not an address for this machine.";
+      assertTrue(expected.getMessage().equals(expectedMessage1) || expected.getMessage().equals(expectedMessage2));
+      if (expected.getMessage().equals(expectedMessage1)) {
+        assertTrue(expected.getCause() instanceof UnknownHostException);
+      }
+      throw expected;
+    }
+  }
+  
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetServerBindAddressToNonLocalHost() {
+    try {
+      new Builder().setServerBindAddress("yahoo.com");
+    }
+    catch (IllegalArgumentException expected) {
+      final String expectedMessage = "yahoo.com is not an address for this machine.";
+      assertEquals(expectedMessage, expected.getMessage());
+      throw expected;
+    }
+  }
+  
+  @Test
+  public void testSetServerBindAddressToLocalHost() throws Exception {
+    String host = InetAddress.getLocalHost().getHostName();            
+    new Builder().setServerBindAddress(host);
+  }
+
+  @Test
+  public void testSetAndGetHostnameForClients() {
+    final Builder builder = new Builder();
+
+    assertNull(builder.getHostNameForClients());
+    assertSame(builder, builder.setHostNameForClients("Pegasus"));
+    assertEquals("Pegasus", builder.getHostNameForClients());
+    assertSame(builder, builder.setHostNameForClients(null));
+    assertNull(builder.getHostNameForClients());
+  }
+
+  @Test
+  public void testSetAndGetServerPort() {
+    Builder builder = new Builder();
+
+    assertEquals(ServerLauncher.DEFAULT_SERVER_PORT, builder.getServerPort());
+    assertSame(builder, builder.setServerPort(0));
+    assertEquals(0, builder.getServerPort().intValue());
+    assertSame(builder, builder.setServerPort(1));
+    assertEquals(1, builder.getServerPort().intValue());
+    assertSame(builder, builder.setServerPort(80));
+    assertEquals(80, builder.getServerPort().intValue());
+    assertSame(builder, builder.setServerPort(1024));
+    assertEquals(1024, builder.getServerPort().intValue());
+    assertSame(builder, builder.setServerPort(65535));
+    assertEquals(65535, builder.getServerPort().intValue());
+    assertSame(builder, builder.setServerPort(null));
+    assertEquals(ServerLauncher.DEFAULT_SERVER_PORT, builder.getServerPort());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetServerPortToOverflow() {
+    try {
+      new Builder().setServerPort(65536);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals(LocalizedStrings.Launcher_Builder_INVALID_PORT_ERROR_MESSAGE.toLocalizedString("Server"),
+        expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetServerPortToUnderflow() {
+    try {
+      new Builder().setServerPort(-1);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals(LocalizedStrings.Launcher_Builder_INVALID_PORT_ERROR_MESSAGE.toLocalizedString("Server"),
+        expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetCriticalHeapPercentage() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getCriticalHeapPercentage());
+    assertSame(builder, builder.setCriticalHeapPercentage(55.5f));
+    assertEquals(55.5f, builder.getCriticalHeapPercentage().floatValue(), 0.0f);
+    assertSame(builder, builder.setCriticalHeapPercentage(null));
+    assertNull(builder.getCriticalHeapPercentage());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetCriticalHeapPercentageToOverflow() {
+    try {
+      new Builder().setCriticalHeapPercentage(100.01f);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("Critical heap percentage (100.01) must be between 0 and 100!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetCriticalHeapPercentageToUnderflow() {
+    try {
+      new Builder().setCriticalHeapPercentage(-0.01f);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("Critical heap percentage (-0.01) must be between 0 and 100!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetEvictionHeapPercentage() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getEvictionHeapPercentage());
+    assertSame(builder, builder.setEvictionHeapPercentage(55.55f));
+    assertEquals(55.55f, builder.getEvictionHeapPercentage().floatValue(), 0.0f);
+    assertSame(builder, builder.setEvictionHeapPercentage(null));
+    assertNull(builder.getEvictionHeapPercentage());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetEvictionHeapPercentageToOverflow() {
+    try {
+      new Builder().setEvictionHeapPercentage(101.0f);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("Eviction heap percentage (101.0) must be between 0 and 100!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetEvictionHeapPercentageToUnderflow() {
+    try {
+      new Builder().setEvictionHeapPercentage(-10.0f);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("Eviction heap percentage (-10.0) must be between 0 and 100!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetMaxConnections() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getMaxConnections());
+    assertSame(builder, builder.setMaxConnections(1000));
+    assertEquals(1000, builder.getMaxConnections().intValue());
+    assertSame(builder, builder.setMaxConnections(null));
+    assertNull(builder.getMaxConnections());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetMaxConnectionsWithIllegalValue() {
+    try {
+      new Builder().setMaxConnections(-10);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("Max Connections (-10) must be greater than 0!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetMaxMessageCount() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getMaxMessageCount());
+    assertSame(builder, builder.setMaxMessageCount(50));
+    assertEquals(50, builder.getMaxMessageCount().intValue());
+    assertSame(builder, builder.setMaxMessageCount(null));
+    assertNull(builder.getMaxMessageCount());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetMaxMessageCountWithIllegalValue() {
+    try {
+      new Builder().setMaxMessageCount(0);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("Max Message Count (0) must be greater than 0!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetMaxThreads() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getMaxThreads());
+    assertSame(builder, builder.setMaxThreads(16));
+    assertEquals(16, builder.getMaxThreads().intValue());
+    assertSame(builder, builder.setMaxThreads(null));
+    assertNull(builder.getMaxThreads());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetMaxThreadsWithIllegalValue() {
+    try {
+      new Builder().setMaxThreads(-4);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("Max Threads (-4) must be greater than 0!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetMessageTimeToLive() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getMessageTimeToLive());
+    assertSame(builder, builder.setMessageTimeToLive(30000));
+    assertEquals(30000, builder.getMessageTimeToLive().intValue());
+    assertSame(builder, builder.setMessageTimeToLive(null));
+    assertNull(builder.getMessageTimeToLive());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetMessageTimeToLiveWithIllegalValue() {
+    try {
+      new Builder().setMessageTimeToLive(0);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("Message Time To Live (0) must be greater than 0!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testSetAndGetSocketBufferSize() {
+    Builder builder = new Builder();
+
+    assertNull(builder.getSocketBufferSize());
+    assertSame(builder, builder.setSocketBufferSize(32768));
+    assertEquals(32768, builder.getSocketBufferSize().intValue());
+    assertSame(builder, builder.setSocketBufferSize(null));
+    assertNull(builder.getSocketBufferSize());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSetSocketBufferSizeWithIllegalValue() {
+    try {
+      new Builder().setSocketBufferSize(-8192);
+    }
+    catch (IllegalArgumentException expected) {
+      assertEquals("The Server's Socket Buffer Size (-8192) must be greater than 0!", expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testBuildWithMemberNameSetInApiPropertiesOnStart() {
+    ServerLauncher launcher = new Builder()
+      .setCommand(ServerLauncher.Command.START)
+      .setMemberName(null)
+      .set(DistributionConfig.NAME_NAME, "serverABC")
+      .build();
+
+    assertNotNull(launcher);
+    assertEquals(ServerLauncher.Command.START, launcher.getCommand());
+    assertNull(launcher.getMemberName());
+    assertEquals("serverABC", launcher.getProperties().getProperty(DistributionConfig.NAME_NAME));
+  }
+
+  @Test
+  public void testBuildWithMemberNameSetInSystemPropertiesOnStart() {
+    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + DistributionConfig.NAME_NAME, "serverXYZ");
+
+    ServerLauncher launcher = new Builder()
+      .setCommand(ServerLauncher.Command.START)
+      .setMemberName(null)
+      .build();
+
+    assertNotNull(launcher);
+    assertEquals(ServerLauncher.Command.START, launcher.getCommand());
+    assertNull(launcher.getMemberName());
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testBuildNoMemberNameOnStart() {
+    try {
+      new Builder().setCommand(Command.START).build();
+    }
+    catch (IllegalStateException expected) {
+      assertEquals(LocalizedStrings.Launcher_Builder_MEMBER_NAME_VALIDATION_ERROR_MESSAGE.toLocalizedString("Server"),
+        expected.getMessage());
+      throw expected;
+    }
+  }
+
+  @Test
+  public void testIsServing() {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.singletonList(mockCacheServer)));
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+    assertTrue(serverLauncher.isServing(mockCache));
+  }
+
+  @Test
+  public void testIsServingWhenNoCacheServersExist() {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.emptyList()));
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+    assertFalse(serverLauncher.isServing(mockCache));
+  }
+
+  @Test
+  public void reconnectedCacheIsDiscovered() throws Exception {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final Cache mockReconnectedCache = mockContext.mock(Cache.class, "ReconnectedCache");
+
+    mockContext.checking(new Expectations() {{
+      exactly(2).of(mockCache).isReconnecting();
+      will(returnValue(Boolean.FALSE));
+
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.emptyList()));
+
+      oneOf(mockCache).isReconnecting();
+      will(returnValue(Boolean.TRUE));
+
+      oneOf(mockCache).getReconnectedCache();
+      will(returnValue(mockReconnectedCache));
+
+      oneOf(mockReconnectedCache).close();
+
+    }});
+
+    final ServerLauncher serverLauncher =
+            new Builder()
+                    .setMemberName("serverOne")
+                    .setCache(mockCache)
+                    .build();
+
+    assertNotNull(serverLauncher);
+    serverLauncher.waitOnServer();
+  }
+
+  @Test
+  public void reconnectingDistributedSystemIsDisconnectedOnStop() throws Exception {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
+    final Cache mockReconnectedCache = mockContext.mock(Cache.class, "ReconnectedCache");
+
+    mockContext.checking(new Expectations() {{
+      exactly(1).of(mockCache).isReconnecting();
+      will(returnValue(Boolean.TRUE));
+
+      exactly(1).of(mockCache).getReconnectedCache();
+      will(returnValue(mockReconnectedCache));
+
+      exactly(2).of(mockReconnectedCache).isReconnecting();
+      will(returnValue(Boolean.TRUE));
+
+      exactly(1).of(mockReconnectedCache).getReconnectedCache();
+      will(returnValue(null));
+
+      oneOf(mockReconnectedCache).getDistributedSystem();
+      will(returnValue(mockDistributedSystem));
+
+      oneOf(mockDistributedSystem).stopReconnecting();
+
+      oneOf(mockReconnectedCache).close();
+    }});
+
+    final ServerLauncher serverLauncher =
+            new Builder()
+                    .setMemberName("serverOne")
+                    .setCache(mockCache)
+                    .build();
+
+    assertNotNull(serverLauncher);
+    serverLauncher.setIsRunningForTest();
+    serverLauncher.stop();
+  }
+
+  @Test
+  public void testIsWaiting() {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getDistributedSystem();
+      will(returnValue(mockDistributedSystem));
+      oneOf(mockDistributedSystem).isConnected();
+      will(returnValue(true));
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+
+    serverLauncher.running.set(true);
+
+    assertTrue(serverLauncher.isRunning());
+    assertTrue(serverLauncher.isWaiting(mockCache));
+  }
+
+  @Test
+  public void testIsWaitingWhenNotConnected() {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getDistributedSystem();
+      will(returnValue(mockDistributedSystem));
+      oneOf(mockDistributedSystem).isConnected();
+      will(returnValue(false));
+      oneOf(mockCache).isReconnecting();
+      will(returnValue(Boolean.FALSE));
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+
+    serverLauncher.running.set(true);
+
+    assertTrue(serverLauncher.isRunning());
+    assertFalse(serverLauncher.isWaiting(mockCache));
+  }
+
+  @Test
+  public void testIsWaitingWhenNotRunning() {
+    ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+
+    serverLauncher.running.set(false);
+
+    assertFalse(serverLauncher.isRunning());
+    assertFalse(serverLauncher.isWaiting(null));
+  }
+
+  @Test
+  public void testWaitOnServer() throws Throwable {
+    TestFramework.runOnce(new ServerWaitMultiThreadedTestCase());
+  }
+
+  @Test
+  public void testIsDefaultServerEnabled() {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.emptyList()));
+    }});
+
+    ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+    assertFalse(serverLauncher.isDisableDefaultServer());
+    assertTrue(serverLauncher.isDefaultServerEnabled(mockCache));
+  }
+
+  @Test
+  public void testIsDefaultServerEnabledWhenCacheServersExist() {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.singletonList(mockCacheServer)));
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(false).build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+    assertFalse(serverLauncher.isDisableDefaultServer());
+    assertFalse(serverLauncher.isDefaultServerEnabled(mockCache));
+  }
+  @Test
+  public void testIsDefaultServerEnabledWhenNoCacheServersExistAndDefaultServerDisabled() {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.emptyList()));
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(true).build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+    assertTrue(serverLauncher.isDisableDefaultServer());
+    assertFalse(serverLauncher.isDefaultServerEnabled(mockCache));
+  }
+
+  @Test
+  public void testStartCacheServer() throws IOException {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.emptyList()));
+      oneOf(mockCache).addCacheServer();
+      will(returnValue(mockCacheServer));
+      oneOf(mockCacheServer).setBindAddress(with(aNull(String.class)));
+      oneOf(mockCacheServer).setPort(with(equal(11235)));
+      oneOf(mockCacheServer).start();
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne")
+      .setServerBindAddress(null)
+      .setServerPort(11235)
+      .setDisableDefaultServer(false)
+      .build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+    assertFalse(serverLauncher.isDisableDefaultServer());
+
+    serverLauncher.startCacheServer(mockCache);
+  }
+
+  @Test
+  public void testStartCacheServerWhenDefaultServerDisabled() throws IOException {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.emptyList()));
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(true).build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+    assertTrue(serverLauncher.isDisableDefaultServer());
+
+    serverLauncher.startCacheServer(mockCache);
+  }
+
+  @Test
+  public void testStartCacheServerWithExistingCacheServer() throws IOException {
+    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+    final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
+
+    mockContext.checking(new Expectations() {{
+      oneOf(mockCache).getCacheServers();
+      will(returnValue(Collections.singletonList(mockCacheServer)));
+    }});
+
+    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(false).build();
+
+    assertNotNull(serverLauncher);
+    assertEquals("serverOne", serverLauncher.getMemberName());
+    assertFalse(serverLauncher.isDisableDefaultServer());
+
+    serverLauncher.startCacheServer(mockCache);
+  }
+  
+  public static void main(final String... args) {
+    System.err.printf("Thread (%1$s) is daemon (%2$s)%n", Thread.currentThread().getName(),
+      Thread.currentThread().isDaemon());
+    new Builder(args).setCommand(Command.START).build().run();
+  }
+
+  private final class ServerWaitMultiThreadedTestCase extends MultithreadedTestCase {
+
+    private final AtomicBoolean connectionStateHolder = new AtomicBoolean(true);
+
+    private ServerLauncher serverLauncher;
+
+    @Override
+    public void initialize() {
+      super.initialize();
+
+      final Cache mockCache = mockContext.mock(Cache.class, "Cache");
+
+      final DistributedSystem mockDistributedSystem = new DistributedSystemAdapter() {
+        @Override public boolean isConnected() {
+          return connectionStateHolder.get();
+        }
+      };
+
+      mockContext.checking(new Expectations() {{
+        allowing(mockCache).getDistributedSystem();
+        will(returnValue(mockDistributedSystem));
+        allowing(mockCache).isReconnecting();
+        will(returnValue(Boolean.FALSE));
+        allowing(mockCache).getCacheServers();
+        will(returnValue(Collections.emptyList()));
+        oneOf(mockCache).close();
+      }});
+
+      this.serverLauncher = new Builder().setMemberName("dataMember").setDisableDefaultServer(true)
+        .setCache(mockCache).build();
+
+      assertNotNull(this.serverLauncher);
+      assertEquals("dataMember", this.serverLauncher.getMemberName());
+      assertTrue(this.serverLauncher.isDisableDefaultServer());
+      assertTrue(connectionStateHolder.get());
+    }
+
+    public void thread1() {
+      assertTick(0);
+
+      Thread.currentThread().setName("GemFire Data Member 'main' Thread");
+      this.serverLauncher.running.set(true);
+
+      assertTrue(this.serverLauncher.isRunning());
+      assertFalse(this.serverLauncher.isServing(this.serverLauncher.getCache()));
+      assertTrue(this.serverLauncher.isWaiting(this.serverLauncher.getCache()));
+
+      this.serverLauncher.waitOnServer();
+
+      assertTick(1); // NOTE the tick does not advance when the other Thread terminates
+    }
+
+    public void thread2() {
+      waitForTick(1);
+
+      Thread.currentThread().setName("GemFire 'shutdown' Thread");
+
+      assertTrue(this.serverLauncher.isRunning());
+
+      this.connectionStateHolder.set(false);
+    }
+
+    @Override
+    public void finish() {
+      super.finish();
+      assertFalse(this.serverLauncher.isRunning());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderIntegrationTest.java
new file mode 100644
index 0000000..f04c7cf
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderIntegrationTest.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.distributed;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.Mockito;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.distributed.AbstractLauncher.Status;
+import com.gemstone.gemfire.distributed.ServerLauncher.Builder;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.process.ProcessType;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Extracted from ServerLauncherLocalIntegrationTest.
+ */
+@Category(IntegrationTest.class)
+public class ServerLauncherWithProviderIntegrationTest extends AbstractServerLauncherIntegrationTestCase {
+
+  @Before
+  public final void setUpServerLauncherWithSpringTest() throws Exception {
+    disconnectFromDS();
+    System.setProperty(ProcessType.TEST_PREFIX_PROPERTY, getUniqueName()+"-");
+  }
+
+  @After
+  public final void tearDownServerLauncherWithSpringTest() throws Exception {
+    MockServerLauncherCacheProvider.setCache(null);
+    disconnectFromDS();
+    
+  }
+
+  // NOTE make sure bugs like Trac #51201 never happen again!!!
+  @Test
+  public void testBootstrapGemFireServerWithProvider() throws Throwable {
+    Cache mockCache = Mockito.mock(Cache.class);
+    MockServerLauncherCacheProvider.setCache(mockCache);
+    this.launcher = new Builder()
+      .setDisableDefaultServer(true)
+      .setForce(true)
+      .setMemberName(getUniqueName())
+      .setSpringXmlLocation("spring/spring-gemfire-context.xml")
+      .set(DistributionConfig.MCAST_PORT_NAME, "0")
+      .build();
+
+    assertNotNull(this.launcher);
+
+    try {
+      assertEquals(Status.ONLINE, this.launcher.start().getStatus());
+
+      waitForServerToStart(this.launcher);
+
+      Cache cache = this.launcher.getCache();
+
+      assertEquals(mockCache, cache);
+    }
+    catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      assertNull(this.launcher.getCache());
+    }
+    catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderJUnitTest.java
deleted file mode 100644
index 9728485..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherWithProviderJUnitTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gemstone.gemfire.distributed;
-
-import static org.junit.Assert.*;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.mockito.Mockito;
-
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.distributed.AbstractLauncher.Status;
-import com.gemstone.gemfire.distributed.ServerLauncher.Builder;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.process.ProcessType;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-
-/**
- * Extracted from ServerLauncherLocalJUnitTest.
- * 
- */
-@Category(IntegrationTest.class)
-public class ServerLauncherWithProviderJUnitTest extends AbstractServerLauncherJUnitTestCase {
-
-  @Before
-  public final void setUpServerLauncherWithSpringTest() throws Exception {
-    disconnectFromDS();
-    System.setProperty(ProcessType.TEST_PREFIX_PROPERTY, getUniqueName()+"-");
-  }
-
-  @After
-  public final void tearDownServerLauncherWithSpringTest() throws Exception {
-    MockServerLauncherCacheProvider.setCache(null);
-    disconnectFromDS();
-    
-  }
-
-  // NOTE make sure bugs like Trac #51201 never happen again!!!
-  @Test
-  public void testBootstrapGemFireServerWithProvider() throws Throwable {
-    Cache mockCache = Mockito.mock(Cache.class);
-    MockServerLauncherCacheProvider.setCache(mockCache);
-    this.launcher = new Builder()
-      .setDisableDefaultServer(true)
-      .setForce(true)
-      .setMemberName(getUniqueName())
-      .setSpringXmlLocation("spring/spring-gemfire-context.xml")
-      .set(DistributionConfig.MCAST_PORT_NAME, "0")
-      .build();
-
-    assertNotNull(this.launcher);
-
-    try {
-      assertEquals(Status.ONLINE, this.launcher.start().getStatus());
-
-      waitForServerToStart(this.launcher);
-
-      Cache cache = this.launcher.getCache();
-
-      assertEquals(mockCache, cache);
-    }
-    catch (Throwable e) {
-      this.errorCollector.addError(e);
-    }
-
-    try {
-      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
-      assertNull(this.launcher.getCache());
-    }
-    catch (Throwable e) {
-      this.errorCollector.addError(e);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/internal/ClassBuilder.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/ClassBuilder.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/ClassBuilder.java
index 780ed4f..97062e5 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/ClassBuilder.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/ClassBuilder.java
@@ -40,7 +40,7 @@ import javax.tools.SimpleJavaFileObject;
 import javax.tools.ToolProvider;
 
 /**
- * Test framework utility class to programatically create classes, JARs and ClassLoaders that include the classes.
+ * Test framework utility class to programmatically create classes, JARs and ClassLoaders that include the classes.
  * 
  * @since 7.0
  */

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/BasicAppender.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/BasicAppender.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/BasicAppender.java
new file mode 100644
index 0000000..0b04379
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/BasicAppender.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.logging.log4j.custom;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+
+@Plugin(name = "Basic", category = "Core", elementType = "appender", printObject = true)
+public class BasicAppender extends AbstractAppender {
+
+  private static volatile BasicAppender instance;
+
+  private final List<LogEvent> events = new ArrayList<>();
+
+  public BasicAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout) {
+    super(name, filter, layout);
+  }
+
+  @PluginFactory
+  public static BasicAppender createAppender(@PluginAttribute("name") String name,
+                                             @PluginAttribute("ignoreExceptions") boolean ignoreExceptions,
+                                             @PluginElement("Layout") Layout layout,
+                                             @PluginElement("Filters") Filter filter) {
+    if (layout == null) {
+      layout = PatternLayout.createDefaultLayout();
+    }
+    instance = new BasicAppender(name, filter, layout);
+    return instance;
+  }
+
+  public static BasicAppender getInstance() {
+    return instance;
+  }
+
+  public static void clearInstance() {
+    instance = null;
+  }
+
+  public static void clearEvents() {
+    instance.events.clear();
+  }
+
+  @Override
+  public void append(final LogEvent event) {
+    this.events.add(event);
+  }
+
+  public List<LogEvent> events() {
+    return this.events;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest.java
new file mode 100644
index 0000000..632b69c
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfigWithCacheIntegrationTest.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.logging.log4j.custom;
+
+import static com.gemstone.gemfire.internal.logging.log4j.custom.CustomConfiguration.*;
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.SystemErrRule;
+import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import com.gemstone.gemfire.LogWriter;
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.logging.log4j.Configurator;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests with custom log4j2 configuration.
+ */
+@Category(IntegrationTest.class)
+public class CustomConfigWithCacheIntegrationTest {
+
+  private String beforeConfigFileProp;
+  private Level beforeLevel;
+
+  private File customConfigFile;
+  private Cache cache;
+
+  @Rule
+  public SystemErrRule systemErrRule = new SystemErrRule().enableLog();
+
+  @Rule
+  public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Before
+  public void setUp() throws Exception {
+    Configurator.shutdown();
+    BasicAppender.clearInstance();
+
+    this.beforeConfigFileProp = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+    this.beforeLevel = StatusLogger.getLogger().getLevel();
+
+    this.customConfigFile = createConfigFileIn(this.temporaryFolder.getRoot());
+
+    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.customConfigFile.getAbsolutePath());
+
+    Properties gemfireProperties = new Properties();
+    gemfireProperties.put(DistributionConfig.LOCATORS_NAME, "");
+    gemfireProperties.put(DistributionConfig.MCAST_PORT_NAME, "0");
+    gemfireProperties.put(DistributionConfig.LOG_LEVEL_NAME, "info");
+    this.cache = new CacheFactory(gemfireProperties).create();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    if (this.cache != null) {
+      this.cache.getDistributedSystem().disconnect();
+    }
+
+    Configurator.shutdown();
+
+    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+    if (this.beforeConfigFileProp != null) {
+      System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.beforeConfigFileProp);
+    }
+    StatusLogger.getLogger().setLevel(this.beforeLevel);
+
+    LogService.reconfigure();
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+
+    BasicAppender.clearInstance();
+
+    assertThat(this.systemErrRule.getLog()).isEmpty();
+  }
+
+  @Test
+  public void cacheLogWriterMessageShouldMatchCustomConfig() throws Exception {
+    String logLogger = LogService.MAIN_LOGGER_NAME;
+    Level logLevel = Level.INFO;
+    String logMessage = "this is a log statement from " + testName.getMethodName();
+
+    LogWriter logger = this.cache.getLogger();
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isFalse();
+
+    BasicAppender.clearEvents();
+
+    logger.info(logMessage);
+
+    BasicAppender appender = BasicAppender.getInstance();
+    assertThat(appender).isNotNull();
+    assertThat(appender.events().size()).isGreaterThan(0);
+
+    LogEvent event = null;
+    for (LogEvent logEvent : appender.events()) {
+      if (logEvent.getMessage().getFormattedMessage().contains(logMessage)) {
+        event = logEvent;
+        break;
+      }
+    }
+
+    assertThat(event).isNotNull();
+
+    assertThat(event.getLoggerName()).isEqualTo(logLogger);
+    assertThat(event.getLevel()).isEqualTo(logLevel);
+    assertThat(event.getMessage().getFormattedMessage()).isEqualTo(logMessage);
+
+    assertThat(systemOutRule.getLog()).contains(logLevel.name());
+    assertThat(systemOutRule.getLog()).contains(logMessage);
+    assertThat(systemOutRule.getLog()).contains(CONFIG_LAYOUT_PREFIX);
+    assertThat(systemOutRule.getLog()).containsPattern(defineLogStatementRegex(logLevel, logMessage));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest.java
new file mode 100644
index 0000000..631f232
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfigWithLogServiceIntegrationTest.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.logging.log4j.custom;
+
+import static com.gemstone.gemfire.internal.logging.log4j.custom.CustomConfiguration.*;
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.File;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.SystemErrRule;
+import org.junit.contrib.java.lang.system.SystemOutRule;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.logging.log4j.Configurator;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests with custom log4j2 configuration.
+ */
+@Category(IntegrationTest.class)
+public class CustomConfigWithLogServiceIntegrationTest {
+
+  private String beforeConfigFileProp;
+  private Level beforeLevel;
+
+  private File customConfigFile;
+
+  @Rule
+  public SystemErrRule systemErrRule = new SystemErrRule().enableLog();
+
+  @Rule
+  public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Before
+  public void setUp() throws Exception {
+    Configurator.shutdown();
+    BasicAppender.clearInstance();
+
+    this.beforeConfigFileProp = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+    this.beforeLevel = StatusLogger.getLogger().getLevel();
+
+    this.customConfigFile = createConfigFileIn(this.temporaryFolder.getRoot());
+
+    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.customConfigFile.getAbsolutePath());
+    LogService.reconfigure();
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isFalse();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    Configurator.shutdown();
+
+    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+    if (this.beforeConfigFileProp != null) {
+      System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.beforeConfigFileProp);
+    }
+    StatusLogger.getLogger().setLevel(this.beforeLevel);
+
+    LogService.reconfigure();
+    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+
+    BasicAppender.clearInstance();
+
+    assertThat(this.systemErrRule.getLog()).isEmpty();
+  }
+
+  @Test
+  public void logEventShouldMatchCustomConfig() throws Exception {
+    String logLogger = getClass().getName();
+    Level logLevel = Level.DEBUG;
+    String logMessage = "this is a log statement";
+
+    Logger logger = LogService.getLogger();
+    logger.debug(logMessage);
+
+    BasicAppender appender = BasicAppender.getInstance();
+    assertThat(appender).isNotNull();
+    assertThat(appender.events()).hasSize(1);
+
+    LogEvent event = appender.events().get(0);
+    assertThat(event.getLoggerName()).isEqualTo(logLogger);
+    assertThat(event.getLevel()).isEqualTo(logLevel);
+    assertThat(event.getMessage().getFormattedMessage()).isEqualTo(logMessage);
+
+    assertThat(systemOutRule.getLog()).contains(logLevel.name());
+    assertThat(systemOutRule.getLog()).contains(logMessage);
+    assertThat(systemOutRule.getLog()).contains(CONFIG_LAYOUT_PREFIX);
+    assertThat(systemOutRule.getLog()).matches(defineLogStatementRegex(logLevel, logMessage));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfiguration.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfiguration.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfiguration.java
new file mode 100644
index 0000000..05c72d6
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/logging/log4j/custom/CustomConfiguration.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.logging.log4j.custom;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.logging.log4j.Level;
+
+public class CustomConfiguration {
+
+  public static final String CONFIG_FILE_NAME = "log4j2-custom.xml";
+  public static final String CONFIG_LAYOUT_PREFIX = "CUSTOM";
+
+  protected CustomConfiguration() {
+  }
+
+  public static URL openConfigResource() {
+    return new CustomConfiguration().getClass().getResource(CONFIG_FILE_NAME);
+  }
+
+  public static File createConfigFileIn(final File targetFolder) throws IOException, URISyntaxException {
+    URL resource = openConfigResource();
+    File targetFile = new File(targetFolder, CONFIG_FILE_NAME);
+    IOUtils.copy(resource.openStream(), new FileOutputStream(targetFile));
+    assertThat(targetFile).hasSameContentAs(new File(resource.toURI()));
+    return targetFile;
+  }
+
+  private static final String DATE = "((?:19|20)\\\\d\\\\d)/(0?[1-9]|1[012])/([12][0-9]|3[01]|0?[1-9])";
+
+  private static final String TIME = "\\b(?<!')([xXzZ])(?!')\\b";
+
+  public static String defineLogStatementRegex(final Level level, final String message) {
+    // CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n
+    return CONFIG_LAYOUT_PREFIX + ": level=" + level.toString() + " time=" + ".*" + " message=" + message + "\nthrowable=\n";
+  }
+
+  public static String defineLogStatementRegex(final Level level, final String message, final String throwable) {
+    // CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n
+    return CONFIG_LAYOUT_PREFIX + ": level=" + level.toString() + " time=" + ".*" + " message=" + message + "\nthrowable=" + throwable + "\n";
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java
index 6255af1..583f4d1 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/FileProcessControllerIntegrationJUnitTest.java
@@ -40,7 +40,6 @@ import org.junit.rules.TemporaryFolder;
 import org.junit.rules.TestName;
 
 import com.gemstone.gemfire.distributed.LocatorLauncher;
-import com.gemstone.gemfire.distributed.LocatorStateJUnitTest;
 import com.gemstone.gemfire.distributed.AbstractLauncher.Status;
 import com.gemstone.gemfire.distributed.LocatorLauncher.Builder;
 import com.gemstone.gemfire.distributed.LocatorLauncher.LocatorState;
@@ -51,16 +50,16 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
  */
 @Category(IntegrationTest.class)
 public class FileProcessControllerIntegrationJUnitTest {
-  
+
+  private ProcessType processType;
+  private ExecutorService executor;
+
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
   
   @Rule
   public TestName testName = new TestName();
   
-  private ProcessType processType;
-  private ExecutorService executor;
-  
   @Before
   public void setUp() throws Exception {
     this.processType = ProcessType.LOCATOR;
@@ -114,8 +113,8 @@ public class FileProcessControllerIntegrationJUnitTest {
     // when: status is called in one thread and json is written to the file
     AtomicReference<String> status = new AtomicReference<String>();
     AtomicReference<Exception> exception = new AtomicReference<Exception>();
-    ExecutorService executor = Executors.newSingleThreadExecutor();
-    executor.execute(new Runnable() {
+    this.executor = Executors.newSingleThreadExecutor();
+    this.executor.execute(new Runnable() {
       @Override
       public void run() {
         try {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfsh.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfsh.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfsh.java
index 156a198..c21e0c4 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfsh.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfsh.java
@@ -23,16 +23,12 @@ import jline.console.ConsoleReader;
 import org.springframework.shell.core.ExitShellRequest;
 import org.springframework.shell.event.ShellStatus.Status;
 
-import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
 import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.Writer;
 import java.util.Properties;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -60,14 +56,14 @@ public class HeadlessGfsh implements ResultHandler {
   private long timeout = 20;
   public String outputString = null;
 
-  public HeadlessGfsh(String name, int timeout) throws ClassNotFoundException, IOException {
-    this(name, timeout, null);
+  public HeadlessGfsh(String name, int timeout, String parentDir) throws ClassNotFoundException, IOException {
+    this(name, timeout, null, parentDir);
   }
 
-  public HeadlessGfsh(String name, int timeout, Properties envProps) throws ClassNotFoundException, IOException {
+  public HeadlessGfsh(String name, int timeout, Properties envProps, String parentDir) throws ClassNotFoundException, IOException {
     this.timeout = timeout;
     System.setProperty("jline.terminal", GfshUnsupportedTerminal.class.getName());
-    this.shell = new HeadlessGfshShell(name, this);
+    this.shell = new HeadlessGfshShell(name, this, parentDir);
     this.shell.setEnvProperty(Gfsh.ENV_APP_RESULT_VIEWER, "non-basic");
 
     if (envProps != null) {
@@ -175,8 +171,8 @@ public class HeadlessGfsh implements ResultHandler {
     private boolean hasError = false;
     boolean stopCalledThroughAPI = false;
 
-    protected HeadlessGfshShell(String testName, ResultHandler handler) throws ClassNotFoundException, IOException {
-      super(false, new String[]{}, new HeadlessGfshConfig(testName));
+    protected HeadlessGfshShell(String testName, ResultHandler handler, String parentDir) throws ClassNotFoundException, IOException {
+      super(false, new String[]{}, new HeadlessGfshConfig(testName, parentDir));
       this.handler = handler;
     }
 
@@ -297,7 +293,6 @@ public class HeadlessGfsh implements ResultHandler {
     }
   }
 
-
   /**
    * HeadlessGfshConfig for tests. Taken from TestableGfsh
    */
@@ -312,7 +307,7 @@ public class HeadlessGfsh implements ResultHandler {
     private String name;
     private String generatedHistoryFileName = null;
 
-    public HeadlessGfshConfig(String name) {
+    public HeadlessGfshConfig(String name, String parentDir) {
       this.name = name;
 
       if (isDUnitTest(this.name)) {
@@ -321,8 +316,8 @@ public class HeadlessGfsh implements ResultHandler {
         fileNamePrefix = "non-hydra-client";
       }
 
-      parentDir = new File("gfsh_files");
-      parentDir.mkdirs();
+      this.parentDir = new File(parentDir);
+      this.parentDir.mkdirs();
     }
 
     private static boolean isDUnitTest(String name) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfshIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfshIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfshIntegrationTest.java
new file mode 100644
index 0000000..7bfde5b
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfshIntegrationTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.management.internal.cli;
+
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
+import static com.gemstone.gemfire.internal.AvailablePort.*;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.distributed.DistributedSystem;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * TODO : Add more tests for error-catch, different type of results etc
+ */
+@Category(IntegrationTest.class)
+public class HeadlessGfshIntegrationTest {
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @SuppressWarnings({"deprecation"})
+  @Test
+  public void testHeadlessGfshTest() throws ClassNotFoundException, IOException, InterruptedException {
+    int port = getRandomAvailablePort(SOCKET);
+
+    Properties properties = new Properties();
+    properties.put(NAME_NAME, this.testName.getMethodName());
+    properties.put(JMX_MANAGER_NAME, "true");
+    properties.put(JMX_MANAGER_START_NAME, "true");
+    properties.put(JMX_MANAGER_PORT_NAME, String.valueOf(port));
+    properties.put(HTTP_SERVICE_PORT_NAME, "0");
+    properties.put(MCAST_PORT_NAME, "0");
+
+    DistributedSystem ds = DistributedSystem.connect(properties);
+    GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.create(ds);
+
+    HeadlessGfsh gfsh = new HeadlessGfsh("Test", 25, this.temporaryFolder.newFolder("gfsh_files").getCanonicalPath());
+    for (int i = 0; i < 5; i++) {
+      gfsh.executeCommand("connect --jmx-manager=localhost[" + port + "]");
+      Object result = gfsh.getResult();
+      assertTrue(gfsh.isConnectedAndReady());
+      assertNotNull(result);
+      gfsh.clear();
+      gfsh.executeCommand("list members");
+      result = gfsh.getResult();
+      assertNotNull(result);
+      gfsh.executeCommand("disconnect");
+      gfsh.getResult();
+    }
+
+    long l1 = System.currentTimeMillis();
+    gfsh.executeCommand("exit");
+    long l2 = System.currentTimeMillis();
+    gfsh.getResult();
+    long l3 = System.currentTimeMillis();
+    System.out.println("L3-l2=" + (l3 - l2) + " Total time= " + (l3 - l1) / 1000);
+    gfsh.terminate();
+    cache.close();
+    ds.disconnect();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfshJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfshJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfshJUnitTest.java
deleted file mode 100644
index 86fe03e..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/HeadlessGfshJUnitTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gemstone.gemfire.management.internal.cli;
-
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.AvailablePort;
-import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.management.internal.MBeanJMXAdapter;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import javax.management.ObjectName;
-import java.io.IOException;
-import java.util.Properties;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * TODO : Add more tests for error-catch, different type of results etc
- *
- */
-@Category(IntegrationTest.class)
-public class HeadlessGfshJUnitTest {
-
-  @SuppressWarnings({"deprecation"})
-  @Test
-  public void testHeadlessGfshTest() throws ClassNotFoundException, IOException, InterruptedException {
-    GemFireCacheImpl cache = null;
-    DistributedSystem ds = null;
-    Properties pr = new Properties();
-    pr.put("name", "testHeadlessGfshTest");
-    pr.put(DistributionConfig.JMX_MANAGER_NAME, "true");
-    pr.put(DistributionConfig.JMX_MANAGER_START_NAME, "true");
-    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    pr.put(DistributionConfig.JMX_MANAGER_PORT_NAME, String.valueOf(port));
-    pr.put(DistributionConfig.HTTP_SERVICE_PORT_NAME, "0");
-    pr.put(DistributionConfig.MCAST_PORT_NAME, "0");
-
-    ds = DistributedSystem.connect(pr);
-    cache = (GemFireCacheImpl) CacheFactory.create(ds);
-
-    HeadlessGfsh gfsh = new HeadlessGfsh("Test", 25);
-    for (int i = 0; i < 5; i++) {
-      gfsh.executeCommand("connect --jmx-manager=localhost[" + port + "]");
-      Object result = gfsh.getResult();
-      assertTrue(gfsh.isConnectedAndReady());
-      assertNotNull(result);
-      gfsh.clear();
-      gfsh.executeCommand("list members");
-      result = gfsh.getResult();
-      assertNotNull(result);
-      gfsh.executeCommand("disconnect");
-      gfsh.getResult();
-    }
-
-    long l1 = System.currentTimeMillis();
-    gfsh.executeCommand("exit");
-    long l2 = System.currentTimeMillis();
-    gfsh.getResult();
-    long l3 = System.currentTimeMillis();
-    System.out.println("L3-l2=" + (l3 - l2) + " Total time= " + (l3 - l1) / 1000);
-    gfsh.terminate();
-    cache.close();
-    ds.disconnect();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
index 5c6239b..0486c5a 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
@@ -43,6 +43,11 @@ import com.gemstone.gemfire.management.internal.security.JSONAuthorization;
 import com.gemstone.gemfire.test.dunit.Host;
 import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase;
 
+import org.junit.runners.Parameterized;
+
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+
 /**
  * Base class for all the CLI/gfsh command dunit tests.
  */
@@ -60,10 +65,26 @@ public abstract class CliCommandTestBase extends JUnit4CacheTestCase {
   protected String username = "super-user";
   protected String password = "1234567";
 
-  protected int httpPort;
-  protected int jmxPort;
+  private transient int httpPort;
+  private transient int jmxPort;
+  private transient String jmxHost;
+  protected transient String gfshDir;
+
+  @Rule
+  public transient TemporaryFolder temporaryFolder = new TemporaryFolder();
 
-  protected String jmxHost;
+  @Override
+  public final void postSetUp() throws Exception {
+    setUpCliCommandTestBase();
+    postSetUpCliCommandTestBase();
+  }
+
+  private void setUpCliCommandTestBase() throws Exception {
+    this.gfshDir = this.temporaryFolder.newFolder("gfsh_files").getCanonicalPath();
+  }
+
+  protected void postSetUpCliCommandTestBase() throws Exception {
+  }
 
   @Override
   public final void preTearDownCacheTestCase() throws Exception {
@@ -145,7 +166,7 @@ public abstract class CliCommandTestBase extends JUnit4CacheTestCase {
   /**
    * Destroy all of the components created for the default setup.
    */
-    protected final void destroyDefaultSetup() {
+  protected final void destroyDefaultSetup() {
     if (this.shell != null) {
       executeCommand(shell, "exit");
       this.shell.terminate();
@@ -267,7 +288,7 @@ public abstract class CliCommandTestBase extends JUnit4CacheTestCase {
     try {
       Gfsh.SUPPORT_MUTLIPLESHELL = true;
       String shellId = getClass().getSimpleName() + "_" + getName();
-      HeadlessGfsh shell = new HeadlessGfsh(shellId, 30);
+      HeadlessGfsh shell = new HeadlessGfsh(shellId, 30, this.gfshDir);
       //Added to avoid trimming of the columns
       info("Started testable shell: " + shell);
       return shell;


Mime
View raw message