You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2017/10/06 21:18:53 UTC

[geode] branch develop updated (3dd3244 -> d1ef591)

This is an automated email from the ASF dual-hosted git repository.

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


    from 3dd3244  GEODE-1998: fix the GEODE ticket number in comment
     new 7e507da  GEODE-3746: Refactor FunctionCommandsDUnitTest to use rules
     new d1ef591  GEODE-3746: FunctionCommandsDUnitTest uses http as transport

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../cli/commands/FunctionCommandsDUnitTest.java    | 746 ++++-----------------
 .../cli/commands/CommandOverHttpDUnitTest.java     |   3 +-
 ...java => FunctionCommandsOverHttpDUnitTest.java} |  11 +-
 3 files changed, 152 insertions(+), 608 deletions(-)
 copy geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/{IndexCommandOverHttpTest.java => FunctionCommandsOverHttpDUnitTest.java} (83%)

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

[geode] 01/02: GEODE-3746: Refactor FunctionCommandsDUnitTest to use rules

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7e507da7e8006e00d2c76e15051c464cc858ff55
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Thu Oct 5 12:59:39 2017 -0700

    GEODE-3746: Refactor FunctionCommandsDUnitTest to use rules
---
 .../cli/commands/FunctionCommandsDUnitTest.java    | 744 ++++-----------------
 1 file changed, 143 insertions(+), 601 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTest.java
index 15ce1ee..9450d10 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTest.java
@@ -12,23 +12,11 @@
  * or implied. See the License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
-import static org.apache.geode.distributed.ConfigurationProperties.NAME;
-import static org.apache.geode.test.dunit.Assert.assertEquals;
-import static org.apache.geode.test.dunit.Assert.assertFalse;
-import static org.apache.geode.test.dunit.Assert.assertNotNull;
-import static org.apache.geode.test.dunit.Assert.assertTrue;
-import static org.apache.geode.test.dunit.Assert.fail;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-
-import java.util.List;
-import java.util.Properties;
+package org.apache.geode.management.internal.cli.commands;
 
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.Region;
@@ -37,649 +25,203 @@ import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.cache.execute.Function;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.internal.cache.functions.TestFunction;
-import org.apache.geode.management.DistributedRegionMXBean;
+import org.apache.geode.management.DistributedSystemMXBean;
 import org.apache.geode.management.ManagementService;
 import org.apache.geode.management.cli.Result;
-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.result.TabularResultData;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.SerializableRunnable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
+import org.apache.geode.test.junit.rules.GfshShellConnectionRule;
+import org.assertj.core.util.Strings;
+import org.json.JSONArray;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
-/**
- * Dunit class for testing gemfire function commands : execute function, destroy function, list
- * function
- */
-@Category({DistributedTest.class, FlakyTest.class}) // GEODE-1563 GEODE-3530
-@SuppressWarnings("serial")
-public class FunctionCommandsDUnitTest extends CliCommandTestBase {
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+@Category(DistributedTest.class)
+public class FunctionCommandsDUnitTest {
+  private MemberVM server1;
+  private MemberVM server2;
 
-  private static final String REGION_NAME = "FunctionCommandsReplicatedRegion";
   private static final String REGION_ONE = "RegionOne";
   private static final String REGION_TWO = "RegionTwo";
 
-  void setupWith2Regions() {
-    final VM vm1 = Host.getHost(0).getVM(1);
-    final VM vm2 = Host.getHost(0).getVM(2);
-    setUpJmxManagerOnVm0ThenConnect(null);
-
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-        // no need to close cache as it will be closed as part of teardown2
-        Cache cache = getCache();
-
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            cache.createRegionFactory(RegionShortcut.PARTITION);
-        Region region = dataRegionFactory.create("RegionOne");
-        for (int i = 0; i < 10; i++) {
-          region.put("key" + (i + 200), "value" + (i + 200));
-        }
-        region = dataRegionFactory.create("RegionTwo");
-        for (int i = 0; i < 1000; i++) {
-          region.put("key" + (i + 200), "value" + (i + 200));
-        }
-      }
-    });
+  @Rule
+  public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
 
+  @Rule
+  public GfshShellConnectionRule gfsh = new GfshShellConnectionRule();
 
