geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aging...@apache.org
Subject [45/60] [abbrv] incubator-geode git commit: GEODE-1326: Add test for gfsh function execution with ResultCollector
Date Tue, 03 May 2016 21:45:59 GMT
GEODE-1326: Add test for gfsh function execution with ResultCollector


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

Branch: refs/heads/feature/GEODE-1209
Commit: ce43082f9cf0cd1702bd0de5e6be6b314e063396
Parents: 72be65f
Author: Jens Deppe <jdeppe@pivotal.io>
Authored: Fri Apr 29 09:23:09 2016 -0700
Committer: Jens Deppe <jdeppe@pivotal.io>
Committed: Fri Apr 29 14:13:36 2016 -0700

----------------------------------------------------------------------
 .../cli/commands/FunctionCommandsDUnitTest.java | 72 +++++++++++++++++++-
 .../cli/commands/ToUpperResultCollector.java    | 65 ++++++++++++++++++
 2 files changed, 135 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ce43082f/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/FunctionCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/FunctionCommandsDUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/FunctionCommandsDUnitTest.java
index b4a2cef..86c0273 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/FunctionCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/FunctionCommandsDUnitTest.java
@@ -163,7 +163,38 @@ public class FunctionCommandsDUnitTest extends CliCommandTestBase {
       getLogWriter().info("testExecuteFunctionOnRegion cmdResult=" + cmdResult);
       String stringResult = commandResultToString(cmdResult);
       getLogWriter().info("testExecuteFunctionOnRegion stringResult=" + stringResult);
-      assert (stringResult.contains("Execution summary"));
+      assertTrue(stringResult.contains("Execution summary"));
+    } else {
+      fail("testExecuteFunctionOnRegion did not return CommandResult");
+    }
+  }
+
+  @Test
+  public void testExecuteFunctionOnRegionWithCustomResultCollector() {
+    createDefaultSetup(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);
+      }
+    });
+
+    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");
     }
@@ -240,7 +271,7 @@ public class FunctionCommandsDUnitTest extends CliCommandTestBase {
       assertEquals(Result.Status.OK, cmdResult.getStatus());
       String stringResult = commandResultToString(cmdResult);
       getLogWriter().info("testExecuteFunctionOnRegionBug51480 stringResult=" + stringResult);
-      assert (stringResult.contains("Execution summary"));
+      assertTrue(stringResult.contains("Execution summary"));
     } else {
       fail("testExecuteFunctionOnRegionBug51480 did not return CommandResult");
 
@@ -349,6 +380,43 @@ public class FunctionCommandsDUnitTest extends CliCommandTestBase {
   }
 
   @Test
+  public void testExecuteFunctionOnMembersWithArgsAndCustomResultCollector() {
+    Properties localProps = new Properties();
+    localProps.setProperty(DistributionConfig.NAME_NAME, "Manager");
+    localProps.setProperty(DistributionConfig.GROUPS_NAME, "Group1");
+    createDefaultSetup(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");
+    }
+  }
+
+  @Test
   public void testExecuteFunctionOnGroups() {
     Properties localProps = new Properties();
     localProps.setProperty(DistributionConfig.NAME_NAME, "Manager");

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ce43082f/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ToUpperResultCollector.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ToUpperResultCollector.java
b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ToUpperResultCollector.java
new file mode 100644
index 0000000..613463a
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ToUpperResultCollector.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.management.internal.cli.commands;
+
+import com.gemstone.gemfire.cache.execute.FunctionException;
+import com.gemstone.gemfire.cache.execute.ResultCollector;
+import com.gemstone.gemfire.distributed.DistributedMember;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+public class ToUpperResultCollector implements ResultCollector {
+
+  private List<Object> results = new ArrayList<>();
+
+  private CountDownLatch latch = new CountDownLatch(1);
+
+  @Override
+  public Object getResult() throws FunctionException {
+    try {
+      latch.await();
+    } catch (InterruptedException e) {
+      throw new FunctionException("Interrupted waiting for results", e);
+    }
+    return results;
+  }
+
+  @Override
+  public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException
{
+    latch.await(timeout, unit);
+    return results;
+  }
+
+  @Override
+  public void addResult(DistributedMember memberID, Object resultOfSingleExecution) {
+    results.add(resultOfSingleExecution.toString().toUpperCase());
+  }
+
+  @Override
+  public void endResults() {
+    latch.countDown();
+  }
+
+  @Override
+  public void clearResults() {
+    results.clear();
+    latch = new CountDownLatch(1);
+  }
+}


Mime
View raw message