geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [28/50] [abbrv] geode git commit: GEODE-2003: Changed REST api to handle fully qualified Classname for function ID's.
Date Fri, 20 Jan 2017 22:53:24 GMT
GEODE-2003: Changed REST api to handle fully qualified Classname for function ID's.


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

Branch: refs/heads/feature/GEODE-1930-2
Commit: 9f62ffc8815c27833a9ca2cc4b680481b5e054b3
Parents: 6d8aab0
Author: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Authored: Tue Jan 17 15:19:19 2017 -0800
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Tue Jan 17 15:19:19 2017 -0800

----------------------------------------------------------------------
 ...stAPIOnRegionFunctionExecutionDUnitTest.java | 20 ++---
 .../web/controllers/RestAPITestBase.java        | 23 ++---
 ...tAPIsOnGroupsFunctionExecutionDUnitTest.java | 17 ++--
 ...APIsOnMembersFunctionExecutionDUnitTest.java | 93 +++++++++++++++-----
 .../controllers/FunctionAccessController.java   |  2 +-
 5 files changed, 93 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/9f62ffc8/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIOnRegionFunctionExecutionDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIOnRegionFunctionExecutionDUnitTest.java
b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIOnRegionFunctionExecutionDUnitTest.java
index 5cae692..025084c 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIOnRegionFunctionExecutionDUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIOnRegionFunctionExecutionDUnitTest.java
@@ -134,11 +134,6 @@ public class RestAPIOnRegionFunctionExecutionDUnitTest extends RestAPITestBase
{
 
   }
 