-    vm2.invoke(new SerializableRunnable() {
-      public void run() {
-        final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-        // no need to close cache as it will be closed as part of teardown2
-        Cache cache = getCache();
-
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            cache.createRegionFactory(RegionShortcut.PARTITION);
-        Region region = dataRegionFactory.create("RegionOne");
-        for (int i = 0; i < 10000; i++) {
-          region.put("key" + (i + 400), "value" + (i + 400));
-        }
-        region = dataRegionFactory.create("Regiontwo");
-        for (int i = 0; i < 10; i++) {
-          region.put("key" + (i + 200), "value" + (i + 200));
-        }
-      }
-    });
-  }
+  @Before
+  public void before() throws Exception {
+    MemberVM locator = lsRule.startLocatorVM(0);
 
-  @Test
-  public void testExecuteFunctionWithNoRegionOnManager() throws Exception {
-    setupWith2Regions();
-    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    FunctionService.registerFunction(function);
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-      }
-    });
-    Thread.sleep(2500);
-    String command = "execute function --id=" + function.getId() + " --region=" + "/" + "RegionOne";
-    getLogWriter().info("testExecuteFunctionWithNoRegionOnManager command : " + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      String strCmdResult = commandResultToString(cmdResult);
-      getLogWriter()
-          .info("testExecuteFunctionWithNoRegionOnManager stringResult : " + strCmdResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      assertTrue(strCmdResult.contains("Execution summary"));
-    } else {
-      fail("testExecuteFunctionWithNoRegionOnManager failed as did not get CommandResult");
-    }
+    Properties props = new Properties();
+    props.setProperty("groups", "group-1");
+    server1 = lsRule.startServerVM(1, props, locator.getPort());
 
-  }
+    server2 = lsRule.startServerVM(2, locator.getPort());
 
-  public String getMemberId() {
-    Cache cache = getCache();
-    return cache.getDistributedSystem().getDistributedMember().getId();
-  }
+    server1.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.serverStarter.getCache();
 
-  @Test
-  public void testExecuteFunctionOnRegion() {
-    setUpJmxManagerOnVm0ThenConnect(null);
-
-    final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            getCache().createRegionFactory(RegionShortcut.REPLICATE);
-        Region region = dataRegionFactory.create(REGION_NAME);
-        assertNotNull(region);
-        FunctionService.registerFunction(function);
+      RegionFactory<Integer, Integer> dataRegionFactory =
+          cache.createRegionFactory(RegionShortcut.PARTITION);
+      Region region = dataRegionFactory.create(REGION_ONE);
+      for (int i = 0; i < 10; i++) {
+        region.put("key" + (i + 200), "value" + (i + 200));
       }
-    });
-
-    String command = "execute function --id=" + function.getId() + " --region=" + REGION_NAME;
-    getLogWriter().info("testExecuteFunctionOnRegion command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      getLogWriter().info("testExecuteFunctionOnRegion cmdResult=" + cmdResult);
-      String stringResult = commandResultToString(cmdResult);
-      getLogWriter().info("testExecuteFunctionOnRegion stringResult=" + stringResult);
-      assertTrue(stringResult.contains("Execution summary"));
-    } else {
-      fail("testExecuteFunctionOnRegion did not return CommandResult");
-    }
-  }
-
-  @Test
-  public void testExecuteFunctionOnRegionWithCustomResultCollector() {
-    setUpJmxManagerOnVm0ThenConnect(null);
-
-    final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_RETURN_ARGS);
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            getCache().createRegionFactory(RegionShortcut.REPLICATE);
-        Region region = dataRegionFactory.create(REGION_NAME);
-        assertNotNull(region);
-        FunctionService.registerFunction(function);
+      region = dataRegionFactory.create(REGION_TWO);
+      for (int i = 0; i < 1000; i++) {
+        region.put("key" + (i + 200), "value" + (i + 200));
       }
     });
 
