geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [2/2] geode git commit: Refactor test rules
Date Thu, 09 Feb 2017 15:50:17 GMT
Refactor test rules

* Refactor GfshShellConnectorRule so that it's easier to use it either as a rule or classRule
* Refactor LocatorServerStartupRule so that tests using it do not need to extend from Junit4DUnitTest and can be used as a class rule.
* properly close all the vms using the ServerStartupRule
* add NetstatDUnitTest


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

Branch: refs/heads/develop
Commit: d188118bcfad69580acde9d926f03292b2fef4a7
Parents: 857cd29
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Wed Feb 8 16:04:42 2017 -0800
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Thu Feb 9 07:49:57 2017 -0800

----------------------------------------------------------------------
 .../geode/tools/pulse/PulseDataExportTest.java  |  12 +-
 .../ConnectToLocatorSSLDUnitTest.java           |  16 +-
 .../management/internal/cli/HeadlessGfsh.java   |   8 +-
 .../internal/cli/NetstatDUnitTest.java          |  94 +++++++++++
 .../configuration/ClusterConfigBaseTest.java    |   4 +-
 .../ClusterConfigDeployJarDUnitTest.java        |  58 ++-----
 .../ClusterConfigDistributionDUnitTest.java     |  23 ++-
 .../ClusterConfigImportDUnitTest.java           |  42 ++---
 .../ClusterConfigWithSecurityDUnitTest.java     |  11 +-
 .../security/GfshCommandsPostProcessorTest.java |  36 ++---
 .../security/GfshCommandsSecurityTest.java      |  30 ++--
 .../ClusterConfigWithoutSecurityDUnitTest.java  |  33 ++--
 .../security/PeerAuthenticatorDUnitTest.java    |  19 ++-
 ...eerSecurityWithEmbeddedLocatorDUnitTest.java |  22 +--
 .../SecurityClusterConfigDUnitTest.java         |  23 ++-
 .../SecurityWithoutClusterConfigDUnitTest.java  |  37 +++--
 .../security/StartServerAuthorizationTest.java  |  52 +++----
 .../dunit/rules/GfshShellConnectionRule.java    | 121 ++++++++------
 .../apache/geode/test/dunit/rules/Locator.java  |   4 +-
 .../dunit/rules/LocatorServerStartupRule.java   |  32 ++--
 .../apache/geode/test/dunit/rules/Member.java   |   8 +-
 .../apache/geode/test/dunit/rules/Server.java   |   4 +-
 .../test/dunit/rules/ServerStarterRule.java     |   2 +-
 .../LuceneClusterConfigurationDUnitTest.java    | 156 ++++++++-----------
 24 files changed, 448 insertions(+), 399 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
index 28d50da..b547290 100644
--- a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseDataExportTest.java
@@ -16,13 +16,12 @@
 
 package org.apache.geode.tools.pulse;
 
-import static org.awaitility.Awaitility.await;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
 
 import org.apache.geode.cache.client.ClientCacheFactory;
 import org.apache.geode.cache.client.ClientRegionShortcut;
 import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
 import org.apache.geode.test.dunit.rules.Locator;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
@@ -47,7 +46,6 @@ import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.EntityUtils;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -61,14 +59,15 @@ import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
 @Category(DistributedTest.class)