-  @Override
-  protected String getFunctionID() {
-    return SampleFunction.Id;
-  }
-
   private void createCacheAndRegisterFunction() {
     restURLs.add(vm0.invoke("createCacheWithGroups",
         () -> createCacheWithGroups(vm0.getHost().getHostName(), null, urlContext)));
@@ -175,7 +170,7 @@ public class RestAPIOnRegionFunctionExecutionDUnitTest extends RestAPITestBase
{
     assertEquals(200, response.getStatusLine().getStatusCode());
     assertNotNull(response.getEntity());
 
-    assertCorrectInvocationCount(1, vm0, vm1, vm2, vm3);
+    assertCorrectInvocationCount("SampleFunction", 1, vm0, vm1, vm2, vm3);
 
     // remove the expected exception
     restURLs.clear();
@@ -194,7 +189,7 @@ public class RestAPIOnRegionFunctionExecutionDUnitTest extends RestAPITestBase
{
     assertEquals(200, response.getStatusLine().getStatusCode());
     assertNotNull(response.getEntity());
 
-    assertCorrectInvocationCount(4, vm0, vm1, vm2, vm3);
+    assertCorrectInvocationCount("SampleFunction", 4, vm0, vm1, vm2, vm3);
 
     restURLs.clear();
   }
@@ -212,7 +207,7 @@ public class RestAPIOnRegionFunctionExecutionDUnitTest extends RestAPITestBase
{
     assertEquals(200, response.getStatusLine().getStatusCode());
     assertNotNull(response.getEntity());
 
-    assertCorrectInvocationCount(1, vm0, vm1, vm2, vm3);
+    assertCorrectInvocationCount("SampleFunction", 1, vm0, vm1, vm2, vm3);
 
     restURLs.clear();
   }
@@ -242,14 +237,17 @@ public class RestAPIOnRegionFunctionExecutionDUnitTest extends RestAPITestBase
{
     assertNotNull(response.getEntity());
 
     // Assert that only 1 node has executed the function.
-    assertCorrectInvocationCount(4, vm0, vm1, vm2, vm3);
+    assertCorrectInvocationCount("SampleFunction", 4, vm0, vm1, vm2, vm3);
 
     jsonBody = "[" + "{\"@type\": \"double\",\"@value\": 220}"
         + ",{\"@type\":\"org.apache.geode.rest.internal.web.controllers.Item\","
         + "\"itemNo\":\"609\",\"description\":\"Part X Free on Bumper Offer\","
         + "\"quantity\":\"3\"," + "\"unitprice\":\"9\"," + "\"totalprice\":\"12.00\"}" +
"]";
 
-    resetInvocationCounts(vm0, vm1, vm2, vm3);
+    vm0.invoke(() -> resetInvocationCount("SampleFunction"));
+    vm1.invoke(() -> resetInvocationCount("SampleFunction"));
+    vm2.invoke(() -> resetInvocationCount("SampleFunction"));
+    vm3.invoke(() -> resetInvocationCount("SampleFunction"));
 
     response = executeFunctionThroughRestCall("SampleFunction", PR_REGION_NAME, "key2", jsonBody,
         null, null);
@@ -257,7 +255,7 @@ public class RestAPIOnRegionFunctionExecutionDUnitTest extends RestAPITestBase
{
     assertNotNull(response.getEntity());
 
     // Assert that only 1 node has executed the function.
-    assertCorrectInvocationCount(1, vm0, vm1, vm2, vm3);
+    assertCorrectInvocationCount("SampleFunction", 1, vm0, vm1, vm2, vm3);
 
     restURLs.clear();
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/9f62ffc8/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPITestBase.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPITestBase.java
b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPITestBase.java
index 68555bc..f2e90a4 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPITestBase.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPITestBase.java
@@ -124,9 +124,8 @@ class RestAPITestBase extends JUnit4DistributedTestCase {
     return "http://" + hostName + ":" + servicePort + context + "/v1";
   }
 
-  private int getInvocationCount() {
-    RestFunctionTemplate function =
-        (RestFunctionTemplate) FunctionService.getFunction(getFunctionID());
+  private int getInvocationCount(String functionID) {
+    RestFunctionTemplate function = (RestFunctionTemplate) FunctionService.getFunction(functionID);
     return function.invocationCount;
   }
 
@@ -176,10 +175,6 @@ class RestAPITestBase extends JUnit4DistributedTestCase {
     return post;
   }
 
-  protected String getFunctionID() {
-    throw new RuntimeException("This method should be overridden");
-  }
-
   void assertHttpResponse(CloseableHttpResponse response, int httpCode,
       int expectedServerResponses) {
     assertEquals(httpCode, response.getStatusLine().getStatusCode());
@@ -215,22 +210,16 @@ class RestAPITestBase extends JUnit4DistributedTestCase {
     return "";
   }
 
-  void assertCorrectInvocationCount(int expectedInvocationCount, VM... vms) {
+  void assertCorrectInvocationCount(String functionID, int expectedInvocationCount, VM...
vms) {
     int count = 0;
     for (final VM vm : vms) {
-      count += vm.invoke("getInvocationCount", () -> getInvocationCount());
+      count += vm.invoke("getInvocationCount", () -> getInvocationCount(functionID));
     }
     assertEquals(expectedInvocationCount, count);
   }
 
-  private void resetInvocationCount() {
-    RestFunctionTemplate f = (RestFunctionTemplate) FunctionService.getFunction(getFunctionID());
+  protected void resetInvocationCount(String functionID) {
+    RestFunctionTemplate f = (RestFunctionTemplate) FunctionService.getFunction(functionID);
     f.invocationCount = 0;
   }
-
-  void resetInvocationCounts(VM... vms) {
-    for (final VM vm : vms) {
-      vm.invoke("resetInvocationCount", () -> resetInvocationCount());
-    }
-  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/9f62ffc8/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnGroupsFunctionExecutionDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnGroupsFunctionExecutionDUnitTest.java
b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnGroupsFunctionExecutionDUnitTest.java
index eae528c..dc87bbc 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnGroupsFunctionExecutionDUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnGroupsFunctionExecutionDUnitTest.java
@@ -50,11 +50,6 @@ public class RestAPIsOnGroupsFunctionExecutionDUnitTest extends RestAPITestBase
   }
 
 
-  @Override
-  protected String getFunctionID() {
-    return OnGroupsFunction.Id;
-  }
-
   private void setupCacheWithGroupsAndFunction() {
     restURLs.add(vm0.invoke("createCacheWithGroups",
         () -> createCacheWithGroups(vm0.getHost().getHostName(), "g0,gm", urlContext)));
@@ -81,7 +76,7 @@ public class RestAPIsOnGroupsFunctionExecutionDUnitTest extends RestAPITestBase
       assertHttpResponse(response, 200, 3);
     }
 
-    assertCorrectInvocationCount(30, vm0, vm1, vm2);
+    assertCorrectInvocationCount("OnGroupsFunction", 30, vm0, vm1, vm2);
 
     restURLs.clear();
   }
@@ -99,7 +94,7 @@ public class RestAPIsOnGroupsFunctionExecutionDUnitTest extends RestAPITestBase
       assertHttpResponse(response, 500, 0);
     }
 
-    assertCorrectInvocationCount(0, vm0, vm1, vm2);
+    assertCorrectInvocationCount("OnGroupsFunction", 0, vm0, vm1, vm2);
     restURLs.clear();
   }
 
@@ -114,7 +109,7 @@ public class RestAPIsOnGroupsFunctionExecutionDUnitTest extends RestAPITestBase
           null, null, "no%20such%20group", null);
       assertHttpResponse(response, 500, 0);
     }
-    assertCorrectInvocationCount(0, vm0, vm1, vm2);
+    assertCorrectInvocationCount("OnGroupsFunction", 0, vm0, vm1, vm2);
 
     for (int i = 0; i < 5; i++) {
 
@@ -123,9 +118,11 @@ public class RestAPIsOnGroupsFunctionExecutionDUnitTest extends RestAPITestBase
       assertHttpResponse(response, 200, 1);
     }
 
-    assertCorrectInvocationCount(5, vm0, vm1, vm2);
+    assertCorrectInvocationCount("OnGroupsFunction", 5, vm0, vm1, vm2);
 
-    resetInvocationCounts(vm0, vm1, vm2);
+    vm0.invoke(() -> resetInvocationCount("OnGroupsFunction"));
+    vm1.invoke(() -> resetInvocationCount("OnGroupsFunction"));
+    vm2.invoke(() -> resetInvocationCount("OnGroupsFunction"));
 
     restURLs.clear();
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/9f62ffc8/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnMembersFunctionExecutionDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnMembersFunctionExecutionDUnitTest.java
b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnMembersFunctionExecutionDUnitTest.java
index 7528bff..71e9fcf 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnMembersFunctionExecutionDUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/RestAPIsOnMembersFunctionExecutionDUnitTest.java
@@ -14,28 +14,27 @@
  */
 package org.apache.geode.rest.internal.web.controllers;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.START_DEV_REST_API;
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Properties;
-
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.execute.FunctionContext;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.rest.internal.web.RestFunctionTemplate;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
 import org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Properties;
 
 @Category(DistributedTest.class)
 @RunWith(Parameterized.class)
@@ -61,16 +60,12 @@ public class RestAPIsOnMembersFunctionExecutionDUnitTest extends RestAPITestBase
 
     CacheFactory.create(new RestAPIsOnMembersFunctionExecutionDUnitTest().getSystem(props));
     FunctionService.registerFunction(new OnMembersFunction());
+    FunctionService.registerFunction(new FullyQualifiedFunction());
 
     return "http://" + hostName + ":" + servicePort + urlContext + "/v1";
 
   }
 
-  @Override
-  protected String getFunctionID() {
-    return OnMembersFunction.Id;
-  }
-
   @Test
   public void testFunctionExecutionOnAllMembers() {
     createCacheForVMs();
@@ -81,7 +76,7 @@ public class RestAPIsOnMembersFunctionExecutionDUnitTest extends RestAPITestBase
       assertHttpResponse(response, 200, 4);
     }
 
-    assertCorrectInvocationCount(20, vm0, vm1, vm2, vm3);
+    assertCorrectInvocationCount("OnMembersFunction", 20, vm0, vm1, vm2, vm3);
 
     restURLs.clear();
   }
@@ -107,7 +102,26 @@ public class RestAPIsOnMembersFunctionExecutionDUnitTest extends RestAPITestBase
       assertHttpResponse(response, 200, 3);
     }
 