-    String command = "execute function --id=" + function.getId() + " --region=" + REGION_NAME
-        + " --arguments=arg1,arg2" + " --result-collector="
-        + ToUpperResultCollector.class.getName();
-    getLogWriter().info("testExecuteFunctionOnRegion command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      getLogWriter().info("testExecuteFunctionOnRegion cmdResult=" + cmdResult);
-      String stringResult = commandResultToString(cmdResult);
-      getLogWriter().info("testExecuteFunctionOnRegion stringResult=" + stringResult);
-      assertTrue(stringResult.contains("Execution summary"));
-      assertTrue(stringResult.contains("ARG1"));
-    } else {
-      fail("testExecuteFunctionOnRegion did not return CommandResult");
-    }
-  }
-
-  void setupForBug51480() {
-    final VM vm1 = Host.getHost(0).getVM(1);
-    setUpJmxManagerOnVm0ThenConnect(null);
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-        // no need to close cache as it will be closed as part of teardown2
-        Cache cache = getCache();
-
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            cache.createRegionFactory(RegionShortcut.PARTITION);
-        Region region = dataRegionFactory.create(REGION_ONE);
-        for (int i = 0; i < 10; i++) {
-          region.put("key" + (i + 200), "value" + (i + 200));
-        }
+    server2.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.serverStarter.getCache();
+      RegionFactory<Integer, Integer> dataRegionFactory =
+          cache.createRegionFactory(RegionShortcut.PARTITION);
+      Region region = dataRegionFactory.create(REGION_ONE);
+      for (int i = 0; i < 10000; i++) {
+        region.put("key" + (i + 400), "value" + (i + 400));
+      }
+      region = dataRegionFactory.create(REGION_TWO);
+      for (int i = 0; i < 10; i++) {
+        region.put("key" + (i + 200), "value" + (i + 200));
       }
     });
-  }
 
-  SerializableRunnable checkRegionMBeans = new SerializableRunnable() {
-    @Override
-    public void run() {
-      final WaitCriterion waitForManagerMBean = new WaitCriterion() {
-        @Override
-        public boolean done() {
-          final ManagementService service = ManagementService.getManagementService(getCache());
-          final DistributedRegionMXBean bean =
-              service.getDistributedRegionMXBean(Region.SEPARATOR + REGION_ONE);
-          if (bean == null) {
-            return false;
-          } else {
-            getLogWriter()
-                .info("Probing for checkRegionMBeans testExecuteFunctionOnRegionBug51480 finished");
-            return true;
-          }
-        }
-
-        @Override
-        public String description() {
-          return "Probing for testExecuteFunctionOnRegionBug51480";
-        }
-      };
-      waitForCriterion(waitForManagerMBean, 2 * 60 * 1000, 2000, true);
-      DistributedRegionMXBean bean = ManagementService.getManagementService(getCache())
-          .getDistributedRegionMXBean(Region.SEPARATOR + REGION_ONE);
-      assertNotNull(bean);
-    }
-  };
-
-  @Test
-  public void testExecuteFunctionOnRegionBug51480() {
-    setupForBug51480();
+    registerFunction(new TestFunction(true, TestFunction.TEST_FUNCTION1), locator, server1,
+        server2);
+    registerFunction(new TestFunction(true, TestFunction.TEST_FUNCTION_RETURN_ARGS), locator,
+        server1, server2);
 
-    // check if DistributedRegionMXBean is available so that command will not fail
-    final VM manager = Host.getHost(0).getVM(0);
-    manager.invoke(checkRegionMBeans);
+    locator.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.locatorStarter.getLocator().getCache();
+      ManagementService managementService = ManagementService.getManagementService(cache);
+      DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean();
 
-    final Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        FunctionService.registerFunction(function);
-      }
+      await().atMost(120, TimeUnit.SECONDS).until(() -> dsMXBean.getMemberCount() == 3);
     });
 
-    String command = "execute function --id=" + function.getId() + " --region=" + REGION_ONE;
-
-    getLogWriter().info("testExecuteFunctionOnRegionBug51480 command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      getLogWriter().info("testExecuteFunctionOnRegionBug51480 cmdResult=" + cmdResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      String stringResult = commandResultToString(cmdResult);
-      getLogWriter().info("testExecuteFunctionOnRegionBug51480 stringResult=" + stringResult);
-      assertTrue(stringResult.contains("Execution summary"));
-    } else {
-      fail("testExecuteFunctionOnRegionBug51480 did not return CommandResult");
+    gfsh.connect(locator);
+  }
 
+  private void registerFunction(Function function, MemberVM... vms) {
+    for (MemberVM vm : vms) {
+      vm.invoke(() -> FunctionService.registerFunction(function));
     }
   }
 
   @Test
