geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [geode] branch develop updated: GEODE-3539: enhance GfshCommandRule (#1108)
Date Fri, 01 Dec 2017 05:54:58 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/develop by this push:
     new c51a455  GEODE-3539: enhance GfshCommandRule (#1108)
c51a455 is described below

commit c51a455c05d3a94a880569693e8a8e14d176e380
Author: jinmeiliao <jiliao@pivotal.io>
AuthorDate: Thu Nov 30 21:54:56 2017 -0800

    GEODE-3539: enhance GfshCommandRule (#1108)
    
    * reduce the default timeout
    * add ability to configure the timeout at construction time.
---
 .../DescribeDiskStoreCommandIntegrationTest.java   |  9 +---
 .../ListDiskStoreCommandIntegrationTest.java       |  8 +--
 .../cli/commands/ListMembersCommandDUnitTest.java  | 25 ++++------
 .../internal/cli/commands/ListRegionDUnitTest.java | 57 ++++++----------------
 .../geode/test/junit/rules/GfshCommandRule.java    | 11 +++--
 5 files changed, 34 insertions(+), 76 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeDiskStoreCommandIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeDiskStoreCommandIntegrationTest.java
index 3edc944..21f3f28 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeDiskStoreCommandIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeDiskStoreCommandIntegrationTest.java
@@ -18,10 +18,8 @@ package org.apache.geode.management.internal.cli.commands;
 import java.util.Arrays;
 import java.util.List;
 
-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;
 
@@ -56,12 +54,7 @@ public class DescribeDiskStoreCommandIntegrationTest {
   }
 
   @ClassRule
-  public static GfshCommandRule gfsh = new GfshCommandRule();
-
-  @Before
-  public void setTimeout() {
-    gfsh.setTimeout(1);
-  }
+  public static GfshCommandRule gfsh = new GfshCommandRule().setTimeout(1);
 
   @Test
   public void commandFailsWithoutOptions() throws Exception {
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListDiskStoreCommandIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListDiskStoreCommandIntegrationTest.java
index 25ac49c..fa43871 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListDiskStoreCommandIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListDiskStoreCommandIntegrationTest.java
@@ -15,7 +15,6 @@
 
 package org.apache.geode.management.internal.cli.commands;
 
-import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
@@ -41,12 +40,7 @@ public class ListDiskStoreCommandIntegrationTest {
           .withName(MEMBER_NAME).withJMXManager().withAutoStart();
 
   @Rule
-  public GfshCommandRule gfsh = new GfshCommandRule();
-
-  @Before
-  public void setTimeout() {
-    gfsh.setTimeout(1);
-  }
+  public GfshCommandRule gfsh = new GfshCommandRule().setTimeout(1);
 
   @Test
   public void commandSucceedsWhenConnected() throws Exception {
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListMembersCommandDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListMembersCommandDUnitTest.java
index 05b83c9..3ad80a9 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListMembersCommandDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListMembersCommandDUnitTest.java
@@ -16,6 +16,7 @@ package org.apache.geode.management.internal.cli.commands;
 
 import static org.apache.geode.management.internal.cli.i18n.CliStrings.GROUPS;
 import static org.apache.geode.management.internal.cli.i18n.CliStrings.LIST_MEMBER;
+import static org.apache.geode.test.junit.rules.GfshCommandRule.PortType.jmxManager;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.Properties;
@@ -38,25 +39,27 @@ public class ListMembersCommandDUnitTest {
   private static MemberVM locator;
 
   @Rule
-  public GfshCommandRule gfsh = new GfshCommandRule();
+  public GfshCommandRule gfsh = new GfshCommandRule(locator::getJmxPort, jmxManager);
 
   @BeforeClass
   public static void setup() throws Exception {
-    locator = lsRule.startLocatorVM(0, propertiesForGroup("locatorGroup"));
-    lsRule.startServerVM(1, propertiesForGroup("serverGroup1"), locator.getPort());
-    lsRule.startServerVM(2, propertiesForGroup("serverGroup1"), locator.getPort());
-    lsRule.startServerVM(3, propertiesForGroup("serverGroup2"), locator.getPort());
+    Properties properties = new Properties();
+    properties.setProperty(GROUPS, "locatorGroup");
+    locator = lsRule.startLocatorVM(0, properties);
+    lsRule.startServerVM(1, "serverGroup1", locator.getPort());
+    lsRule.startServerVM(2, "serverGroup1", locator.getPort());
+    lsRule.startServerVM(3, "serverGroup2", locator.getPort());
   }
 
   @Test
   public void listMembersWithoutConnection() throws Exception {
+    gfsh.disconnect();
     gfsh.executeAndAssertThat(LIST_MEMBER).statusIsError()
         .containsOutput("Command 'list members' was found but is not currently available");
   }
 
   @Test
   public void listAllMembers() throws Exception {
-    gfsh.connectAndVerify(locator);
     gfsh.executeAndAssertThat(LIST_MEMBER).statusIsSuccess();
     String output = gfsh.getGfshOutput();
 
@@ -68,7 +71,6 @@ public class ListMembersCommandDUnitTest {
 
   @Test
   public void listMembersInLocatorGroup() throws Exception {
-    gfsh.connectAndVerify(locator);
     gfsh.executeAndAssertThat(LIST_MEMBER + " --group=locatorGroup").statusIsSuccess();
     String output = gfsh.getGfshOutput();
 
@@ -80,7 +82,6 @@ public class ListMembersCommandDUnitTest {
 
   @Test
   public void listMembersInServerGroupOne() throws Exception {
-    gfsh.connectAndVerify(locator);
     gfsh.executeAndAssertThat(LIST_MEMBER + " --group=serverGroup1").statusIsSuccess();
     String output = gfsh.getGfshOutput();
 
@@ -92,7 +93,6 @@ public class ListMembersCommandDUnitTest {
 
   @Test
   public void listMembersInServerGroupTwo() throws Exception {
-    gfsh.connectAndVerify(locator);
     gfsh.executeAndAssertThat(LIST_MEMBER + " --group=serverGroup2").statusIsSuccess();
     String output = gfsh.getGfshOutput();
 
@@ -104,7 +104,6 @@ public class ListMembersCommandDUnitTest {
 
   @Test
   public void listMembersInNonExistentGroup() throws Exception {
-    gfsh.connectAndVerify(locator);
     gfsh.executeAndAssertThat(LIST_MEMBER + " --group=foo").statusIsSuccess();
     String output = gfsh.getGfshOutput();
 
@@ -114,10 +113,4 @@ public class ListMembersCommandDUnitTest {
     assertThat(output).doesNotContain("server-3");
     assertThat(output).contains("No Members Found");
   }
-
-  private static Properties propertiesForGroup(String group) {
-    Properties properties = new Properties();
-    properties.setProperty(GROUPS, group);
-    return properties;
-  }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListRegionDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListRegionDUnitTest.java
index 4c4a528..7feb2ae 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListRegionDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListRegionDUnitTest.java
@@ -15,19 +15,10 @@
 
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_TIME_STATISTICS;
-import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.apache.geode.distributed.ConfigurationProperties.NAME;
-import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_SAMPLING_ENABLED;
 import static org.apache.geode.management.internal.cli.i18n.CliStrings.GROUP;
 import static org.apache.geode.management.internal.cli.i18n.CliStrings.LIST_REGION;
 import static org.apache.geode.management.internal.cli.i18n.CliStrings.MEMBER;
 
-import java.util.Properties;
-
 import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Test;
@@ -66,22 +57,16 @@ public class ListRegionDUnitTest {
   public static LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
   @ClassRule
-  public static GfshCommandRule gfshShellConnectionRule = new GfshCommandRule();
+  public static GfshCommandRule gfsh = new GfshCommandRule();
 
   @BeforeClass
   public static void setupSystem() throws Exception {
-    final Properties locatorProps = createProperties(LOCATOR_NAME, GROUP3_NAME);
-    MemberVM locator = lsRule.startLocatorVM(0, locatorProps);
-
-    final Properties server1Props = createProperties(SERVER1_NAME, GROUP1_NAME);
-    server1Props.setProperty(LOCATORS, "localhost[" + locator.getPort() + "]");
-    MemberVM server1 = lsRule.startServerVM(1, server1Props, locator.getPort());
-
-    final Properties server2Props = createProperties(SERVER2_NAME, GROUP2_NAME);
-    MemberVM server = lsRule.startServerVM(2, server2Props, locator.getPort());
+    MemberVM locator = lsRule.startLocatorVM(0);
+    MemberVM server1 = lsRule.startServerVM(1, GROUP1_NAME, locator.getPort());
+    MemberVM server = lsRule.startServerVM(2, GROUP2_NAME, locator.getPort());
 
     server1.invoke(() -> {
-      final Cache cache = CacheFactory.getAnyInstance();
+      final Cache cache = LocatorServerStartupRule.getCache();
       RegionFactory<String, Integer> dataRegionFactory =
           cache.createRegionFactory(RegionShortcut.PARTITION);
       dataRegionFactory.create(PR1);
@@ -89,20 +74,20 @@ public class ListRegionDUnitTest {
     });
 
     server.invoke(() -> {
-      final Cache cache = CacheFactory.getAnyInstance();
+      final Cache cache = LocatorServerStartupRule.getCache();
       RegionFactory<String, Integer> dataRegionFactory =
           cache.createRegionFactory(RegionShortcut.PARTITION);
       dataRegionFactory.create(PR1);
       createRegionsWithSubRegions();
     });
 
-    gfshShellConnectionRule.connectAndVerify(locator);
+    gfsh.connectAndVerify(locator);
   }
 
   @Test
   public void listAllRegions() throws Exception {
     String listRegions = new CommandStringBuilder(LIST_REGION).toString();
-    gfshShellConnectionRule.executeAndAssertThat(listRegions).statusIsSuccess().containsOutput(PR1,
+    gfsh.executeAndAssertThat(listRegions).statusIsSuccess().containsOutput(PR1,
         LOCALREGIONONSERVER1, REGION1, REGION2, REGION3);
   }
 
@@ -110,7 +95,7 @@ public class ListRegionDUnitTest {
   public void listRegionsOnManager() throws Exception {
     String listRegions =
         new CommandStringBuilder(LIST_REGION).addOption(MEMBER, SERVER1_NAME).toString();
-    gfshShellConnectionRule.executeAndAssertThat(listRegions).statusIsSuccess().containsOutput(PR1,
+    gfsh.executeAndAssertThat(listRegions).statusIsSuccess().containsOutput(PR1,
         LOCALREGIONONSERVER1);
   }
 
@@ -118,36 +103,24 @@ public class ListRegionDUnitTest {
   public void listRegionsOnServer() throws Exception {
     CommandStringBuilder csb = new CommandStringBuilder(LIST_REGION);
     csb.addOption(MEMBER, SERVER2_NAME);
-    gfshShellConnectionRule.executeAndAssertThat(csb.toString()).statusIsSuccess()
-        .containsOutput(PR1, REGION1, REGION2, REGION3, SUBREGION1A);
+    gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess().containsOutput(PR1, REGION1,
+        REGION2, REGION3, SUBREGION1A);
   }
 
   @Test
   public void listRegionsInGroup1() throws Exception {
     CommandStringBuilder csb = new CommandStringBuilder(LIST_REGION);
     csb.addOption(GROUP, GROUP1_NAME);
-    gfshShellConnectionRule.executeAndAssertThat(csb.toString()).statusIsSuccess()
-        .containsOutput(PR1, LOCALREGIONONSERVER1);
+    gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess().containsOutput(PR1,
+        LOCALREGIONONSERVER1);
   }
 
   @Test
   public void listRegionsInGroup2() throws Exception {
     CommandStringBuilder csb = new CommandStringBuilder(LIST_REGION);
     csb.addOption(GROUP, GROUP2_NAME);
-    gfshShellConnectionRule.executeAndAssertThat(csb.toString()).statusIsSuccess()
-        .containsOutput(PR1, REGION1, REGION2, REGION3, SUBREGION1A);
-  }
-
-
-  private static Properties createProperties(String name, String groups) {
-    Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    props.setProperty(LOG_LEVEL, "info");
-    props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
-    props.setProperty(ENABLE_TIME_STATISTICS, "true");
-    props.setProperty(NAME, name);
-    props.setProperty(GROUPS, groups);
-    return props;
+    gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess().containsOutput(PR1, REGION1,
+        REGION2, REGION3, SUBREGION1A);
   }
 
   private static void createLocalRegion(final String regionName) {
diff --git a/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshCommandRule.java
b/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshCommandRule.java
index 48e9987..fb94fa7 100644
--- a/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshCommandRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/junit/rules/GfshCommandRule.java
@@ -74,6 +74,7 @@ public class GfshCommandRule extends DescribedExternalResource {
   private Supplier<Integer> portSupplier;
   private PortType portType = PortType.jmxManager;
   private HeadlessGfsh gfsh = null;
+  private int gfshTimeout = 2;
   private boolean connected = false;
   private IgnoredException ignoredException;
   private TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -98,7 +99,7 @@ public class GfshCommandRule extends DescribedExternalResource {
   protected void before(Description description) throws Throwable {
     LogWrapper.close();
     workingDir = temporaryFolder.newFolder("gfsh_files");
-    this.gfsh = new HeadlessGfsh(getClass().getName(), 30, workingDir.getAbsolutePath());
+    this.gfsh = new HeadlessGfsh(getClass().getName(), gfshTimeout, workingDir.getAbsolutePath());
     ignoredException =
         addIgnoredException("java.rmi.NoSuchObjectException: no such object in table");
 
@@ -267,8 +268,12 @@ public class GfshCommandRule extends DescribedExternalResource {
     return workingDir;
   }
 
-  public void setTimeout(long timeoutInSeconds) {
-    gfsh.setTimeout(timeoutInSeconds);
+  public GfshCommandRule setTimeout(int timeoutInSeconds) {
+    this.gfshTimeout = timeoutInSeconds;
+    if (gfsh != null) {
+      gfsh.setTimeout(timeoutInSeconds);
+    }
+    return this;
   }
 
   public enum PortType {

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message