-    assertCorrectInvocationCount(15, vm0, vm1, vm2, vm3);
+    assertCorrectInvocationCount("OnMembersFunction", 15, vm0, vm1, vm2, vm3);
+
+    restURLs.clear();
+  }
+
+  @Test
+  public void testFunctionExecutionWithFullyQualifiedName() {
+    createCacheForVMs();
+    // restURLs.add(createCacheAndRegisterFunction(vm0.getHost().getHostName(), "m1"));
+
+    for (int i = 0; i < 5; i++) {
+      CloseableHttpResponse response = executeFunctionThroughRestCall(
+          "org.apache.geode.rest.internal.web.controllers.FullyQualifiedFunction", null,
null, null,
+          null, "m1,m2,m3");
+      assertHttpResponse(response, 200, 3);
+    }
+
+    assertCorrectInvocationCount(
+        "org.apache.geode.rest.internal.web.controllers.FullyQualifiedFunction", 15, vm0,
vm1, vm2,
+        vm3);
 
     restURLs.clear();
   }
@@ -122,7 +136,7 @@ public class RestAPIsOnMembersFunctionExecutionDUnitTest extends RestAPITestBase
       assertHttpResponse(response, 500, 0);
     }
 
-    assertCorrectInvocationCount(0, vm0, vm1, vm2, vm3);
+    assertCorrectInvocationCount("OnMembersFunction", 0, vm0, vm1, vm2, vm3);
 
     restURLs.clear();
   }