-  public void testExecuteFunctionOnMember() {
-    Properties localProps = new Properties();
-    localProps.setProperty(NAME, "Manager");
-    localProps.setProperty(GROUPS, "Group1");
-    setUpJmxManagerOnVm0ThenConnect(localProps);
-    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    FunctionService.registerFunction(function);
-    final VM vm1 = Host.getHost(0).getVM(1);
-    final String vm1MemberId = vm1.invoke(this::getMemberId);
-
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            getCache().createRegionFactory(RegionShortcut.REPLICATE);
-        Region region = dataRegionFactory.create(REGION_NAME);
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        assertNotNull(region);
-        FunctionService.registerFunction(function);
-      }
-    });
-
-    String command = "execute function --id=" + function.getId() + " --member=" + vm1MemberId;
-    getLogWriter().info("testExecuteFunctionOnMember command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-    String stringResult = commandResultToString(cmdResult);
-    getLogWriter().info("testExecuteFunctionOnMember stringResult:" + stringResult);
-    assertTrue(stringResult.contains("Execution summary"));
+  public void testExecuteFunctionOnRegion() {
+    CommandResult result = gfsh.executeAndVerifyCommand(
+        "execute function --id=" + TestFunction.TEST_FUNCTION1 + " --region=/" + REGION_ONE);
+    assertThat(((JSONArray) result.getContent().get("Member ID/Name")).length()).isEqualTo(2);
   }
 
   @Test
-  public void testExecuteFunctionOnMembers() {
-    Properties localProps = new Properties();
-    localProps.setProperty(NAME, "Manager");
-    localProps.setProperty(GROUPS, "Group1");
-    setUpJmxManagerOnVm0ThenConnect(localProps);
-    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    FunctionService.registerFunction(function);
-    final VM vm1 = Host.getHost(0).getVM(1);
-
-
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            getCache().createRegionFactory(RegionShortcut.REPLICATE);
-        Region region = dataRegionFactory.create(REGION_NAME);
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        assertNotNull(region);
-        FunctionService.registerFunction(function);
-      }
-    });
-    String command = "execute function --id=" + function.getId();
-    getLogWriter().info("testExecuteFunctionOnMembers command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      getLogWriter().info("testExecuteFunctionOnMembers cmdResult:" + cmdResult);
-      String stringResult = commandResultToString(cmdResult);
-      getLogWriter().info("testExecuteFunctionOnMembers stringResult:" + stringResult);
-      assertTrue(stringResult.contains("Execution summary"));
-    } else {
-      fail("testExecuteFunctionOnMembers did not return CommandResult");
-    }
+  public void testExecuteUnknownFunction() throws Exception {
+    CommandResult result = gfsh.executeAndVerifyCommand("execute function --id=UNKNOWN_FUNCTION");
+    assertThat(result.getContent().toString())
+        .contains("UNKNOWN_FUNCTION is not registered on member");
   }
 
   @Test
-  public void testExecuteFunctionOnMembersWithArgs() {
-    Properties localProps = new Properties();
-    localProps.setProperty(NAME, "Manager");
-    localProps.setProperty(GROUPS, "Group1");
-    setUpJmxManagerOnVm0ThenConnect(localProps);
-    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_RETURN_ARGS);
-    FunctionService.registerFunction(function);
-
-
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            getCache().createRegionFactory(RegionShortcut.REPLICATE);
-        Region region = dataRegionFactory.create(REGION_NAME);
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_RETURN_ARGS);
-        assertNotNull(region);
-        FunctionService.registerFunction(function);
-      }
-    });
-
-    String command = "execute function --id=" + function.getId() + " --arguments=arg1,arg2";
-
-    getLogWriter().info("testExecuteFunctionOnMembersWithArgs command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      getLogWriter().info("testExecuteFunctionOnMembersWithArgs cmdResult:" + cmdResult);
-      String stringResult = commandResultToString(cmdResult);
-      getLogWriter().info("testExecuteFunctionOnMembersWithArgs stringResult:" + stringResult);
-      assertTrue(stringResult.contains("Execution summary"));
-      assertTrue(stringResult.contains("arg1"));
-    } else {
-      fail("testExecuteFunctionOnMembersWithArgs did not return CommandResult");
-    }
+  public void testExecuteFunctionOnRegionWithCustomResultCollector() {
+    CommandResult result = gfsh
+        .executeAndVerifyCommand("execute function --id=" + TestFunction.TEST_FUNCTION_RETURN_ARGS
+            + " --region=" + REGION_ONE + " --arguments=arg1,arg2" + " --result-collector="
+            + ToUpperResultCollector.class.getName());
+    assertThat(result.getContent().toString()).contains("ARG1");
   }
 
   @Test
