geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [12/37] incubator-geode git commit: GEODE-1255: Add test coverage for using a custom log4j2.xml with Geode
Date Fri, 06 May 2016 21:40:43 GMT
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
deleted file mode 100755
index 395a9e6..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherJUnitTest.java
+++ /dev/null
@@ -1,903 +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 java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Collections;
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-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;
-
-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.Ignore;
-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;
-
-/**
- * The ServerLauncherJUnitTest 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 ServerLauncherJUnitTest {
-
-  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/ServerLauncherLocalFileIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileIntegrationTest.java
new file mode 100755
index 0000000..5a457a7
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileIntegrationTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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 com.gemstone.gemfire.internal.process.ProcessControllerFactory;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Subclass of ServerLauncherLocalDUnitTest which forces the code to not find 
+ * the Attach API which is in the JDK tools.jar.  As a result ServerLauncher
+ * ends up using the FileProcessController implementation.
+ *
+ * @since 8.0
+ */
+@Category(IntegrationTest.class)
+public class ServerLauncherLocalFileIntegrationTest extends ServerLauncherLocalIntegrationTest {
+
+  @Before
+  public final void setUpServerLauncherLocalFileTest() throws Exception {
+    System.setProperty(ProcessControllerFactory.PROPERTY_DISABLE_ATTACH_API, "true");
+  }
+  
+  @After
+  public final void tearDownServerLauncherLocalFileTest() throws Exception {   
+  }
+  
+  @Override
+  @Test
+  public void testIsAttachAPIFound() throws Exception {
+    final ProcessControllerFactory factory = new ProcessControllerFactory();
+    assertFalse(factory.isAttachAPIFound());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileJUnitTest.java
deleted file mode 100755
index bda05c4..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalFileJUnitTest.java
+++ /dev/null
@@ -1,54 +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 com.gemstone.gemfire.internal.process.ProcessControllerFactory;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-
-/**
- * Subclass of ServerLauncherLocalDUnitTest which forces the code to not find 
- * the Attach API which is in the JDK tools.jar.  As a result ServerLauncher
- * ends up using the FileProcessController implementation.
- *
- * @since 8.0
- */
-@Category(IntegrationTest.class)
-public class ServerLauncherLocalFileJUnitTest extends ServerLauncherLocalJUnitTest {
-
-  @Before
-  public final void setUpServerLauncherLocalFileTest() throws Exception {
-    System.setProperty(ProcessControllerFactory.PROPERTY_DISABLE_ATTACH_API, "true");
-  }
-  
-  @After
-  public final void tearDownServerLauncherLocalFileTest() throws Exception {   
-  }
-  
-  @Override
-  @Test
-  public void testIsAttachAPIFound() throws Exception {
-    final ProcessControllerFactory factory = new ProcessControllerFactory();
-    assertFalse(factory.isAttachAPIFound());
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/566fce96/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java
new file mode 100755
index 0000000..911bfab
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/ServerLauncherLocalIntegrationTest.java
@@ -0,0 +1,1073 @@
+/*
+ * 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.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.lang.management.ManagementFactory;
+import java.net.BindException;
+import java.net.InetAddress;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.DataPolicy;
+import com.gemstone.gemfire.cache.Scope;
+import com.gemstone.gemfire.distributed.AbstractLauncher.Status;
+import com.gemstone.gemfire.distributed.ServerLauncher.Builder;
+import com.gemstone.gemfire.distributed.ServerLauncher.ServerState;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.AvailablePort;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.internal.GemFireVersion;
+import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.cache.AbstractCacheServer;
+import com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation;
+import com.gemstone.gemfire.internal.cache.xmlcache.CacheXmlGenerator;
+import com.gemstone.gemfire.internal.cache.xmlcache.RegionAttributesCreation;
+import com.gemstone.gemfire.internal.process.ProcessControllerFactory;
+import com.gemstone.gemfire.internal.process.ProcessType;
+import com.gemstone.gemfire.internal.process.ProcessUtils;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests for ServerLauncher as a local API in the local JVM.
+ *
+ * @see com.gemstone.gemfire.distributed.AbstractLauncher
+ * @see com.gemstone.gemfire.distributed.ServerLauncher
+ * @see com.gemstone.gemfire.distributed.ServerLauncher.Builder
+ * @see com.gemstone.gemfire.distributed.ServerLauncher.ServerState
+ * @see com.gemstone.gemfire.internal.AvailablePortHelper
+ * @since 8.0
+ */
+@Category(IntegrationTest.class)
+public class ServerLauncherLocalIntegrationTest extends AbstractServerLauncherIntegrationTestCase {
+  
+  @Before
+  public final void setUpServerLauncherLocalTest() throws Exception {
+    disconnectFromDS();
+    System.setProperty(ProcessType.TEST_PREFIX_PROPERTY, getUniqueName()+"-");
+  }
+
+  @After
+  public final void tearDownServerLauncherLocalTest() throws Exception {    
+    disconnectFromDS();
+  }
+  
+  protected Status getExpectedStopStatusForNotRunning() {
+    return Status.NOT_RESPONDING;
+  }
+
+  @Test
+  public void testBuilderSetProperties() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    this.launcher = new Builder()
+        .setDisableDefaultServer(true)
+        .setForce(true)
+        .setMemberName(getUniqueName())
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.DISABLE_AUTO_RECONNECT_NAME, "true")
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0")
+        .build();
+
+    assertNotNull(this.launcher);
+    
+    try {
+      assertEquals(Status.ONLINE, this.launcher.start().getStatus());
+      waitForServerToStart(this.launcher);
+  
+      final Cache cache = this.launcher.getCache();
+  
+      assertNotNull(cache);
+  
+      final DistributedSystem distributedSystem = cache.getDistributedSystem();
+  
+      assertNotNull(distributedSystem);
+      assertEquals("true", distributedSystem.getProperties().getProperty(DistributionConfig.DISABLE_AUTO_RECONNECT_NAME));
+      assertEquals("config", distributedSystem.getProperties().getProperty(DistributionConfig.LOG_LEVEL_NAME));
+      assertEquals("0", distributedSystem.getProperties().getProperty(DistributionConfig.MCAST_PORT_NAME));
+      assertEquals(getUniqueName(), distributedSystem.getProperties().getProperty(DistributionConfig.NAME_NAME));
+
+    } 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);
+    }
+  }
+
+  @Test
+  public void testIsAttachAPIFound() throws Exception {
+    final ProcessControllerFactory factory = new ProcessControllerFactory();
+    assertTrue(factory.isAttachAPIFound());
+  }
+  
+  @Test
+  public void testStartCreatesPidFile() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // build and start the Server locally
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    this.launcher = builder.build();
+    assertNotNull(this.launcher);
+
+    try {
+      this.launcher.start();
+      waitForServerToStart(this.launcher);
+      assertEquals(Status.ONLINE, this.launcher.status().getStatus());
+
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertTrue(ProcessUtils.isProcessAlive(pid));
+      assertEquals(getPid(), pid);
+
+      assertEquals(Status.ONLINE, this.launcher.status().getStatus());
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+      
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+
+  @Test
+  public void testStartDeletesStaleControlFiles() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // create existing control files
+    this.stopRequestFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getStopRequestFileName());
+    this.stopRequestFile.createNewFile();
+    assertTrue(this.stopRequestFile.exists());
+
+    this.statusRequestFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getStatusRequestFileName());
+    this.statusRequestFile.createNewFile();
+    assertTrue(this.statusRequestFile.exists());
+
+    this.statusFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getStatusFileName());
+    this.statusFile.createNewFile();
+    assertTrue(this.statusFile.exists());
+    
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    assertFalse(builder.getForce());
+    this.launcher = builder.build();
+    assertFalse(this.launcher.isForcing());
+    this.launcher.start();
+    
+    try {
+      waitForServerToStart(this.launcher);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+    
+    try {
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertTrue(ProcessUtils.isProcessAlive(pid));
+      assertEquals(getPid(), pid);
+      
+      // validate stale control files were deleted
+      assertFalse(this.stopRequestFile.exists());
+      assertFalse(this.statusRequestFile.exists());
+      assertFalse(this.statusFile.exists());
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+  
+  @Test
+  public void testStartOverwritesStalePidFile() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // create existing pid file
+    this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+    assertFalse("Integer.MAX_VALUE shouldn't be the same as local pid " + Integer.MAX_VALUE, Integer.MAX_VALUE == ProcessUtils.identifyPid());
+    writePid(this.pidFile, Integer.MAX_VALUE);
+
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    assertFalse(builder.getForce());
+    this.launcher = builder.build();
+    assertFalse(this.launcher.isForcing());
+    this.launcher.start();
+    
+    try {
+      waitForServerToStart(this.launcher);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+    
+    try {
+      // validate the pid file and its contents
+      assertTrue(this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertTrue(ProcessUtils.isProcessAlive(pid));
+      assertEquals(getPid(), pid);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+
+  /**
+   * Confirms fix for #47778.
+   */
+  @Test
+  public void testStartUsingDisableDefaultServerLeavesPortFree() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // build and start the server
+    assertTrue(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
+    
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+    
+    this.launcher = builder.build();
+
+    // wait for server to start
+    try {
+      // if start succeeds without throwing exception then #47778 is fixed
+      this.launcher.start();
+      waitForServerToStart(this.launcher);
+
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertTrue(ProcessUtils.isProcessAlive(pid));
+      assertEquals(getPid(), pid);
+
+      // verify server did not a port
+      assertTrue(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
+      
+      final ServerState status = this.launcher.status();
+      final String portString = status.getPort();
+      assertEquals("Port should be \"\" instead of " + portString, "", portString);
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    // stop the server
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+
+  /**
+   * Confirms fix for #47778.
+   */
+  @Test
+  public void testStartUsingDisableDefaultServerSkipsPortCheck() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // generate one free port and then use TEST_OVERRIDE_DEFAULT_PORT_PROPERTY
+    this.socket = SocketCreator.getDefaultInstance().createServerSocket(this.serverPort, 50, null, -1);
+    assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
+    
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    this.launcher = builder.build();
+
+    // wait for server to start
+    try {
+      // if start succeeds without throwing exception then #47778 is fixed
+      this.launcher.start();
+      waitForServerToStart(this.launcher);
+
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertTrue(ProcessUtils.isProcessAlive(pid));
+      assertEquals(getPid(), pid);
+
+      final ServerState status = this.launcher.status();
+      final String portString = status.getPort();
+      assertEquals("Port should be \"\" instead of " + portString, "", portString);
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+    
+    // stop the server
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  
+    // verify port is still in use
+    this.errorCollector.checkThat(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET), is(equalTo(false)));
+  }
+
+  @Test
+  @Ignore("Need to rewrite this without using dunit.Host")
+  public void testStartUsingForceOverwritesExistingPidFile() throws Throwable {
+  }/*
+    assertTrue(getUniqueName() + " is broken if PID == Integer.MAX_VALUE", ProcessUtils.identifyPid() != Integer.MAX_VALUE);
+    
+    // create existing pid file
+    this.pidFile = new File(ProcessType.SERVER.getPidFileName());
+    final int realPid = Host.getHost(0).getVM(3).invoke(() -> ProcessUtils.identifyPid());
+    assertFalse(realPid == ProcessUtils.identifyPid());
+    writePid(this.pidFile, realPid);
+
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setForce(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    assertTrue(builder.getForce());
+    this.launcher = builder.build();
+    assertTrue(this.launcher.isForcing());
+    this.launcher.start();
+
+    // collect and throw the FIRST failure
+    Throwable failure = null;
+
+    try {
+      waitForServerToStart(this.launcher);
+
+      // validate the pid file and its contents
+      assertTrue(this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertTrue(ProcessUtils.isProcessAlive(pid));
+      assertEquals(getPid(), pid);
+      
+      // validate log file was created
+      final String logFileName = getUniqueName()+".log";
+      assertTrue("Log file should exist: " + logFileName, new File(logFileName).exists());
+      
+    } catch (Throwable e) {
+      logger.error(e);
+      if (failure == null) {
+        failure = e;
+      }
+    }
+
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      logger.error(e);
+      if (failure == null) {
+        failure = e;
+      }
+    }
+    
+    if (failure != null) {
+      throw failure;
+    }
+  } // testStartUsingForceOverwritesExistingPidFile
+  */
+
+  /**
+   * Confirms part of fix for #47664
+   */
+  @Test
+  public void testStartUsingServerPortOverridesCacheXml() throws Throwable {
+    // verifies part of the fix for #47664
+    
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+    
+    // generate two free ports
+    final int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+    assertTrue(AvailablePort.isPortAvailable(freeTCPPorts[0], AvailablePort.SOCKET));
+    assertTrue(AvailablePort.isPortAvailable(freeTCPPorts[1], AvailablePort.SOCKET));
+    
+    // write out cache.xml with one port
+    final CacheCreation creation = new CacheCreation();
+    final RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
+    attrs.setScope(Scope.DISTRIBUTED_ACK);
+    attrs.setDataPolicy(DataPolicy.REPLICATE);
+    creation.createRegion(getUniqueName(), attrs);
+    creation.addCacheServer().setPort(freeTCPPorts[0]);
+    
+    File cacheXmlFile = this.temporaryFolder.newFile(getUniqueName() + ".xml");
+    final PrintWriter pw = new PrintWriter(new FileWriter(cacheXmlFile), true);
+    CacheXmlGenerator.generate(creation, pw);
+    pw.close();
+    
+    System.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, cacheXmlFile.getCanonicalPath());
+    
+    // start server
+    final Builder builder = new Builder()
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setServerPort(freeTCPPorts[1])
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    this.launcher = builder.build();
+    this.launcher.start();
+  
+    // wait for server to start up
+    try {
+      waitForServerToStart(this.launcher);
+  
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertTrue(ProcessUtils.isProcessAlive(pid));
+      assertEquals(getPid(), pid);
+
+      // verify server used --server-port instead of default or port in cache.xml
+      assertTrue(AvailablePort.isPortAvailable(freeTCPPorts[0], AvailablePort.SOCKET));
+      assertFalse(AvailablePort.isPortAvailable(freeTCPPorts[1], AvailablePort.SOCKET));
+      
+      final ServerState status = this.launcher.status();
+      final String portString = status.getPort();
+      final int port = Integer.valueOf(portString);
+      assertEquals("Port should be " + freeTCPPorts[1] + " instead of " + port, freeTCPPorts[1], port);
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+      
+    // stop the server
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      waitForFileToDelete(this.pidFile);
+      assertFalse("PID file still exists!", pidFile.exists());
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+  
+  /**
+   * Confirms part of fix for #47664
+   */
+  @Test
+  public void testStartUsingServerPortUsedInsteadOfDefaultCacheXml() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // write out cache.xml with one port
+    final CacheCreation creation = new CacheCreation();
+    final RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
+    attrs.setScope(Scope.DISTRIBUTED_ACK);
+    attrs.setDataPolicy(DataPolicy.REPLICATE);
+    creation.createRegion(getUniqueName(), attrs);
+    creation.addCacheServer();
+    
+    File cacheXmlFile = this.temporaryFolder.newFile(getUniqueName() + ".xml");
+    final PrintWriter pw = new PrintWriter(new FileWriter(cacheXmlFile), true);
+    CacheXmlGenerator.generate(creation, pw);
+    pw.close();
+    
+    System.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, cacheXmlFile.getCanonicalPath());
+      
+    // start server
+    final Builder builder = new Builder()
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setServerPort(this.serverPort)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    this.launcher = builder.build();
+    this.launcher.start();
+  
+    // wait for server to start up
+    try {
+      waitForServerToStart(this.launcher);
+  
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertTrue(ProcessUtils.isProcessAlive(pid));
+      assertEquals(getPid(), pid);
+
+      // verify server used --server-port instead of default
+      assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
+      
+      final int port = Integer.valueOf( this.launcher.status().getPort());
+      assertEquals("Port should be " + this.serverPort + " instead of " + port, this.serverPort, port);
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+      
+    // stop the server
+    try {
+      assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+
+  @Test
+  public void testStartWithDefaultPortInUseFails() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // generate one free port and then use TEST_OVERRIDE_DEFAULT_PORT_PROPERTY
+    this.socket = SocketCreator.getDefaultInstance().createServerSocket(this.serverPort, 50, null, -1);
+    assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
+    
+    // build and start the server
+    final Builder builder = new Builder()
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    this.launcher = builder.build();
+    
+    RuntimeException expected = null;
+    try {
+      this.launcher.start();
+     
+      // why did it not fail like it's supposed to?
+      final String property = System.getProperty(AbstractCacheServer.TEST_OVERRIDE_DEFAULT_PORT_PROPERTY);
+      assertNotNull(property);
+      assertEquals(this.serverPort, Integer.valueOf(property).intValue());
+      assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
+      
+      fail("Server port is " + this.launcher.getCache().getCacheServers().get(0).getPort());
+      fail("ServerLauncher start should have thrown RuntimeException caused by BindException");
+    } catch (RuntimeException e) {
+      expected = e;
+      assertNotNull(expected.getMessage());
+      // BindException text varies by platform
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+    
+    try {
+      assertNotNull(expected);
+      final Throwable cause = expected.getCause();
+      assertNotNull(cause);
+      assertTrue(cause instanceof BindException);
+      // BindException string varies by platform
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    try {
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertFalse("Pid file should not exist: " + this.pidFile, this.pidFile.exists());
+      
+      // creation of log file seems to be random -- look into why sometime
+      final String logFileName = getUniqueName()+".log";
+      assertFalse("Log file should not exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+    
+    // just in case the launcher started...
+    ServerState status = null;
+    try {
+      status = this.launcher.stop();
+    } catch (Throwable t) { 
+      // ignore
+    }
+    
+    try {
+      waitForFileToDelete(this.pidFile);
+      assertEquals(getExpectedStopStatusForNotRunning(), status.getStatus());
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+
+  @Test
+  @Ignore("Need to rewrite this without using dunit.Host")
+  public void testStartWithExistingPidFileFails() throws Throwable {
+  }/*
+    // create existing pid file
+    final int realPid = Host.getHost(0).getVM(3).invoke(() -> ProcessUtils.identifyPid());
+    assertFalse("Remote pid shouldn't be the same as local pid " + realPid, realPid == ProcessUtils.identifyPid());
+
+    this.pidFile = new File(ProcessType.SERVER.getPidFileName());
+    writePid(this.pidFile, realPid);
+    
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    assertFalse(builder.getForce());
+    this.launcher = builder.build();
+    assertFalse(this.launcher.isForcing());
+
+    // collect and throw the FIRST failure
+    Throwable failure = null;
+    RuntimeException expected = null;
+    
+    try {
+      this.launcher.start();
+      fail("ServerLauncher start should have thrown RuntimeException caused by FileAlreadyExistsException");
+    } catch (RuntimeException e) {
+      expected = e;
+      assertNotNull(expected.getMessage());
+      assertTrue(expected.getMessage().contains("A PID file already exists and a Server may be running in"));
+    } catch (Throwable e) {
+      logger.error(e);
+      if (failure == null) {
+        failure = e;
+      }
+    }
+
+    // just in case the launcher started...
+    ServerState status = null;
+    try {
+      status = this.launcher.stop();
+    } catch (Throwable t) { 
+      // ignore
+    }
+    
+    try {
+      assertNotNull(expected);
+      final Throwable cause = expected.getCause();
+      assertNotNull(cause);
+      assertTrue(cause instanceof FileAlreadyExistsException);
+      assertTrue(cause.getMessage().contains("Pid file already exists: "));
+      assertTrue(cause.getMessage().contains("vf.gf.server.pid for process " + realPid));
+    } catch (Throwable e) {
+      logger.error(e);
+      if (failure == null) {
+        failure = e;
+      }
+    }
+    
+    try {
+      delete(this.pidFile);
+      final Status theStatus = status.getStatus();
+      assertFalse(theStatus == Status.STARTING);
+      assertFalse(theStatus == Status.ONLINE);
+    } catch (Throwable e) {
+      logger.error(e);
+      if (failure == null) {
+        failure = e;
+      }
+    }
+    
+    if (failure != null) {
+      throw failure;
+    }
+  } // testStartWithExistingPidFileFails
+  */
+  
+  /**
+   * Confirms fix for #47665.
+   */
+  @Test
+  public void testStartUsingServerPortInUseFails() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // generate one free port and then use TEST_OVERRIDE_DEFAULT_PORT_PROPERTY
+    final int freeTCPPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+    this.socket = SocketCreator.getDefaultInstance().createServerSocket(freeTCPPort, 50, null, -1);
+    
+    // build and start the server
+    final Builder builder = new Builder()
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setServerPort(freeTCPPort)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    this.launcher = builder.build();
+    
+    RuntimeException expected = null;
+    try {
+      this.launcher.start();
+      fail("ServerLauncher start should have thrown RuntimeException caused by BindException");
+    } catch (RuntimeException e) {
+      expected = e;
+      assertNotNull(expected.getMessage());
+      // BindException string varies by platform
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+    
+    try {
+      assertNotNull(expected);
+      final Throwable cause = expected.getCause();
+      assertNotNull(cause);
+      assertTrue(cause instanceof BindException);
+      // BindException string varies by platform
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    try {
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertFalse("Pid file should not exist: " + this.pidFile, this.pidFile.exists());
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+    
+    // just in case the launcher started...
+    ServerState status = null;
+    try {
+      status = this.launcher.stop();
+    } catch (Throwable t) { 
+      // ignore
+    }
+    
+    try {
+      waitForFileToDelete(this.pidFile);
+      assertEquals(getExpectedStopStatusForNotRunning(), status.getStatus());
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+  
+  @Test
+  public void testStatusUsingPid() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+    
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+    
+    assertFalse(builder.getForce());
+    this.launcher = builder.build();
+    assertFalse(this.launcher.isForcing());
+    
+    ServerLauncher pidLauncher = null;
+    try {
+      this.launcher.start();
+      waitForServerToStart(this.launcher);
+      
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertEquals(ProcessUtils.identifyPid(), pid);
+  
+      pidLauncher = new Builder().setPid(pid).build();
+      assertNotNull(pidLauncher);
+      assertFalse(pidLauncher.isRunning());
+
+      final ServerState actualStatus = pidLauncher.status();
+      assertNotNull(actualStatus);
+      assertEquals(Status.ONLINE, actualStatus.getStatus());
+      assertEquals(pid, actualStatus.getPid().intValue());
+      assertTrue(actualStatus.getUptime() > 0);
+      // getWorkingDirectory returns user.dir instead of rootFolder because test is starting Server in this process (to move logFile and pidFile into temp dir)
+      assertEquals(ManagementFactory.getRuntimeMXBean().getClassPath(), actualStatus.getClasspath());
+      assertEquals(GemFireVersion.getGemFireVersion(), actualStatus.getGemFireVersion());
+      assertEquals(System.getProperty("java.version"),  actualStatus.getJavaVersion());
+      assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
+      assertEquals(getUniqueName(), actualStatus.getMemberName());
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    if (pidLauncher == null) {
+      try {
+        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+        waitForFileToDelete(this.pidFile);
+      } catch (Throwable e) {
+        this.errorCollector.addError(e);
+      }
+      
+    } else {
+      try {
+        assertEquals(Status.STOPPED, pidLauncher.stop().getStatus());
+        waitForFileToDelete(this.pidFile);
+      } catch (Throwable e) {
+        this.errorCollector.addError(e);
+      }
+    }
+  }
+  
+  @Test
+  public void testStatusUsingWorkingDirectory() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+    
+    assertFalse(builder.getForce());
+    this.launcher = builder.build();
+    assertFalse(this.launcher.isForcing());
+    
+    ServerLauncher dirLauncher = null;
+    try {
+      this.launcher.start();
+      waitForServerToStart(this.launcher);
+      
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertEquals(ProcessUtils.identifyPid(), pid);
+  
+      dirLauncher = new Builder().setWorkingDirectory(rootFolder).build();
+      assertNotNull(dirLauncher);
+      assertFalse(dirLauncher.isRunning());
+
+      final ServerState actualStatus = dirLauncher.status();
+      assertNotNull(actualStatus);
+      assertEquals(Status.ONLINE, actualStatus.getStatus());
+      assertEquals(pid, actualStatus.getPid().intValue());
+      assertTrue(actualStatus.getUptime() > 0);
+      // getWorkingDirectory returns user.dir instead of rootFolder because test is starting Server in this process (to move logFile and pidFile into temp dir)
+      assertEquals(ManagementFactory.getRuntimeMXBean().getClassPath(), actualStatus.getClasspath());
+      assertEquals(GemFireVersion.getGemFireVersion(), actualStatus.getGemFireVersion());
+      assertEquals(System.getProperty("java.version"),  actualStatus.getJavaVersion());
+      assertEquals(InetAddress.getLocalHost().getCanonicalHostName(), actualStatus.getHost());
+      assertEquals(getUniqueName(), actualStatus.getMemberName());
+      
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    if (dirLauncher == null) {
+      try {
+        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
+        waitForFileToDelete(this.pidFile);
+      } catch (Throwable e) {
+        this.errorCollector.addError(e);
+      }
+      
+    } else {
+      try {
+        assertEquals(Status.STOPPED, dirLauncher.stop().getStatus());
+        waitForFileToDelete(this.pidFile);
+      } catch (Throwable e) {
+        this.errorCollector.addError(e);
+      }
+    }
+  }
+  
+  @Test
+  public void testStopUsingPid() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    assertFalse(builder.getForce());
+    this.launcher = builder.build();
+    assertFalse(this.launcher.isForcing());
+
+    ServerLauncher pidLauncher = null;
+    
+    try {
+      this.launcher.start();
+      waitForServerToStart(this.launcher);
+  
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertEquals(ProcessUtils.identifyPid(), pid);
+
+      pidLauncher = new Builder().setPid(pid).build();
+      assertNotNull(pidLauncher);
+      assertFalse(pidLauncher.isRunning());
+      
+      // stop the server
+      final ServerState serverState = pidLauncher.stop();
+      assertNotNull(serverState);
+      assertEquals(Status.STOPPED, serverState.getStatus());
+    
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    try {
+      this.launcher.stop();
+    } catch (Throwable e) {
+      // ignore
+    }
+
+    try {
+      // verify the PID file was deleted
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+  
+  @Test
+  public void testStopUsingWorkingDirectory() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    // build and start the server
+    final Builder builder = new Builder()
+        .setDisableDefaultServer(true)
+        .setMemberName(getUniqueName())
+        .setRedirectOutput(true)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.MCAST_PORT_NAME, "0");
+
+    assertFalse(builder.getForce());
+    this.launcher = builder.build();
+    assertFalse(this.launcher.isForcing());
+
+    ServerLauncher dirLauncher = null;
+    try {
+      this.launcher.start();
+      waitForServerToStart(this.launcher);
+    
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
+      assertTrue(this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertEquals(ProcessUtils.identifyPid(), pid);
+
+      dirLauncher = new Builder().setWorkingDirectory(rootFolder).build();
+      assertNotNull(dirLauncher);
+      assertFalse(dirLauncher.isRunning());
+      
+      // stop the server
+      final ServerState serverState = dirLauncher.stop();
+      assertNotNull(serverState);
+      assertEquals(Status.STOPPED, serverState.getStatus());
+    
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    try {
+      this.launcher.stop();
+    } catch (Throwable e) {
+      // ignore
+    }
+
+    try {
+      // verify the PID file was deleted
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+  }
+}


Mime
View raw message