You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@geode.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/12/01 05:55:00 UTC

[jira] [Commented] (GEODE-3539) Add more test coverage for p2p commands

    [ https://issues.apache.org/jira/browse/GEODE-3539?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16273975#comment-16273975 ] 

ASF GitHub Bot commented on GEODE-3539:
---------------------------------------

jinmeiliao closed pull request #1108: GEODE-3539: enhance GfshCommandRule
URL: https://github.com/apache/geode/pull/1108
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 3edc944ce2..21f3f28ed7 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 @@
 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 static void beforeClass() throws Exception {
   }
 
   @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 25ac49cdbe..fa438716f0 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 @@
           .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 05b83c96ab..3ad80a91d0 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 @@
 
 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 @@
   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 void listAllMembers() throws Exception {
 
   @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 void listMembersInLocatorGroup() throws Exception {
 
   @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 void listMembersInServerGroupOne() throws Exception {
 
   @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 void listMembersInServerGroupTwo() throws Exception {
 
   @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 void listMembersInNonExistentGroup() throws Exception {
     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 4c4a5289c3..7feb2ae12e 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 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 static void setupSystem() throws Exception {
     });
 
     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 void listAllRegions() throws Exception {
   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 void listRegionsOnManager() throws Exception {
   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 48e99872a4..fb94fa7f2e 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 @@
   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 GfshCommandRule(Supplier<Integer> portSupplier, PortType portType) {
   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 File getWorkingDir() {
     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 {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add more test coverage for p2p commands
> ---------------------------------------
>
>                 Key: GEODE-3539
>                 URL: https://issues.apache.org/jira/browse/GEODE-3539
>             Project: Geode
>          Issue Type: Improvement
>          Components: gfsh
>            Reporter: Jinmei Liao
>
> Add more command tests that would eventually get rid of the legacy tests.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)