-  public void testExecuteFunctionOnMembersWithArgsAndCustomResultCollector() {
-    Properties localProps = new Properties();
-    localProps.setProperty(NAME, "Manager");
-    localProps.setProperty(GROUPS, "Group1");
-    setUpJmxManagerOnVm0ThenConnect(localProps);
-    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_RETURN_ARGS);
-    FunctionService.registerFunction(function);
-
-
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            getCache().createRegionFactory(RegionShortcut.REPLICATE);
-        Region region = dataRegionFactory.create(REGION_NAME);
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_RETURN_ARGS);
-        assertNotNull(region);
-        FunctionService.registerFunction(function);
-      }
-    });
-
-    String command = "execute function --id=" + function.getId() + " --arguments=\"arg1,arg2\""
-        + " --result-collector=" + ToUpperResultCollector.class.getName();
-
-    getLogWriter().info("testExecuteFunctionOnMembersWithArgs command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      getLogWriter().info("testExecuteFunctionOnMembersWithArgs cmdResult:" + cmdResult);
-      String stringResult = commandResultToString(cmdResult);
-      getLogWriter().info("testExecuteFunctionOnMembersWithArgs stringResult:" + stringResult);
-      assertTrue(stringResult.contains("Execution summary"));
-      assertTrue(stringResult.contains("ARG1"));
-    } else {
-      fail("testExecuteFunctionOnMembersWithArgs did not return CommandResult");
-    }
+  public void testExecuteFunctionOnMember() {
+    CommandResult result = gfsh.executeAndVerifyCommand("execute function --id="
+        + TestFunction.TEST_FUNCTION1 + " --member=" + server1.getMember().getName());
+    assertThat(((JSONArray) result.getContent().get("Member ID/Name")).length()).isEqualTo(1);
   }
 