-public class PulseDataExportTest extends JUnit4DistributedTestCase {
+public class PulseDataExportTest {
 
   @Rule
   public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
   private Locator locator;
   private org.apache.geode.test.dunit.rules.Server server;
-  private GfshShellConnectionRule gfshConnector;
+  @Rule
+  public GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule();
   private HttpClient httpClient;
   private CookieStore cookieStore;
 
@@ -80,8 +79,7 @@ public class PulseDataExportTest extends JUnit4DistributedTestCase {
 
     locator = lsRule.startLocatorVMWithPulse(0, new Properties());
 
-    gfshConnector = new GfshShellConnectionRule(locator);
-    gfshConnector.connect();
+    gfshConnector.connect(locator);
     assertThat(gfshConnector.isConnected()).isTrue();
 
     server = lsRule.startServerVM(1, locator.getPort());

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java
index 9d678e1..83a367e 100644
--- a/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/ConnectToLocatorSSLDUnitTest.java
@@ -38,11 +38,10 @@ import static org.apache.geode.util.test.TestUtil.getResourcePath;
 
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.security.SecurableCommunicationChannels;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
+import org.apache.geode.test.dunit.rules.Locator;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
 import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
 import org.junit.After;
 import org.junit.Before;
@@ -57,13 +56,16 @@ import java.io.OutputStream;
 import java.util.Properties;
 
 @Category(DistributedTest.class)
-public class ConnectToLocatorSSLDUnitTest extends JUnit4DistributedTestCase {
+public class ConnectToLocatorSSLDUnitTest {
 
   @Rule
   public TemporaryFolder folder = new SerializableTemporaryFolder();
   @Rule
   public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
+  @Rule
+  public GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule();
+
   private File jks = null;
   private File securityPropsFile = null;
   private Properties securityProps;
@@ -81,20 +83,16 @@ public class ConnectToLocatorSSLDUnitTest extends JUnit4DistributedTestCase {
   }
 
   private void setUpLocatorAndConnect(Properties securityProps) throws Exception {
-    lsRule.startLocatorVM(0, securityProps);
+    Locator locator = lsRule.startLocatorVM(0, securityProps);
 
     // saving the securityProps to a file
     OutputStream out = new FileOutputStream(securityPropsFile);
     securityProps.store(out, null);
 
-    GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule(
-        lsRule.getMember(0).getPort(), GfshShellConnectionRule.PortType.locator);
-
-    gfshConnector.connect(CliStrings.CONNECT__SECURITY_PROPERTIES,
+    gfshConnector.connect(locator, CliStrings.CONNECT__SECURITY_PROPERTIES,
         securityPropsFile.getCanonicalPath());
 
     assertTrue(gfshConnector.isConnected());
-    gfshConnector.close();
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
index b9a19cb..72be0c7 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/HeadlessGfsh.java
@@ -14,10 +14,10 @@
  */
 package org.apache.geode.management.internal.cli;
 
+import jline.console.ConsoleReader;
 import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.cli.shell.GfshConfig;
 import org.apache.geode.management.internal.cli.shell.jline.GfshUnsupportedTerminal;
-import jline.console.ConsoleReader;
 import org.springframework.shell.core.ExitShellRequest;
 import org.springframework.shell.event.ShellStatus.Status;
 
@@ -83,7 +83,7 @@ public class HeadlessGfsh implements ResultHandler {
     });
 
     this.shell.start();
-    this.setThreadLocalInstance();
+    this.shell.setThreadLocalInstance();
 
     try {
       shellStarted.await();
@@ -92,10 +92,6 @@ public class HeadlessGfsh implements ResultHandler {
     }
   }
 
-  public void setThreadLocalInstance() {
-    shell.setThreadLocalInstance();
-  }
-
   // TODO : Have non-blocking method also where we move executeCommand call to separate thread-pool
   public boolean executeCommand(String command) {
     boolean status = false;

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/cli/NetstatDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/NetstatDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/NetstatDUnitTest.java
new file mode 100644
index 0000000..3ee0c46
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/NetstatDUnitTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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 org.apache.geode.management.internal.cli;
+
+import org.apache.geode.internal.AvailablePortHelper;
+import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.Server;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Properties;
+
+@Category(DistributedTest.class)
+public class NetstatDUnitTest {
+  @ClassRule
+  public static LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+
+  @ClassRule
+  public static GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule();
+
+  private static int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
+
+  private static String netStatCommand = null;
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    Properties properties = new Properties();
+    // common properties
+    properties.setProperty("locators", "localhost[" + ports[0] + "]");
+    properties.setProperty("http-service-port", "0");
+
+    // start peer locator
+    properties.setProperty("start-locator", "localhost[" + ports[0] + "],peer=true,server=true");
+    properties.setProperty("jmx-manager-port", ports[1] + "");
+    lsRule.startServerVM(0, properties);
+
+    // start server with jmx Manager as well
+    properties.remove("start-locator");
+    properties.setProperty("jmx-manager-port", ports[2] + "");
+    Server server = lsRule.startServerVM(1, properties);
+
+    // start server with no jmx Manager
+    properties.setProperty("jmx-manager", "false");
+    properties.setProperty("jmx-manager-port", "0");
+    properties.setProperty("jmx-manager-start", "false");
+    lsRule.startServerVM(2, properties);
+
+    // start another server
+    lsRule.startServerVM(3, properties);
+
+    netStatCommand = "netstat --with-lsof=true --member=" + server.getName();
+  }
+
+  @Test
+  public void testConnectToLocator() throws Exception {
+    gfshConnector.connect(ports[0], GfshShellConnectionRule.PortType.locator);
+    gfshConnector.executeAndVerifyCommand(netStatCommand);
+  }
+
+  @Test
+  public void testConnectToJmxManagerOne() throws Exception {
+    gfshConnector.connect(ports[1], GfshShellConnectionRule.PortType.jmxManger);
+    gfshConnector.executeAndVerifyCommand(netStatCommand);
+  }
+
+  @Test
+  public void testConnectToJmxManagerTwo() throws Exception {
+    gfshConnector.connect(ports[2], GfshShellConnectionRule.PortType.jmxManger);
+    gfshConnector.executeAndVerifyCommand(netStatCommand);
+  }
+
+  @After
+  public void after() throws Exception {
+    gfshConnector.disconnect();
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
index cc0fff2..cecc8cf 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
@@ -18,12 +18,10 @@ package org.apache.geode.management.internal.configuration;
 
 import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
 import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
-import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.geode.internal.ClassBuilder;
 import org.apache.geode.management.internal.configuration.utils.ZipUtils;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.junit.Before;
 import org.junit.Rule;
@@ -32,7 +30,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Properties;
 
-public class ClusterConfigBaseTest extends JUnit4DistributedTestCase {
+public class ClusterConfigBaseTest {
   public String clusterConfigZipPath;
 
   public static final ConfigGroup CLUSTER = new ConfigGroup("cluster").regions("regionForCluster")

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
index 79f0128..15e6ea6 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
@@ -19,51 +19,37 @@ import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
 import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import org.apache.geode.internal.ClassBuilder;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
 import org.apache.geode.test.dunit.rules.Locator;
 import org.apache.geode.test.dunit.rules.Server;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.io.File;
-import java.io.IOException;
-
 @Category(DistributedTest.class)
 public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
-  private GfshShellConnectionRule gfshConnector;
+  @Rule
+  public GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule();
 
   private String clusterJar, group1Jar, group2Jar;
 
   @Before
   public void before() throws Exception {
     super.before();
-
     clusterJar = createJarFileWithClass("Cluster", "cluster.jar", lsRule.getTempFolder().getRoot());
     group1Jar = createJarFileWithClass("Group1", "group1.jar", lsRule.getTempFolder().getRoot());
     group2Jar = createJarFileWithClass("Group2", "group2.jar", lsRule.getTempFolder().getRoot());
   }
 
-  @After
-  public void after() throws Exception {
-    if (gfshConnector != null) {
-      gfshConnector.close();
-    }
-  }
-
   @Test
   public void testDeployToNoServer() throws Exception {
     String clusterJarPath = clusterJar;
     // set up the locator/servers
     Locator locator = lsRule.startLocatorVM(0, locatorProps);
 
-    gfshConnector = new GfshShellConnectionRule(locator);
-    gfshConnector.connect();
+    gfshConnector.connect(locator);
     assertThat(gfshConnector.isConnected()).isTrue();
 
     gfshConnector.executeAndVerifyCommand("deploy --jar=" + clusterJarPath);
@@ -89,13 +75,10 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
     // has to start a server in order to run deploy command
     lsRule.startServerVM(3, serverProps, locator.getPort());
 
-    gfshConnector =
-        new GfshShellConnectionRule(locator.getPort(), GfshShellConnectionRule.PortType.locator);
-    gfshConnector.connect();
+    gfshConnector.connect(locator);
     assertThat(gfshConnector.isConnected()).isTrue();
 
-    CommandResult result = gfshConnector.executeCommand("deploy --jar=" + clusterJar);
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand("deploy --jar=" + clusterJar);
 
     ConfigGroup cluster = new ConfigGroup("cluster").jars("cluster.jar");
     ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
@@ -119,13 +102,10 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
     serverProps.setProperty(GROUPS, "group1,group2");
     Server server3 = lsRule.startServerVM(3, serverProps, locator.getPort());
 
-    gfshConnector =
-        new GfshShellConnectionRule(locator.getPort(), GfshShellConnectionRule.PortType.locator);
-    gfshConnector.connect();
+    gfshConnector.connect(locator);
     assertThat(gfshConnector.isConnected()).isTrue();
 
-    CommandResult result = gfshConnector.executeCommand("deploy --jar=" + clusterJar);
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand("deploy --jar=" + clusterJar);
 
     ConfigGroup cluster = new ConfigGroup("cluster").jars("cluster.jar");
     ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
@@ -134,8 +114,7 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
     expectedClusterConfig.verify(server2);
     expectedClusterConfig.verify(server3);
 
-    result = gfshConnector.executeCommand("deploy --jar=" + group1Jar + " --group=group1");
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand("deploy --jar=" + group1Jar + " --group=group1");
 
     ConfigGroup group1 = new ConfigGroup("group1").jars("group1.jar");
     ClusterConfig expectedGroup1Config = new ClusterConfig(cluster, group1);
@@ -144,8 +123,7 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
     expectedGroup1Config.verify(server2);
     expectedGroup1Config.verify(server3);
 
-    result = gfshConnector.executeCommand("deploy --jar=" + group2Jar + " --group=group2");
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand("deploy --jar=" + group2Jar + " --group=group2");
 
     ConfigGroup group2 = new ConfigGroup("group2").jars("group2.jar");
     ClusterConfig expectedGroup1and2Config = new ClusterConfig(cluster, group1, group2);
@@ -176,13 +154,10 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
     ClusterConfig server2Config = new ClusterConfig(cluster, group2);
     ClusterConfig server3Config = new ClusterConfig(cluster, group1, group2);
 
-    gfshConnector =
-        new GfshShellConnectionRule(locator.getPort(), GfshShellConnectionRule.PortType.locator);
-    gfshConnector.connect();
+    gfshConnector.connect(locator);
     assertThat(gfshConnector.isConnected()).isTrue();
 
-    CommandResult result = gfshConnector.executeCommand("deploy --jar=" + clusterJar);
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand("deploy --jar=" + clusterJar);
 
     // deploy cluster.jar to the cluster
     cluster.addJar("cluster.jar");
@@ -192,8 +167,7 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
     expectedClusterConfig.verify(server3);
 
     // deploy group1.jar to both group1 and group2
-    result = gfshConnector.executeCommand("deploy --jar=" + group1Jar + " --group=group1,group2");
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand("deploy --jar=" + group1Jar + " --group=group1,group2");
 
     group1.addJar("group1.jar");
     group2.addJar("group1.jar");
@@ -203,8 +177,7 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
     server3Config.verify(server3);
 
     // test undeploy cluster
-    result = gfshConnector.executeCommand("undeploy --jar=cluster.jar");
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand("undeploy --jar=cluster.jar");
 
     cluster = cluster.removeJar("cluster.jar");
     server3Config.verify(locator);
@@ -212,8 +185,7 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
     server2Config.verify(server2);
     server3Config.verify(server3);
 
-    result = gfshConnector.executeCommand("undeploy --jar=group1.jar --group=group1");
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand("undeploy --jar=group1.jar --group=group1");
 
     group1 = group1.removeJar("group1.jar");
     /*

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
index f362d4c..e134c42 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
@@ -17,7 +17,6 @@ package org.apache.geode.management.internal.configuration;
 
 import static org.apache.commons.io.FileUtils.writeByteArrayToFile;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -29,9 +28,7 @@ import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
 import org.apache.geode.cache.query.Index;
 import org.apache.geode.internal.ClassBuilder;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
 import org.apache.geode.test.dunit.rules.Locator;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
@@ -47,7 +44,7 @@ import java.io.IOException;
 import java.util.Properties;
 
 @Category(DistributedTest.class)
-public class ClusterConfigDistributionDUnitTest extends JUnit4DistributedTestCase {
+public class ClusterConfigDistributionDUnitTest {
   private static final String REPLICATE_REGION = "ReplicateRegion1";
   private static final String PARTITION_REGION = "PartitionRegion1";
   private static final String INDEX1 = "ID1";
@@ -55,22 +52,22 @@ public class ClusterConfigDistributionDUnitTest extends JUnit4DistributedTestCas
   private static final String AsyncEventQueue1 = "Q1";
 
   private Locator locator;
-  private GfshShellConnectionRule gfshConnector;
+
+  @Rule
+  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+  @Rule
+  public GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule();
 
   @Before
   public void before() throws Exception {
     locator = lsRule.startLocatorVM(0);
-
-    gfshConnector = new GfshShellConnectionRule(locator);
-    gfshConnector.connect();
+    gfshConnector.connect(locator);
     assertThat(gfshConnector.isConnected()).isTrue();
 
     // start a server so that we can execute data commands that requires at least a server running
     lsRule.startServerVM(1, locator.getPort());
   }
 
-  @Rule
-  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
   @Test
   public void testIndexAndAsyncEventQueueCommands() throws Exception {
@@ -173,9 +170,7 @@ public class ClusterConfigDistributionDUnitTest extends JUnit4DistributedTestCas
     csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__PERSISTENT, "true");
     csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__READ__SERIALIZED, "true");
 
-    CommandResult result = gfshConnector.executeAndVerifyCommand(csb.getCommandString());
-    String message = (String) result.getResultData().getGfJsonObject().getJSONObject("content")
-        .getJSONArray("message").get(0);
-    assertEquals(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING, message);
+    String message = gfshConnector.execute(csb.getCommandString());
+    assertThat(message).contains(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING);
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
index f3c471e..b4cba61 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
@@ -31,8 +31,8 @@ import org.apache.geode.test.dunit.rules.Locator;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.Server;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -46,7 +46,8 @@ import java.util.zip.ZipFile;
 
 @Category(DistributedTest.class)
 public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
-  private GfshShellConnectionRule gfshConnector;
+  @Rule
+  public GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule();
 
   public static final ClusterConfig INITIAL_CONFIG = new ClusterConfig(new ConfigGroup("cluster"));
 
@@ -58,20 +59,10 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
     locator = lsRule.startLocatorVM(0, locatorProps);
     INITIAL_CONFIG.verify(locator);
 
-    gfshConnector = new GfshShellConnectionRule(locator);
-    gfshConnector.connect();
+    gfshConnector.connect(locator);
     assertThat(gfshConnector.isConnected()).isTrue();
   }
 
-
-  @After
-  public void after() throws Exception {
-    if (gfshConnector != null) {
-      gfshConnector.close();
-    }
-  }
-
-
   @Test
   public void testImportWithRunningServerWithData() throws Exception {
     Server server = lsRule.startServerVM(1, serverProps, locator.getPort());
@@ -106,9 +97,6 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
     // in the region
     CommandResult result = gfshConnector
         .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
-
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK)
-        .describedAs(result.getContent().toString());
     assertThat(result.getContent().toString())
         .contains("Successfully applied the imported cluster configuration on server-1");
     assertThat(result.getContent().toString())
@@ -129,9 +117,8 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
 
   @Test
   public void testImportClusterConfig() throws Exception {
-    CommandResult result = gfshConnector
-        .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand(
+        "import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
 
     // Make sure that a backup of the old clusterConfig was created
     assertThat(locator.getWorkingDir().listFiles())
@@ -163,9 +150,8 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
         "localhost[" + locator.getPort() + "],localhost[" + locator1.getPort() + "]");
     Locator locator2 = lsRule.startLocatorVM(2, locatorProps);
 
-    CommandResult result = gfshConnector
-        .executeCommand("import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector.executeAndVerifyCommand(
+        "import cluster-configuration --zip-file-name=" + clusterConfigZipPath);
 
     CONFIG_FROM_ZIP.verify(locator);
     REPLICATED_CONFIG_FROM_ZIP.verify(locator1);
@@ -188,20 +174,16 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
   public void testExportClusterConfig(String zipFilePath) throws Exception {
     Server server1 = lsRule.startServerVM(1, serverProps, locator.getPort());
 
-    CommandResult result =
-        gfshConnector.executeCommand("create region --name=myRegion --type=REPLICATE");
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+
+    gfshConnector.executeAndVerifyCommand("create region --name=myRegion --type=REPLICATE");
 
     ConfigGroup cluster = new ConfigGroup("cluster").regions("myRegion");
     ClusterConfig expectedClusterConfig = new ClusterConfig(cluster);
     expectedClusterConfig.verify(server1);
     expectedClusterConfig.verify(locator);
 
-    result =
-        gfshConnector.executeCommand("export cluster-configuration --zip-file-name=" + zipFilePath);
-    System.out.println(result.getContent());
-
-    assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+    gfshConnector
+        .executeAndVerifyCommand("export cluster-configuration --zip-file-name=" + zipFilePath);
 
     File exportedZip = new File(zipFilePath);
     assertThat(exportedZip).exists();

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java
index 388fd9d..4d67fb0 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithSecurityDUnitTest.java
@@ -27,7 +27,6 @@ import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
 import org.apache.geode.management.internal.configuration.utils.ZipUtils;
 import org.apache.geode.security.SimpleTestSecurityManager;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
 import org.apache.geode.test.dunit.rules.Locator;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
@@ -43,12 +42,15 @@ import java.io.File;
 import java.util.Properties;
 
 @Category({DistributedTest.class, SecurityTest.class})
-public class ClusterConfigWithSecurityDUnitTest extends JUnit4DistributedTestCase {
+public class ClusterConfigWithSecurityDUnitTest {
   public String clusterConfigZipPath;
 
   @Rule
   public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
+  @Rule
+  public GfshShellConnectionRule connector = new GfshShellConnectionRule();
+
   Locator locator0;
   Properties locatorProps;
 
@@ -83,9 +85,8 @@ public class ClusterConfigWithSecurityDUnitTest extends JUnit4DistributedTestCas
 
   @Test
   public void testImportNotOverwriteSecurity() throws Exception {
-    GfshShellConnectionRule connector = new GfshShellConnectionRule(locator0);
-    connector.connect(CliStrings.CONNECT__USERNAME, "cluster", CliStrings.CONNECT__PASSWORD,
-        "cluster");
+    connector.connect(locator0, CliStrings.CONNECT__USERNAME, "cluster",
+        CliStrings.CONNECT__PASSWORD, "cluster");
 
     connector.executeAndVerifyCommand(
         "import cluster-configuration --zip-file-name=" + clusterConfigZipPath);

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java
index ac3d1de..0980c18 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsPostProcessorTest.java
@@ -17,11 +17,10 @@ package org.apache.geode.management.internal.security;
 import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
 import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
 import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR;
-import static org.apache.geode.internal.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.management.internal.cli.HeadlessGfsh;
 import org.apache.geode.security.TestPostProcessor;
 import org.apache.geode.security.TestSecurityManager;
 import org.apache.geode.test.dunit.rules.ConnectionConfiguration;
@@ -29,8 +28,8 @@ import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
 import org.apache.geode.test.dunit.rules.ServerStarterRule;
 import org.apache.geode.test.junit.categories.IntegrationTest;
 import org.apache.geode.test.junit.categories.SecurityTest;
-import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -41,6 +40,7 @@ import java.util.Properties;
 public class GfshCommandsPostProcessorTest {
 
   protected static int jmxPort = AvailablePortHelper.getRandomAvailableTCPPort();
+
   static Properties properties = new Properties() {
     {
       setProperty(JMX_MANAGER_PORT, jmxPort + "");
@@ -50,38 +50,34 @@ public class GfshCommandsPostProcessorTest {
           "org/apache/geode/management/internal/security/cacheServer.json");
     }
   };
+
+
+  @ClassRule
+  public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
   @Rule
   public GfshShellConnectionRule gfshConnection =
       new GfshShellConnectionRule(jmxPort, GfshShellConnectionRule.PortType.jmxManger);
-  private HeadlessGfsh gfsh = null;
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    ServerStarterRule serverStarter = new ServerStarterRule(properties);
-    serverStarter.startServer();
     serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create("region1");
   }
 
-  @Before
-  public void before() {
-    gfsh = gfshConnection.getGfsh();
-  }
-
   @Test
   @ConnectionConfiguration(user = "data-user", password = "1234567")
   public void testGetPostProcess() throws Exception {
-    gfsh.executeCommand("put --region=region1 --key=key1 --value=value1");
-    gfsh.executeCommand("put --region=region1 --key=key2 --value=value2");
-    gfsh.executeCommand("put --region=region1 --key=key3 --value=value3");
+    gfshConnection.executeCommand("put --region=region1 --key=key1 --value=value1");
+    gfshConnection.executeCommand("put --region=region1 --key=key2 --value=value2");
+    gfshConnection.executeCommand("put --region=region1 --key=key3 --value=value3");
 
     // for get command, assert the return value is processed
-    gfsh.executeCommand("get --region=region1 --key=key1");
-    assertTrue(gfsh.outputString.contains("data-user/region1/key1/value1"), gfsh.outputString);
+    String result = gfshConnection.execute("get --region=region1 --key=key1");
+    assertThat(result).contains("data-user/region1/key1/value1");
 
     // for query command, assert the return values are processed
-    gfsh.executeCommand("query --query=\"select * from /region1\"");
-    assertTrue(gfsh.outputString.contains("data-user/null/null/value1"), gfsh.outputString);
-    assertTrue(gfsh.outputString.contains("data-user/null/null/value2"), gfsh.outputString);
-    assertTrue(gfsh.outputString.contains("data-user/null/null/value3"), gfsh.outputString);
+    result = gfshConnection.execute("query --query=\"select * from /region1\"");
+    assertThat(result).contains("data-user/null/null/value1");
+    assertThat(result).contains("data-user/null/null/value2");
+    assertThat(result).contains("data-user/null/null/value3");
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
index dbbe0db..2d32905 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/security/GfshCommandsSecurityTest.java
@@ -27,7 +27,6 @@ import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.HeadlessGfsh;
 import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.result.ErrorResultData;
 import org.apache.geode.management.internal.cli.result.ResultBuilder;
@@ -38,8 +37,8 @@ import org.apache.geode.test.dunit.rules.ServerStarterRule;
 import org.apache.geode.test.junit.categories.IntegrationTest;
 import org.apache.geode.test.junit.categories.SecurityTest;
 import org.apache.shiro.authz.permission.WildcardPermission;
-import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -77,20 +76,15 @@ public class GfshCommandsSecurityTest {
   @Rule
   public GfshShellConnectionRule gfshConnection =
       new GfshShellConnectionRule(jmxPort, GfshShellConnectionRule.PortType.jmxManger);
-  private HeadlessGfsh gfsh = null;
+
+  @ClassRule
+  public static ServerStarterRule serverStarter = new ServerStarterRule(properties);
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    ServerStarterRule serverStarter = new ServerStarterRule(properties);
-    serverStarter.startServer();
     serverStarter.cache.createRegionFactory(RegionShortcut.REPLICATE).create("region1");
   }
 
-  @Before
-  public void before() {
-    gfsh = gfshConnection.getGfsh();
-  }
-
   @Test
   @ConnectionConfiguration(user = "data-admin", password = "wrongPwd")
   public void testInvalidCredentials() throws Exception {
@@ -163,8 +157,8 @@ public class GfshCommandsSecurityTest {
     for (TestCommand permitted : allPermitted) {
       LogService.getLogger().info("Processing authorized command: " + permitted.getCommand());
 
-      gfsh.executeCommand(permitted.getCommand());
-      CommandResult result = (CommandResult) gfsh.getResult();
+
+      CommandResult result = gfshConnection.executeCommand(permitted.getCommand());
       assertNotNull(result);
 
       if (result.getResultData() instanceof ErrorResultData) {
@@ -183,9 +177,7 @@ public class GfshCommandsSecurityTest {
         continue;
 
       LogService.getLogger().info("Processing unauthorized command: " + other.getCommand());
-      gfsh.executeCommand(other.getCommand());
-
-      CommandResult result = (CommandResult) gfsh.getResult();
+      CommandResult result = (CommandResult) gfshConnection.executeCommand(other.getCommand());
       int errorCode = ((ErrorResultData) result.getResultData()).getErrorCode();
 
       // for some commands there are pre execution checks to check for user input error, will skip
@@ -207,12 +199,12 @@ public class GfshCommandsSecurityTest {
   @Test
   @ConnectionConfiguration(user = "data-user", password = "1234567")
   public void testGetPostProcess() throws Exception {
-    gfsh.executeCommand("put --region=region1 --key=key2 --value=value2");
-    gfsh.executeCommand("put --region=region1 --key=key2 --value=value2");
-    gfsh.executeCommand("put --region=region1 --key=key3 --value=value3");
+    gfshConnection.executeCommand("put --region=region1 --key=key2 --value=value2");
+    gfshConnection.executeCommand("put --region=region1 --key=key2 --value=value2");
+    gfshConnection.executeCommand("put --region=region1 --key=key3 --value=value3");
 
     // gfsh.executeCommand("get --region=region1 --key=key1");
-    gfsh.executeCommand("query --query=\"select * from /region1\"");
+    gfshConnection.executeCommand("query --query=\"select * from /region1\"");
   }
 
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
index fe37f9e..23ffa9a 100644
--- a/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/ClusterConfigWithoutSecurityDUnitTest.java
@@ -15,35 +15,36 @@
 
 package org.apache.geode.security;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.assertj.core.api.Java6Assertions.*;
-import static org.junit.Assert.*;
-
-import java.util.Properties;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR;
+import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
 
+import org.apache.geode.GemFireConfigException;
+import org.apache.geode.distributed.DistributedSystem;
+import org.apache.geode.internal.i18n.LocalizedStrings;
+import org.apache.geode.test.dunit.IgnoredException;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.ServerStarterRule;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.GemFireConfigException;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.internal.i18n.LocalizedStrings;
-import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.SecurityTest;
+import java.util.Properties;
 
 @Category({DistributedTest.class, SecurityTest.class})
 
-public class ClusterConfigWithoutSecurityDUnitTest extends JUnit4DistributedTestCase {
+public class ClusterConfigWithoutSecurityDUnitTest {
 
   @Rule
   public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
+  private ServerStarterRule serverStarter = null;
+
   @Before
   public void before() throws Exception {
     IgnoredException
@@ -56,6 +57,8 @@ public class ClusterConfigWithoutSecurityDUnitTest extends JUnit4DistributedTest
   @After
   public void after() {
     IgnoredException.removeAllExpectedExceptions();
+    if (serverStarter != null)
+      serverStarter.after();
   }
 
   // when locator is not secured, a secured server should be allowed to start with its own security
@@ -70,7 +73,7 @@ public class ClusterConfigWithoutSecurityDUnitTest extends JUnit4DistributedTest
     props.setProperty("use-cluster-configuration", "false");
 
     // initial security properties should only contain initial set of values
-    ServerStarterRule serverStarter = new ServerStarterRule(props);
+    serverStarter = new ServerStarterRule(props);
     serverStarter.startServer(lsRule.getMember(0).getPort());
     DistributedSystem ds = serverStarter.cache.getDistributedSystem();
 
@@ -91,7 +94,7 @@ public class ClusterConfigWithoutSecurityDUnitTest extends JUnit4DistributedTest
     props.setProperty("security-manager", "mySecurityManager");
     props.setProperty("use-cluster-configuration", "true");
 
-    ServerStarterRule serverStarter = new ServerStarterRule(props);
+    serverStarter = new ServerStarterRule(props);
 
     assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort()))
         .isInstanceOf(GemFireConfigException.class)

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
index a7752ae..52afab4 100644
--- a/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/PeerAuthenticatorDUnitTest.java
@@ -15,28 +15,25 @@
 
 package org.apache.geode.security;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_PEER_AUTHENTICATOR;
 import static org.apache.geode.test.dunit.Host.getHost;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import java.util.Properties;
-
+import org.apache.geode.security.templates.DummyAuthenticator;
+import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
-import org.apache.geode.test.dunit.rules.Member;
 import org.apache.geode.test.dunit.rules.ServerStarterRule;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.security.templates.DummyAuthenticator;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.SecurityTest;
+import java.util.Properties;
 
 @Category({DistributedTest.class, SecurityTest.class})
-public class PeerAuthenticatorDUnitTest extends JUnit4DistributedTestCase {
+public class PeerAuthenticatorDUnitTest {
   @Rule
   public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
@@ -64,8 +61,10 @@ public class PeerAuthenticatorDUnitTest extends JUnit4DistributedTestCase {
 
     server2.invoke(() -> {
       ServerStarterRule serverStarter = new ServerStarterRule(server2Props);
+      LocatorServerStartupRule.serverStarter = serverStarter;
       assertThatThrownBy(() -> serverStarter.startServer(locatorPort))
           .isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid user name");
+
     });
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
index 66c5be6..e87a285 100644
--- a/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/PeerSecurityWithEmbeddedLocatorDUnitTest.java
@@ -15,28 +15,26 @@
 
 package org.apache.geode.security;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_PEER_AUTHENTICATOR;
 import static org.apache.geode.test.dunit.Host.getHost;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import java.util.Properties;
-
-import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
 import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.security.templates.DummyAuthenticator;
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.ServerStarterRule;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.SecurityTest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Properties;
 
 @Category({DistributedTest.class, SecurityTest.class})
-public class PeerSecurityWithEmbeddedLocatorDUnitTest extends JUnit4DistributedTestCase {
+public class PeerSecurityWithEmbeddedLocatorDUnitTest {
 
   @Rule
   public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
@@ -64,6 +62,7 @@ public class PeerSecurityWithEmbeddedLocatorDUnitTest extends JUnit4DistributedT
     VM server2 = getHost(0).getVM(2);
     server2.invoke(() -> {
       ServerStarterRule serverStarter = new ServerStarterRule(server2Props);
+      LocatorServerStartupRule.serverStarter = serverStarter;
       assertThatThrownBy(() -> serverStarter.startServer(locatorPort))
           .isInstanceOf(GemFireSecurityException.class)
           .hasMessageContaining("Security check failed. Authentication error");
@@ -94,6 +93,7 @@ public class PeerSecurityWithEmbeddedLocatorDUnitTest extends JUnit4DistributedT
     VM server2 = getHost(0).getVM(2);
     server2.invoke(() -> {
       ServerStarterRule serverStarter = new ServerStarterRule(server2Props);
+      LocatorServerStartupRule.serverStarter = serverStarter;
       assertThatThrownBy(() -> serverStarter.startServer(locatorPort))
           .isInstanceOf(GemFireSecurityException.class).hasMessageContaining("Invalid user name");
     });

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
index ca209a7..fcda2a3 100644
--- a/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/SecurityClusterConfigDUnitTest.java
@@ -28,14 +28,13 @@ import org.apache.geode.GemFireConfigException;
 import org.apache.geode.distributed.DistributedSystem;
 import org.apache.geode.internal.i18n.LocalizedStrings;
 import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.ServerStarterRule;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.FlakyTest;
 import org.apache.geode.test.junit.categories.SecurityTest;
+import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -43,11 +42,13 @@ import org.junit.experimental.categories.Category;
 import java.util.Properties;
 
 @Category({DistributedTest.class, SecurityTest.class})
-public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase {
+public class SecurityClusterConfigDUnitTest {
 
   @Rule
   public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
+  private ServerStarterRule serverStarter = null;
+
   @Before
   public void before() throws Exception {
     IgnoredException
@@ -63,6 +64,12 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase {
     lsRule.startLocatorVM(0, props);
   }
 
+  @After
+  public void after() {
+    if (serverStarter != null)
+      serverStarter.after();
+  }
+
   @Category(FlakyTest.class) // GEODE-1977
   @Test
   public void testStartServerWithClusterConfig() throws Exception {
@@ -73,7 +80,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase {
     props.setProperty("use-cluster-configuration", "true");
 
     // initial security properties should only contain initial set of values
-    ServerStarterRule serverStarter = new ServerStarterRule(props);
+    serverStarter = new ServerStarterRule(props);
     serverStarter.startServer(lsRule.getMember(0).getPort());
     DistributedSystem ds = serverStarter.cache.getDistributedSystem();
 
@@ -95,7 +102,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase {
     props.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName());
 
     // initial security properties should only contain initial set of values
-    ServerStarterRule serverStarter = new ServerStarterRule(props);
+    serverStarter = new ServerStarterRule(props);
     serverStarter.startServer(lsRule.getMember(0).getPort());
     DistributedSystem ds = serverStarter.cache.getDistributedSystem();
 
@@ -117,7 +124,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase {
     props.setProperty("use-cluster-configuration", "true");
 
     // initial security properties should only contain initial set of values
-    ServerStarterRule serverStarter = new ServerStarterRule(props);
+    serverStarter = new ServerStarterRule(props);
 
     assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort()))
         .isInstanceOf(GemFireConfigException.class)
@@ -136,7 +143,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase {
     props.setProperty("use-cluster-configuration", "true");
 
     // initial security properties should only contain initial set of values
-    ServerStarterRule serverStarter = new ServerStarterRule(props);
+    serverStarter = new ServerStarterRule(props);
 
     assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort()))
         .isInstanceOf(GemFireConfigException.class)
@@ -155,7 +162,7 @@ public class SecurityClusterConfigDUnitTest extends JUnit4DistributedTestCase {
     props.setProperty("security-manager", "mySecurityManager");
     props.setProperty("use-cluster-configuration", "false");
 
-    ServerStarterRule serverStarter = new ServerStarterRule(props);
+    serverStarter = new ServerStarterRule(props);
 
     assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort()))
         .isInstanceOf(GemFireConfigException.class)

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java b/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
index 72654cb..3add1ab 100644
--- a/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/SecurityWithoutClusterConfigDUnitTest.java
@@ -15,33 +15,36 @@
 
 package org.apache.geode.security;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.util.Properties;
-
-import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_POST_PROCESSOR;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 import org.apache.geode.distributed.DistributedSystem;
 import org.apache.geode.internal.i18n.LocalizedStrings;
 import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.ServerStarterRule;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.SecurityTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Properties;
 
 @Category({DistributedTest.class, SecurityTest.class})
 
-public class SecurityWithoutClusterConfigDUnitTest extends JUnit4DistributedTestCase {
+public class SecurityWithoutClusterConfigDUnitTest {
 
   @Rule
   public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
+  private ServerStarterRule serverStarter = null;
+
   @Before
   public void before() throws Exception {
     IgnoredException
@@ -55,6 +58,12 @@ public class SecurityWithoutClusterConfigDUnitTest extends JUnit4DistributedTest
     lsRule.startLocatorVM(0, props);
   }
 
+  @After
+  public void after() {
+    if (serverStarter != null)
+      serverStarter.after();
+  }
+
   @Test
   // if a secured locator is started without cluster config service, the server is free to use any
   // security manager
@@ -69,7 +78,7 @@ public class SecurityWithoutClusterConfigDUnitTest extends JUnit4DistributedTest
     props.setProperty("use-cluster-configuration", "true");
 
     // initial security properties should only contain initial set of values
-    ServerStarterRule serverStarter = new ServerStarterRule(props);
+    serverStarter = new ServerStarterRule(props);
     serverStarter.startServer(lsRule.getMember(0).getPort());
     DistributedSystem ds = serverStarter.cache.getDistributedSystem();
     assertEquals(3, ds.getSecurityProperties().size());

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java b/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
index 24d0db5..8a79702 100644
--- a/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/security/StartServerAuthorizationTest.java
@@ -16,34 +16,40 @@
 package org.apache.geode.security;
 
 import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
-import static org.apache.geode.test.dunit.Host.getHost;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.Locator;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.ServerStarterRule;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.SecurityTest;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import java.util.Properties;
 
 @Category({DistributedTest.class, SecurityTest.class})
-public class StartServerAuthorizationTest extends JUnit4DistributedTestCase {
+public class StartServerAuthorizationTest {
 
-  @Rule
-  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+  @ClassRule
+  public static LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+  private static Locator locator = null;
+  private ServerStarterRule serverStarter = null;
 
-  @Before
-  public void before() throws Exception {
+  @BeforeClass
+  public static void beforeClass() throws Exception {
     Properties props = new Properties();
     props.setProperty(SECURITY_MANAGER, SimpleTestSecurityManager.class.getName());
-    lsRule.startLocatorVM(0, props);
+    locator = lsRule.startLocatorVM(0, props);
+  }
+
+  @After
+  public void after() throws Exception {
+    if (serverStarter != null)
+      serverStarter.after();
   }
 
   @Test
@@ -53,13 +59,10 @@ public class StartServerAuthorizationTest extends JUnit4DistributedTestCase {
     props.setProperty("security-username", "user");
     props.setProperty("security-password", "wrongPswd");
 
-    VM server = getHost(0).getVM(1);
-    server.invoke(() -> {
-      ServerStarterRule serverStarter = new ServerStarterRule(props);
-      assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort()))
-          .isInstanceOf(GemFireSecurityException.class).hasMessageContaining(
-              "Security check failed. Authentication error. Please check your credentials");
-    });
+    serverStarter = new ServerStarterRule(props);
+    assertThatThrownBy(() -> serverStarter.startServer(locator.getPort()))
+        .isInstanceOf(GemFireSecurityException.class).hasMessageContaining(
+            "Security check failed. Authentication error. Please check your credentials");
   }
 
   @Test
@@ -70,13 +73,10 @@ public class StartServerAuthorizationTest extends JUnit4DistributedTestCase {
     props.setProperty("security-username", "user");
     props.setProperty("security-password", "user");
 
-    VM server = getHost(0).getVM(1);
-    server.invoke(() -> {
-      ServerStarterRule serverStarter = new ServerStarterRule(props);
-      assertThatThrownBy(() -> serverStarter.startServer(lsRule.getMember(0).getPort()))
-          .isInstanceOf(GemFireSecurityException.class)
-          .hasMessageContaining("user not authorized for CLUSTER:MANAGE");
-    });
+    serverStarter = new ServerStarterRule(props);
+    assertThatThrownBy(() -> serverStarter.startServer(locator.getPort()))
+        .isInstanceOf(GemFireSecurityException.class)
+        .hasMessageContaining("user not authorized for CLUSTER:MANAGE");
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
index 49c1414..0ac459c 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
@@ -16,7 +16,6 @@ package org.apache.geode.test.dunit.rules;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import org.awaitility.Awaitility;
 import org.apache.geode.management.cli.Result;
 import org.apache.geode.management.internal.cli.CliUtil;
 import org.apache.geode.management.internal.cli.HeadlessGfsh;
@@ -26,55 +25,74 @@ import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.junit.rules.DescribedExternalResource;
 import org.junit.runner.Description;
 
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-
 /**
  * Class which eases the connection to the jmxManager {@link ConnectionConfiguration} it allows for
  * the creation of per-test connections with different user/password combinations, or no username
  * and password
+ *
+ * you can use this as Rule
+ * 
+ * @Rule GfshShellConnectionRule rule = new GfshSheelConnectionRule(); then after you connect to a
+ *       locator, you don't have to call disconnect() or close() at all, since the rule's after
+ *       takes care of it for you.
+ *
+ *       Or as a ClassRule
+ * @ClassRule GfshShellConnectionRule rule = new GfshSheelConnectionRule(); When using as a
+ *            ClassRule, if you call connect in a test, you will need to call disconnect after the
+ *            test as well. See NetstatDUnitTest for example.
+ *
  */
 public class GfshShellConnectionRule extends DescribedExternalResource {
 
-  private int port = 0;
-  private PortType portType = null;
-  private HeadlessGfsh gfsh;
-  private boolean connected;
+  private int port = -1;
+  private PortType portType = PortType.jmxManger;
+  private HeadlessGfsh gfsh = null;
+  private boolean connected = false;
 
-  public GfshShellConnectionRule(Locator locator) {
-    this(locator.getPort(), PortType.locator);
-  }
+  public GfshShellConnectionRule() {}
 
   public GfshShellConnectionRule(int port, PortType portType) {
     this.portType = portType;
     this.port = port;
-    try {
-      this.gfsh = new HeadlessGfsh(getClass().getName(), 30, "gfsh_files");
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-    this.connected = false;
   }
 
+  @Override
   protected void before(Description description) throws Throwable {
+    this.gfsh = new HeadlessGfsh(getClass().getName(), 30, "gfsh_files");
+    // do not connect if no port initialized
+    if (port < 0) {
+      return;
+    }
+
     ConnectionConfiguration config = description.getAnnotation(ConnectionConfiguration.class);
-    if (config != null) {
-      connect(CliStrings.CONNECT__USERNAME, config.user(), CliStrings.CONNECT__PASSWORD,
-          config.password());
-    } else {
-      connect();
+    if (config == null) {
+      connect(port, portType);
+      return;
     }
+
+    connect(port, portType, CliStrings.CONNECT__USERNAME, config.user(),
+        CliStrings.CONNECT__PASSWORD, config.password());
+
+  }
+
+  public void connect(Locator locator, String... options) throws Exception {
+    connect(locator.getPort(), PortType.locator, options);
   }
 
-  public void connect(String... options) throws Exception {
+  public void connectAndVerify(Locator locator, String... options) throws Exception {
+    connect(locator.getPort(), PortType.locator, options);
+    assertThat(this.connected).isTrue();
+  }
+
+  public void connect(int port, PortType type, String... options) throws Exception {
     CliUtil.isGfshVM = true;
     final CommandStringBuilder connectCommand = new CommandStringBuilder(CliStrings.CONNECT);
     String endpoint;
-    if (portType == PortType.locator) {
+    if (type == PortType.locator) {
       // port is the locator port
       endpoint = "localhost[" + port + "]";
       connectCommand.addOption(CliStrings.CONNECT__LOCATOR, endpoint);
-    } else if (portType == PortType.http) {
+    } else if (type == PortType.http) {
       endpoint = "http://localhost:" + port + "/gemfire/v1";
       connectCommand.addOption(CliStrings.CONNECT__USE_HTTP, Boolean.TRUE.toString());
       connectCommand.addOption(CliStrings.CONNECT__URL, endpoint);
@@ -93,34 +111,37 @@ public class GfshShellConnectionRule extends DescribedExternalResource {
     // when we connect too soon, we would get "Failed to retrieve RMIServer stub:
     // javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no
     // such object in table]" Exception.
-    // Tried to wait on jmx connector server being ready, but it doesn't work.
-    AtomicReference<CommandResult> result = new AtomicReference<>();
-    Awaitility.await().atMost(2, TimeUnit.MINUTES).pollDelay(2, TimeUnit.SECONDS).until(() -> {
-      gfsh.executeCommand(connectCommand.toString());
-      result.set((CommandResult) gfsh.getResult());
-      System.out.println("connect result: " + result.get().getContent().toString());
-      return !gfsh.outputString.contains("no such object in table");
-    });
-
-    connected = (result.get().getStatus() == Result.Status.OK);
+    // can not use Awaitility here because it starts another thead, but the Gfsh instance is in a
+    // threadLocal variable, See Gfsh.getExistingInstance()
+    CommandResult result = null;
+    for (int i = 0; i < 50; i++) {
+      result = executeCommand(connectCommand.toString());
+      if (!gfsh.outputString.contains("no such object in table")) {
+        break;
+      }
+      Thread.currentThread().sleep(2000);
+    }
+    connected = (result.getStatus() == Result.Status.OK);
   }
 
-
-  /**
-   * Override to tear down your specific external resource.
-   */
+  @Override
   protected void after(Description description) throws Throwable {
+    if (connected) {
+      disconnect();
+    }
     close();
   }
 
+  public void disconnect() throws Exception {
+    gfsh.clear();
+    executeCommand("disconnect");
+    connected = false;
+  }
+
   public void close() throws Exception {
-    if (gfsh != null) {
-      gfsh.clear();
-      gfsh.executeCommand("disconnect");
-      gfsh.executeCommand("exit");
-      gfsh.terminate();
-      gfsh = null;
-    }
+    gfsh.executeCommand("exit");
+    gfsh.terminate();
+    gfsh = null;
     CliUtil.isGfshVM = false;
   }
 
@@ -131,10 +152,11 @@ public class GfshShellConnectionRule extends DescribedExternalResource {
   public CommandResult executeCommand(String command) throws Exception {
     gfsh.executeCommand(command);
     CommandResult result = (CommandResult) gfsh.getResult();
-    System.out.println("command result: " + result.getContent());
+    System.out.println("Command Result: \n" + gfsh.outputString);
     return result;
   }
 
+
   public CommandResult executeAndVerifyCommand(String command) throws Exception {
     CommandResult result = executeCommand(command);
     assertThat(result.getStatus()).describedAs(result.getContent().toString())
@@ -142,6 +164,11 @@ public class GfshShellConnectionRule extends DescribedExternalResource {
     return result;
   }
 
+  public String execute(String command) throws Exception {
+    executeCommand(command);
+    return gfsh.outputString;
+  }
+
   public boolean isConnected() {
     return connected;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java
index 0350ffd..fe26e83 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java
@@ -22,7 +22,7 @@ import java.io.File;
 
 public class Locator extends Member {
 
-  public Locator(VM vm, int port, File workingDir) {
-    super(vm, port, workingDir);
+  public Locator(VM vm, int port, File workingDir, String name) {
+    super(vm, port, workingDir, name);
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
index ac9221c..6c1b496 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
@@ -21,16 +21,14 @@ import static org.apache.geode.test.dunit.Host.getHost;
 
 import org.apache.geode.test.dunit.Invoke;
 import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.standalone.DUnitLauncher;
 import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.rules.ExternalResource;
 import org.junit.rules.TemporaryFolder;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
-import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
@@ -60,19 +58,24 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
   private TemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
   private List<Member> members;
 
-  @Before
-  public void before() throws Throwable {
+  public LocatorServerStartupRule() {
+    DUnitLauncher.launchIfNeeded();
+  }
+
+  @Override
+  protected void before() throws Throwable {
     restoreSystemProperties.before();
     temporaryFolder.create();
-    Invoke.invokeInEveryVM("Stop each VM", this::stopServerOrLocatorInThisVM);
+    Invoke.invokeInEveryVM("Stop each VM", this::cleanupVm);
     members = new ArrayList<>(4);
   }
 
-  @After
-  public void after() {
+  @Override
+  protected void after() {
+    DUnitLauncher.closeAndCheckForSuspects();
+    Invoke.invokeInEveryVM("Stop each VM", this::cleanupVm);
     restoreSystemProperties.after();
     temporaryFolder.delete();
-    Invoke.invokeInEveryVM("Stop each VM", this::stopServerOrLocatorInThisVM);
   }
 
   /**
@@ -93,7 +96,7 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
       locatorStarter.startLocator();
       return locatorStarter.locator.getPort();
     });
-    Locator locator = new Locator(locatorVM, locatorPort, workingDir);
+    Locator locator = new Locator(locatorVM, locatorPort, workingDir, name);
     members.add(index, locator);
     return locator;
   }
@@ -112,7 +115,6 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
     System.out.println("Current dir is " + new File(".").getCanonicalPath());
     System.out.println("Setting gemfire.home to " + geodeInstallDir);
 
-
     VM locatorVM = getHost(0).getVM(index);
     int locatorPort = locatorVM.invoke(() -> {
       System.setProperty("user.dir", workingDir.getCanonicalPath());
@@ -121,7 +123,7 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
       locatorStarter.startLocator();
       return locatorStarter.locator.getPort();
     });
-    Locator locator = new Locator(locatorVM, locatorPort, workingDir);
+    Locator locator = new Locator(locatorVM, locatorPort, workingDir, name);
     members.add(index, locator);
     return locator;
   }
@@ -160,7 +162,7 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
       serverStarter.startServer(locatorPort);
       return serverStarter.server.getPort();
     });
-    Server server = new Server(serverVM, port, workingDir);
+    Server server = new Server(serverVM, port, workingDir, name);
     members.add(index, server);
     return server;
   }
@@ -176,12 +178,14 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial
     return temporaryFolder;
   }
 
-  private void stopServerOrLocatorInThisVM() {
+  private void cleanupVm() {
     if (serverStarter != null) {
       serverStarter.after();
+      serverStarter = null;
     }
     if (locatorStarter != null) {
       locatorStarter.after();
+      locatorStarter = null;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java
index 129fe68..7cc1eea 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Member.java
@@ -29,11 +29,13 @@ public abstract class Member implements Serializable {
   private VM vm;
   private int port;
   private File workingDir;
+  private String name;
 
-  public Member(VM vm, int port, File workingDir) {
+  public Member(VM vm, int port, File workingDir, String name) {
     this.vm = vm;
     this.port = port;
     this.workingDir = workingDir;
+    this.name = name;
   }
 
   /**
@@ -53,6 +55,10 @@ public abstract class Member implements Serializable {
     return workingDir;
   }
 
+  public String getName() {
+    return name;
+  }
+
   /**
    * Invokes {@code runnable.run()} in the {@code VM} of this member.
    */

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java
index bc4c5d6..4aa2c69 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/Server.java
@@ -21,7 +21,7 @@ import org.apache.geode.test.dunit.VM;
 import java.io.File;
 
 public class Server extends Member {
-  public Server(VM vm, int port, File workingDir) {
-    super(vm, port, workingDir);
+  public Server(VM vm, int port, File workingDir, String name) {
+    super(vm, port, workingDir, name);
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d188118b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java
index 60013ca..f93498f 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ServerStarterRule.java
@@ -106,7 +106,7 @@ public class ServerStarterRule extends ExternalResource implements Serializable
 
   @Override
   public void after() {
-    // make sure this cache is the once currently open. A server cache can be recreated due to
+    // make sure this cache is the one currently open. A server cache can be recreated due to
     // importing a new set of cluster configuration.
     cache = GemFireCacheImpl.getInstance();
     if (cache != null) {


Mime
View raw message