You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2015/01/21 18:55:48 UTC

[06/10] incubator-slider git commit: SLIDER-719 jersey tests about to migrate to WebTarget

SLIDER-719 jersey tests about to migrate to WebTarget


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

Branch: refs/heads/develop
Commit: 79d0e14f1d63b1e1a41edb77dce191238fb52eea
Parents: 72e4790
Author: Steve Loughran <st...@apache.org>
Authored: Tue Jan 20 17:47:51 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 17:47:51 2015 +0000

----------------------------------------------------------------------
 .../agent/rest/JerseyTestDelegates.groovy       | 120 +++++++++++--------
 1 file changed, 71 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/79d0e14f/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
index a06be23..cb89bff 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
@@ -23,7 +23,6 @@ import com.sun.jersey.api.client.WebResource
 import com.sun.jersey.api.client.UniformInterfaceException
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
-import org.apache.hadoop.yarn.webapp.NotFoundException
 import org.apache.slider.api.StateValues
 import org.apache.slider.api.types.SerializedComponentInformation
 import org.apache.slider.api.types.SerializedContainerInformation
@@ -77,10 +76,20 @@ class JerseyTestDelegates extends SliderTestUtils {
    * @return
    */
   public <T> T jGetApplicationResource(String subpath, Class<T> c) {
+    return (T)jExec(HttpVerb.GET, subpath, c)
+  }
+
+  /**
+   * <T> T get(Class<T> c)
+   * Get operation against a path under the Application
+   * @param subpath path
+   * @return
+   */
+  public <T> T jExec(HttpVerb  method, String subpath, Class<T> c) {
     assert c
     def appPath = appendToURL(SLIDER_PATH_APPLICATION, subpath)
     WebResource webResource = buildResource(appPath)
-    (T)webResource.get(c)
+    (T) webResource.method(method.verb, c)
   }
 
   /**
@@ -137,7 +146,13 @@ class JerseyTestDelegates extends SliderTestUtils {
     log.info jerseyGet(SYSTEM_METRICS)
   }
 
-  public <T> T fetchJType(
+  /**
+   * Fetch a typed entry <i>under the application path</i>
+   * @param subpath
+   * @param clazz
+   * @return
+   */
+  public <T> T jFetchType(
       String subpath, Class<T> clazz) {
     (T)jGetApplicationResource(subpath, clazz)
   }
@@ -149,7 +164,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     return tree
   }
 