-  @Test // FlakyTest: GEODE-1563
-  public void testExecuteFunctionOnGroups() {
-    Properties localProps = new Properties();
-    localProps.setProperty(NAME, "Manager");
-    localProps.setProperty(GROUPS, "Group0");
-    setUpJmxManagerOnVm0ThenConnect(localProps);
-    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    FunctionService.registerFunction(function);
-
-    VM vm1 = Host.getHost(0).getVM(1);
-    VM vm2 = Host.getHost(0).getVM(2);
-
-    String vm1id = (String) vm1.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws Exception {
-        Properties localProps = new Properties();
-        localProps.setProperty(GROUPS, "Group1");
-        getSystem(localProps);
-        Cache cache = getCache();
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-        return cache.getDistributedSystem().getDistributedMember().getId();
-      }
-    });
-
-    String vm2id = (String) vm2.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws Exception {
-        Properties localProps = new Properties();
-        localProps.setProperty(GROUPS, "Group2");
-        getSystem(localProps);
-        Cache cache = getCache();
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-        return cache.getDistributedSystem().getDistributedMember().getId();
-      }
-    });
-
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            getCache().createRegionFactory(RegionShortcut.REPLICATE);
-        Region region = dataRegionFactory.create(REGION_NAME);
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        assertNotNull(region);
-        FunctionService.registerFunction(function);
-      }
-    });
-
-    String command =
-        "execute function --id=" + TestFunction.TEST_FUNCTION1 + " --groups=Group1,Group2";
-    getLogWriter().info("testExecuteFunctionOnGroups command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    getLogWriter().info("testExecuteFunctionOnGroups cmdResult=" + cmdResult);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-    TabularResultData resultData = (TabularResultData) cmdResult.getResultData();
-    List<String> members = resultData.retrieveAllValues("Member ID/Name");
-    getLogWriter().info("testExecuteFunctionOnGroups members=" + members);
-    assertTrue(members.size() == 2 && members.contains(vm1id) && members.contains(vm2id));
+  @Test
+  public void testExecuteFunctionOnInvalidMember() {
+    CommandResult result = gfsh.executeCommand(
+        "execute function --id=" + TestFunction.TEST_FUNCTION1 + " --member=INVALID_MEMBER");
+    assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
   }
 
   @Test
-  public void testDestroyOnMember() {
-    setUpJmxManagerOnVm0ThenConnect(null);
-    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    FunctionService.registerFunction(function);
-    final VM vm1 = Host.getHost(0).getVM(1);
-    final String vm1MemberId = vm1.invoke(this::getMemberId);
-    String command = "destroy function --id=" + function.getId() + " --member=" + vm1MemberId;
-    getLogWriter().info("testDestroyOnMember command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      String strCmdResult = commandResultToString(cmdResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      getLogWriter().info("testDestroyOnMember strCmdResult=" + strCmdResult);
-      assertTrue(strCmdResult.contains("Destroyed TestFunction1 Successfully"));
-    } else {
-      fail("testDestroyOnMember failed as did not get CommandResult");
-    }
+  public void testExecuteFunctionOnAllMembers() {
+    CommandResult result =
+        gfsh.executeAndVerifyCommand("execute function --id=" + TestFunction.TEST_FUNCTION1);
+    assertThat(((JSONArray) result.getContent().get("Member ID/Name")).length()).isEqualTo(2);
   }
 
   @Test
-  public void testDestroyOnGroups() {
-    Properties localProps = new Properties();
-    localProps.setProperty(NAME, "Manager");
-    localProps.setProperty(GROUPS, "Group0");
-    setUpJmxManagerOnVm0ThenConnect(localProps);
-    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    FunctionService.registerFunction(function);
-
-    VM vm1 = Host.getHost(0).getVM(1);
-    VM vm2 = Host.getHost(0).getVM(2);
-
-    String vm1id = (String) vm1.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws Exception {
-        Properties localProps = new Properties();
-        localProps.setProperty(GROUPS, "Group1");
-        getSystem(localProps);
-        Cache cache = getCache();
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-        return cache.getDistributedSystem().getDistributedMember().getId();
-      }
-    });
+  public void testExecuteFunctionOnMultipleMembers() {
+    CommandResult result =
+        gfsh.executeAndVerifyCommand("execute function --id=" + TestFunction.TEST_FUNCTION1
+            + " --member=" + Strings.join(server1.getName(), server2.getName()).with(","));
+    assertThat(((JSONArray) result.getContent().get("Member ID/Name")).length()).isEqualTo(2);
+  }
 
+  @Test
+  public void testExecuteFunctionOnMultipleMembersWithArgsAndResultCollector() {
+    CommandResult result = gfsh.executeAndVerifyCommand(
+        "execute function --id=" + TestFunction.TEST_FUNCTION_RETURN_ARGS + " --arguments=arg1,arg2"
+            + " --result-collector=" + ToUpperResultCollector.class.getName());
+    assertThat(((JSONArray) result.getContent().get("Member ID/Name")).length()).isEqualTo(2);
+    assertThat(((JSONArray) result.getContent().get("Function Execution Result")).getString(0))
+        .contains("ARG1");
+    assertThat(((JSONArray) result.getContent().get("Function Execution Result")).getString(1))
+        .contains("ARG1");
+  }
 
-    String vm2id = (String) vm2.invoke(new SerializableCallable() {
-      @Override
-      public Object call() throws Exception {
-        Properties localProps = new Properties();
-        localProps.setProperty(GROUPS, "Group2");
-        getSystem(localProps);
-        Cache cache = getCache();
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-        return cache.getDistributedSystem().getDistributedMember().getId();
-      }
-    });
+  @Test
+  public void testExecuteFunctionOnGroup() {
+    CommandResult result = gfsh.executeAndVerifyCommand(
+        "execute function --id=" + TestFunction.TEST_FUNCTION1 + " --groups=group-1");
+    assertThat(((JSONArray) result.getContent().get("Member ID/Name")).length()).isEqualTo(1);
+  }
 
-    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
-      public void run() {
-        Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-        FunctionService.registerFunction(function);
-      }
-    });
+  @Test
+  public void testDestroyFunctionOnMember() {
+    gfsh.executeAndVerifyCommand(
+        "destroy function --id=" + TestFunction.TEST_FUNCTION1 + " --member=" + server1.getName());
+    CommandResult result = gfsh.executeAndVerifyCommand("list functions");
+    assertThat(((JSONArray) result.getContent().get("Function")).length()).isEqualTo(3);
+    gfsh.executeAndVerifyCommand(
+        "destroy function --id=" + TestFunction.TEST_FUNCTION1 + " --member=" + server2.getName());
+    result = gfsh.executeAndVerifyCommand("list functions");
+    assertThat(((JSONArray) result.getContent().get("Function")).length()).isEqualTo(2);
+  }
 
-    String command =
-        "destroy function --id=" + TestFunction.TEST_FUNCTION1 + " --groups=Group1,Group2";
-    getLogWriter().info("testDestroyOnGroups command=" + command);
-    CommandResult cmdResult = executeCommand(command);
-    getLogWriter().info("testDestroyOnGroups cmdResult=" + cmdResult);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-    String content;
-    content = cmdResult.getContent().get("message").toString();
-    getLogWriter().info("testDestroyOnGroups content = " + content);
-    assertNotNull(content);
-    assertTrue(content
-        .equals("[\"Destroyed " + TestFunction.TEST_FUNCTION1 + " Successfully on " + vm1id + ","
-            + vm2id + "\"]")
-        || content.equals("[\"Destroyed " + TestFunction.TEST_FUNCTION1 + " Successfully on "
-            + vm2id + "," + vm1id + "\"]"));
+  @Test
+  public void testDestroyFunctionOnGroup() {
+    gfsh.executeAndVerifyCommand(
+        "destroy function --id=" + TestFunction.TEST_FUNCTION1 + " --groups=group-1");
+    CommandResult result = gfsh.executeAndVerifyCommand("list functions");
+    assertThat(((JSONArray) result.getContent().get("Function")).length()).isEqualTo(3);
   }
 
   @Test