@@ -134,7 +148,40 @@ public class RestAPIsOnMembersFunctionExecutionDUnitTest extends RestAPITestBase
     @Override
     public void execute(FunctionContext context) {
 
-      System.out.println("SWAP:1:executing OnMembersFunction:" + invocationCount);
+      invocationCount++;
+
+      context.getResultSender().lastResult(Boolean.TRUE);
+    }
+
+    @Override
+    public String getId() {
+      return Id;
+    }
+
+    @Override
+    public boolean hasResult() {
+      return true;
+    }
+
+    @Override
+    public boolean optimizeForWrite() {
+      return false;
+    }
+
+    @Override
+    public boolean isHA() {
+      return false;
+    }
+  }
+
+  private class FullyQualifiedFunction extends RestFunctionTemplate {
+
+    public static final String Id =
+        "org.apache.geode.rest.internal.web.controllers.FullyQualifiedFunction";
+
+    @Override
+    public void execute(FunctionContext context) {
+
       invocationCount++;
 
       context.getResultSender().lastResult(Boolean.TRUE);

http://git-wip-us.apache.org/repos/asf/geode/blob/9f62ffc8/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
index 08ec9a1..2169cb2 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
@@ -118,7 +118,7 @@ public class FunctionAccessController extends AbstractBaseController {
    *
    * @return result as a JSON document
    */
-  @RequestMapping(method = RequestMethod.POST, value = "/{functionId}",
+  @RequestMapping(method = RequestMethod.POST, value = "/{functionId:.+}",
       produces = {MediaType.APPLICATION_JSON_VALUE})
   @ApiOperation(value = "execute function",
       notes = "Execute function with arguments on regions, members, or group(s). By default
function will be executed on all nodes if none of (onRegion, onMembers, onGroups) specified",


Mime
View raw message