-    public void testLiveResources() throws Throwable {
+  public void testLiveResources() throws Throwable {
     describe "Live Resources"
     ConfTreeOperations tree = jGetConfigTree(LIVE_RESOURCES)
 
@@ -190,7 +205,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     describe "containers"
 
     SerializedContainerInformation retrievedContainerInfo =
-        fetchJType(
+        jFetchType(
             LIVE_CONTAINERS + "/${amContainerId}",
             SerializedContainerInformation
         )
@@ -198,7 +213,7 @@ class JerseyTestDelegates extends SliderTestUtils {
 
     // fetch missing
     try {
-      def result = fetchJType(
+      def result = jFetchType(
           LIVE_CONTAINERS + "/unknown",
           SerializedContainerInformation
       )
@@ -211,7 +226,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     describe "components"
 
     Map<String, SerializedComponentInformation> components =
-        fetchJType(LIVE_COMPONENTS, HashMap)
+        jFetchType(LIVE_COMPONENTS, HashMap)
     // two components
     assert components.size() == 1
     log.info "${components}"
@@ -219,7 +234,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     SerializedComponentInformation amComponentInfo =
         (SerializedComponentInformation) components[COMPONENT_AM]
 
-    SerializedComponentInformation amFullInfo = fetchJType(
+    SerializedComponentInformation amFullInfo = jFetchType(
         LIVE_COMPONENTS + "/${COMPONENT_AM}",
         SerializedComponentInformation
     )
@@ -230,6 +245,39 @@ class JerseyTestDelegates extends SliderTestUtils {
   }
 
   /**
+   * Assert that a path resolves to an array list that contains
+   * those entries (and only those entries) expected
+   * @param appmaster AM ref
+   * @param path path under AM
+   * @param entries entries to assert the presence of
+   */
+  public void assertPathServesList(
+      String appmaster,
+      String path,
+      List<String> entries) {
+    def list = jFetchType(path, ArrayList)
+    assert list.size() == entries.size()
+    assert entries.containsAll(list)
+  }
+
+  /**
+   * Fetch a list of URLs, all of which must be of the same type
+   * @param clazz class of resolved values
+   * @param appmaster URL to app master
+   * @param subpaths list of subpaths
+   * @return a map of paths to values
+   */
+  public <T> Map<String, T> fetchTypeList(
+      Class<T> clazz, String appmaster, List<String> subpaths
+                                         ) {
+    Map<String, T> results = [:]
+    subpaths.each { String it ->
+      results[it] = (jFetchType(it, clazz))
+    }
+    return results;
+  }
+
+  /**
    * Test the rest model. For this to work the cluster has to be configured
    * with the global option
    * @param appmaster
@@ -241,14 +289,14 @@ class JerseyTestDelegates extends SliderTestUtils {
         MODEL,
         ApplicationResource.MODEL_ENTRIES)
 
-    def unresolvedConf = fetchJType(MODEL_DESIRED, AggregateConf)
+    def unresolvedConf = jFetchType(MODEL_DESIRED, AggregateConf)
 //    log.info "Unresolved \n$unresolvedConf"
     def unresolvedAppConf = unresolvedConf.appConfOperations
 
     def sam = "slider-appmaster"
     assert unresolvedAppConf.getComponentOpt(sam,
         TEST_GLOBAL_OPTION, "") == ""
-    def resolvedConf = fetchJType(MODEL_RESOLVED, AggregateConf)
+    def resolvedConf = jFetchType(MODEL_RESOLVED, AggregateConf)
 //    log.info "Resolved \n$resolvedConf"
     assert resolvedConf.appConfOperations.getComponentOpt(
         sam, TEST_GLOBAL_OPTION, "") == TEST_GLOBAL_OPTION_PRESENT
@@ -261,54 +309,28 @@ class JerseyTestDelegates extends SliderTestUtils {
 
     def resolved = fetchTypeList(ConfTree, appmaster,
         [MODEL_RESOLVED_APPCONF, MODEL_RESOLVED_RESOURCES])
-    assert resolved[MODEL_RESOLVED_APPCONF].components[sam]
-    [TEST_GLOBAL_OPTION] ==
-    TEST_GLOBAL_OPTION_PRESENT
-  }
-
-
-  public void testRestletGetOperations() throws Throwable {
-    Client client = createJerseyClient()
-    String path = appendToURL(application, LIVE_RESOURCES)
-    WebResource webResource = client.resource(path)
-    webResource.type(MediaType.APPLICATION_JSON)
-               .get(ConfTree.class);
+    assert resolved[MODEL_RESOLVED_APPCONF].
+               components[sam][TEST_GLOBAL_OPTION] == TEST_GLOBAL_OPTION_PRESENT
   }
 
   public void testPing() {
     // GET
-    String ping = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_PING)
-    describe "ping to AM URL $appmaster, ping URL $ping"
-    def pinged = fetchJType(
-        ACTION_PING + "?body=hello",
-        PingResource
-    )
+    describe "pinging"
+    
+    def pinged = jExec(HttpVerb.GET, ACTION_PING, PingResource)
     log.info "Ping GET: $pinged"
-
-    URL pingUrl = new URL(ping)
-    def message = "hello"
-
     // HEAD
-    pingAction(HttpVerb.HEAD, pingUrl, message)
-
-    // Other verbs
-    pingAction(HttpVerb.POST, pingUrl, message)
-    pingAction(HttpVerb.PUT, pingUrl, message)
-    pingAction(HttpVerb.DELETE, pingUrl, message)
+    jExec(HttpVerb.HEAD, ACTION_PING, PingResource)
+    jExec(HttpVerb.PUT, ACTION_PING, PingResource)
+    jExec(HttpVerb.DELETE, ACTION_PING, PingResource)
+    jExec(HttpVerb.POST, ACTION_PING, PingResource)
 
   }
 
-
-  private HttpOperationResponse pingAction(
-      HttpVerb verb,
-      URL pingUrl,
-      String payload) {
-    return pingAction(connectionOperations, verb, pingUrl, payload)
-  }
-
   private HttpOperationResponse pingAction(
-      UrlConnectionOperations ops, HttpVerb verb, URL pingUrl, String payload) {
+      HttpVerb verb, String subpath, String payload) {
     def pinged
+    jExec(verb,subpath, PingResource)
     def outcome = ops.execHttpOperation(
         verb,
         pingUrl,
@@ -355,7 +377,7 @@ class JerseyTestDelegates extends SliderTestUtils {
         [url: ping],
         true,
         "AM failed to shut down") {
-      def pinged = fetchJType(ACTION_PING + "?body=hello",
+      def pinged = jFetchType(ACTION_PING + "?body=hello",
           PingResource
       )
       fail("AM didn't shut down; Ping GET= $pinged")
@@ -383,10 +405,10 @@ class JerseyTestDelegates extends SliderTestUtils {
 
   public void suite() {
 
-    testRestletGetOperations();
     testCodahaleOperations()
     testLiveResources()
     testLiveContainers();
+    testPing();
 
     testRESTModel()
   }