-  public void testListFunction() {
-    // Create the default setup, putting the Manager VM into Group1
-    Properties localProps = new Properties();
-    localProps.setProperty(GROUPS, "Group1");
-    setUpJmxManagerOnVm0ThenConnect(localProps);
-
-    // Find no functions
-    CommandResult cmdResult = executeCommand(CliStrings.LIST_FUNCTION);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-    assertTrue(commandResultToString(cmdResult).contains("No Functions Found"));
-
-    // Add a function in the manager VM (VM 0)
-    final Function function1 = new TestFunction(true, TestFunction.TEST_FUNCTION1);
-    final VM managerVm = Host.getHost(0).getVM(0);
-    managerVm.invoke(new SerializableRunnable() {
-      public void run() {
-        FunctionService.registerFunction(function1);
-      }
-    });
+  public void testListFunctions() {
+    CommandResult result = gfsh.executeAndVerifyCommand("list functions");
+    assertThat(((JSONArray) result.getContent().get("Function")).length()).isEqualTo(4);
 
-    // Add functions in another VM (VM 1)
-    final Function function2 = new TestFunction(true, TestFunction.TEST_FUNCTION2);
-    final Function function3 = new TestFunction(true, TestFunction.TEST_FUNCTION3);
-    final VM vm1 = Host.getHost(0).getVM(1);
-    final String vm1Name = "VM" + vm1.getId();
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        Properties localProps = new Properties();
-        localProps.setProperty(NAME, vm1Name);
-        localProps.setProperty(GROUPS, "Group2");
-        getSystem(localProps);
-        getCache();
-
-        FunctionService.registerFunction(function2);
-        FunctionService.registerFunction(function3);
-      }
-    });
+    result = gfsh.executeAndVerifyCommand("list functions --matches=Test.*");
+    assertThat(((JSONArray) result.getContent().get("Function")).length()).isEqualTo(2);
 
-    // Add functions in a third VM (VM 2)
-    final Function function4 = new TestFunction(true, TestFunction.TEST_FUNCTION4);
-    final Function function5 = new TestFunction(true, TestFunction.TEST_FUNCTION5);
-    final Function function6 = new TestFunction(true, TestFunction.TEST_FUNCTION6);
-    final VM vm2 = Host.getHost(0).getVM(2);
-    final String vm2Name = "VM" + vm2.getId();
-    vm2.invoke(new SerializableRunnable() {
-      public void run() {
-        Properties localProps = new Properties();
-        localProps.setProperty(NAME, vm2Name);
-        localProps.setProperty(GROUPS, "Group3");
-        getSystem(localProps);
-        getCache();
-
-        FunctionService.registerFunction(function4);
-        FunctionService.registerFunction(function5);
-        FunctionService.registerFunction(function6);
-      }
-    });
+    result = gfsh.executeAndVerifyCommand("list functions --matches=Test.* --groups=group-1");
+    assertThat(((JSONArray) result.getContent().get("Function")).length()).isEqualTo(1);
 
