You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2015/01/13 11:06:22 UTC

svn commit: r1651316 - in /lucene/dev/branches/branch_5x/solr: ./ core/ core/src/test/org/apache/solr/core/TestSolrConfigHandler.java core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java

Author: noble
Date: Tue Jan 13 10:06:22 2015
New Revision: 1651316

URL: http://svn.apache.org/r1651316
Log:
SOLR-6770 Optimize tests to avoid duplicate REST calls

Modified:
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java?rev=1651316&r1=1651315&r2=1651316&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java Tue Jan 13 10:06:22 2015
@@ -229,7 +229,7 @@ public class TestSolrConfigHandler exten
 
   }
 
-  public static void testForResponseElement(RestTestHarness harness,
+  public static Map testForResponseElement(RestTestHarness harness,
                                             String testServerBaseUrl,
                                             String uri,
                                             CloudSolrClient cloudSolrServer,List<String> jsonPath,
@@ -257,6 +257,7 @@ public class TestSolrConfigHandler exten
     }
 
     assertTrue(MessageFormat.format("Could not get expected value  {0} for path {1} full output {2}", expected, jsonPath, getAsString(m)), success);
+    return m;
   }
 
   public void testReqParams() throws Exception{

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java?rev=1651316&r1=1651315&r2=1651316&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/TestSolrConfigHandlerCloud.java Tue Jan 13 10:06:22 2015
@@ -18,6 +18,7 @@ package org.apache.solr.handler;
  */
 
 
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -39,6 +40,9 @@ import org.junit.After;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static java.util.Arrays.asList;
+import static org.apache.solr.handler.TestBlobHandler.getAsString;
+
 public class TestSolrConfigHandlerCloud extends AbstractFullDistribZkTestBase {
   static final Logger log =  LoggerFactory.getLogger(TestSolrConfigHandlerCloud.class);
   private List<RestTestHarness> restTestHarnesses = new ArrayList<>();
@@ -102,23 +106,14 @@ public class TestSolrConfigHandlerCloud
 
     TestSolrConfigHandler.runConfigCommand(writeHarness,"/config/params?wt=json", payload);
 
-    TestSolrConfigHandler.testForResponseElement(
-        null,
+    Map result = TestSolrConfigHandler.testForResponseElement(null,
         urls.get(random().nextInt(urls.size())),
         "/config/params?wt=json",
         cloudClient,
-        Arrays.asList("response", "params", "x", "a"),
+        asList("response", "params", "x", "a"),
         "A val",
         10);
-
-    TestSolrConfigHandler.testForResponseElement(
-        null,
-        urls.get(random().nextInt(urls.size())),
-        "/config/params?wt=json",
-        cloudClient,
-        Arrays.asList("response", "params", "x", "b"),
-        "B val",
-        10);
+    compareValues(result, "B val", asList("response", "params", "x", "b"));
 
     payload = "{\n" +
         "'create-requesthandler' : { 'name' : '/dump', 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" +
@@ -130,7 +125,7 @@ public class TestSolrConfigHandlerCloud
         urls.get(random().nextInt(urls.size())),
         "/config/overlay?wt=json",
         cloudClient,
-        Arrays.asList("overlay", "requestHandler", "/dump", "name"),
+        asList("overlay", "requestHandler", "/dump", "name"),
         "/dump",
         10);
 
@@ -138,14 +133,14 @@ public class TestSolrConfigHandlerCloud
         urls.get(random().nextInt(urls.size())),
         "/dump?wt=json&useParams=x",
         cloudClient,
-        Arrays.asList("params", "a"),
+        asList("params", "a"),
         "A val",
         5);
     TestSolrConfigHandler.testForResponseElement(null,
         urls.get(random().nextInt(urls.size())),
         "/dump?wt=json&useParams=x&a=fomrequest",
         cloudClient,
-        Arrays.asList("params", "a"),
+        asList("params", "a"),
         "fomrequest",
         5);
 
@@ -155,19 +150,19 @@ public class TestSolrConfigHandlerCloud
 
     TestSolrConfigHandler.runConfigCommand(writeHarness,"/config?wt=json", payload);
 
-    TestSolrConfigHandler.testForResponseElement(null,
+    result = TestSolrConfigHandler.testForResponseElement(null,
         urls.get(random().nextInt(urls.size())),
         "/config/overlay?wt=json",
         cloudClient,
-        Arrays.asList("overlay", "requestHandler", "/dump1", "name"),
+        asList("overlay", "requestHandler", "/dump1", "name"),
         "/dump1",
         10);
 
-    TestSolrConfigHandler.testForResponseElement(null,
+    result = TestSolrConfigHandler.testForResponseElement(null,
         urls.get(random().nextInt(urls.size())),
         "/dump1?wt=json",
         cloudClient,
-        Arrays.asList("params", "a"),
+        asList("params", "a"),
         "A val",
         5);
 
@@ -184,40 +179,24 @@ public class TestSolrConfigHandlerCloud
 
     TestSolrConfigHandler.runConfigCommand(writeHarness,"/config/params?wt=json", payload);
 
-    TestSolrConfigHandler.testForResponseElement(
+   result =  TestSolrConfigHandler.testForResponseElement(
         null,
         urls.get(random().nextInt(urls.size())),
         "/config/params?wt=json",
         cloudClient,
-        Arrays.asList("response", "params", "y", "c"),
+        asList("response", "params", "y", "c"),
         "CY val",
         10);
 
-    TestSolrConfigHandler.testForResponseElement(null,
+    result = TestSolrConfigHandler.testForResponseElement(null,
         urls.get(random().nextInt(urls.size())),
         "/dump?wt=json&useParams=y",
         cloudClient,
-        Arrays.asList("params", "c"),
+        asList("params", "c"),
         "CY val",
         5);
-
-
-    TestSolrConfigHandler.testForResponseElement(null,
-        urls.get(random().nextInt(urls.size())),
-        "/dump1?wt=json&useParams=y",
-        cloudClient,
-        Arrays.asList("params", "b"),
-        "BY val",
-        5);
-
-    TestSolrConfigHandler.testForResponseElement(null,
-        urls.get(random().nextInt(urls.size())),
-        "/dump1?wt=json&useParams=y",
-        cloudClient,
-        Arrays.asList("params", "a"),
-        null,
-        5);
-
+    compareValues(result, "BY val", asList("params", "b"));
+    compareValues(result, null, asList("params", "a"));
     payload = " {\n" +
         "  'update' : {'y': {\n" +
         "                'c':'CY val modified',\n" +
@@ -230,23 +209,16 @@ public class TestSolrConfigHandlerCloud
 
     TestSolrConfigHandler.runConfigCommand(writeHarness,"/config/params?wt=json", payload);
 
-    TestSolrConfigHandler.testForResponseElement(
+    result = TestSolrConfigHandler.testForResponseElement(
         null,
         urls.get(random().nextInt(urls.size())),
         "/config/params?wt=json",
         cloudClient,
-        Arrays.asList("response", "params", "y", "c"),
+        asList("response", "params", "y", "c"),
         "CY val modified",
         10);
+    compareValues(result, "EY val", asList("response", "params", "y", "e"));
 
-    TestSolrConfigHandler.testForResponseElement(
-        null,
-        urls.get(random().nextInt(urls.size())),
-        "/config/params?wt=json",
-        cloudClient,
-        Arrays.asList("response", "params", "y", "e"),
-        "EY val",
-        10);
 
     payload = " {\n" +
         "  'set' : {'y': {\n" +
@@ -258,23 +230,16 @@ public class TestSolrConfigHandlerCloud
 
 
     TestSolrConfigHandler.runConfigCommand(writeHarness,"/config/params?wt=json", payload);
-    TestSolrConfigHandler.testForResponseElement(
+    result = TestSolrConfigHandler.testForResponseElement(
         null,
         urls.get(random().nextInt(urls.size())),
         "/config/params?wt=json",
         cloudClient,
-        Arrays.asList("response", "params", "y", "p"),
+        asList("response", "params", "y", "p"),
         "P val",
         10);
+    compareValues(result, null, asList("response", "params", "y", "c"));
 
-    TestSolrConfigHandler.testForResponseElement(
-        null,
-        urls.get(random().nextInt(urls.size())),
-        "/config/params?wt=json",
-        cloudClient,
-        Arrays.asList("response", "params", "y", "c"),
-        null,
-        10);
     payload = " {'delete' : 'y'}";
     TestSolrConfigHandler.runConfigCommand(writeHarness,"/config/params?wt=json", payload);
     TestSolrConfigHandler.testForResponseElement(
@@ -282,11 +247,16 @@ public class TestSolrConfigHandlerCloud
         urls.get(random().nextInt(urls.size())),
         "/config/params?wt=json",
         cloudClient,
-        Arrays.asList("response", "params", "y", "p"),
+        asList("response", "params", "y", "p"),
         null,
         10);
 
 
   }
 
+  public static void compareValues(Map result, String expected, List<String> jsonPath) {
+    assertTrue(MessageFormat.format("Could not get expected value  {0} for path {1} full output {2}", expected, jsonPath, getAsString(result)),
+        Objects.equals(expected, ConfigOverlay.getObjectByPath(result, false, jsonPath)));
+  }
+
 }