-    // Find all functions
-    cmdResult = executeCommand(CliStrings.LIST_FUNCTION);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-    String stringResult = commandResultToString(cmdResult);
-    assertEquals(8, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, "Member.*Function"));
-    assertTrue(stringContainsLine(stringResult, "Manager.*" + function1.getId()));
-    assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function2.getId()));
-    assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function3.getId()));
-    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function4.getId()));
-    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function5.getId()));
-    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function6.getId()));
-
-    // Find functions in group Group3
-    cmdResult = executeCommand(CliStrings.LIST_FUNCTION + " --group=Group1,Group3");
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-    stringResult = commandResultToString(cmdResult);
-    assertEquals(6, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, "Member.*Function"));
-    assertTrue(stringContainsLine(stringResult, "Manager.*" + function1.getId()));
-    assertFalse(stringContainsLine(stringResult, vm1Name + ".*"));
-    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function4.getId()));
-    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function5.getId()));
-    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function6.getId()));
-
-    // Find functions for Manager member
-    cmdResult = executeCommand(CliStrings.LIST_FUNCTION + " --member=Manager," + vm1Name);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-    stringResult = commandResultToString(cmdResult);
-    assertEquals(5, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, "Member.*Function"));
-    assertTrue(stringContainsLine(stringResult, "Manager.*" + function1.getId()));
-    assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function2.getId()));
-    assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function3.getId()));
-    assertFalse(stringContainsLine(stringResult, vm2Name + ".*"));
-
-    // Find functions that match a pattern
-    cmdResult = executeCommand(CliStrings.LIST_FUNCTION + " --matches=.*[135]$");
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-    stringResult = commandResultToString(cmdResult);
-    assertEquals(5, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, "Member.*Function"));
-    assertTrue(stringContainsLine(stringResult, "Manager.*" + function1.getId()));
-    assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + function2.getId()));
-    assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + function3.getId()));
-    assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + function4.getId()));
-    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + function5.getId()));
-    assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + function6.getId()));
+    result = gfsh
+        .executeAndVerifyCommand("list functions --matches=Test.* --members=" + server1.getName());
+    assertThat(((JSONArray) result.getContent().get("Function")).length()).isEqualTo(1);
   }
 }

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

[geode] 02/02: GEODE-3746: FunctionCommandsDUnitTest uses http as transport

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d1ef59150748f34737574f55984b9c7e93f96b5a
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Fri Oct 6 07:42:52 2017 -0700

    GEODE-3746: FunctionCommandsDUnitTest uses http as transport
---
 .../cli/commands/FunctionCommandsDUnitTest.java    |  8 ++++--
 .../cli/commands/CommandOverHttpDUnitTest.java     |  3 +--
 .../FunctionCommandsOverHttpDUnitTest.java         | 29 ++++++++++++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTest.java
index 9450d10..bcf71c2 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTest.java
@@ -109,7 +109,7 @@ public class FunctionCommandsDUnitTest {
       await().atMost(120, TimeUnit.SECONDS).until(() -> dsMXBean.getMemberCount() == 3);
     });
 
-    gfsh.connect(locator);
+    connectGfsh(locator);
   }
 
   private void registerFunction(Function function, MemberVM... vms) {
@@ -118,8 +118,12 @@ public class FunctionCommandsDUnitTest {
     }
   }
 
+  public void connectGfsh(MemberVM vm) throws Exception {
+    gfsh.connectAndVerify(vm.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger);
+  }
+
   @Test
-  public void testExecuteFunctionOnRegion() {
+  public void testExecuteFunctionOnRegion() throws Exception {
     CommandResult result = gfsh.executeAndVerifyCommand(
         "execute function --id=" + TestFunction.TEST_FUNCTION1 + " --region=/" + REGION_ONE);
     assertThat(((JSONArray) result.getContent().get("Member ID/Name")).length()).isEqualTo(2);
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
index 3999709..aae902d 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
@@ -27,8 +27,7 @@ import org.apache.geode.test.junit.runners.SuiteRunner;
 @Category({DistributedTest.class, SecurityTest.class})
 @RunWith(SuiteRunner.class)
 @Suite.SuiteClasses({ChangeLogLevelCommandDUnitTest.class, DeployWithGroupsDUnitTest.class,
-    DiskStoreCommandsDUnitTest.class, FunctionCommandsDUnitTest.class, GcCommandDUnitTest.class,
-    GemfireDataCommandsDUnitTest.class,
+    DiskStoreCommandsDUnitTest.class, GcCommandDUnitTest.class, GemfireDataCommandsDUnitTest.class,
     GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.class,
     ListAndDescribeDiskStoreCommandsDUnitTest.class, ListIndexCommandDUnitTest.class,
     ShutdownCommandDUnitTest.class, QueueCommandsDUnitTest.class, ShellCommandsDUnitTest.class,
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsOverHttpDUnitTest.java
new file mode 100644
index 0000000..12d93fa
--- /dev/null
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsOverHttpDUnitTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.commands;
+
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.GfshShellConnectionRule;
+import org.junit.experimental.categories.Category;
+
+@Category(DistributedTest.class)
+public class FunctionCommandsOverHttpDUnitTest extends FunctionCommandsDUnitTest {
+  @Override
+  public void connectGfsh(MemberVM vm) throws Exception {
+    gfsh.connectAndVerify(vm.getHttpPort(), GfshShellConnectionRule.PortType.http);
+  }
+}

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