From f6b3337b6514515e5c8dc91e3d0ed6c372fabfb0 Mon Sep 17 00:00:00 2001 From: Cao Manh Dat Date: Fri, 12 May 2017 09:54:19 +0700 Subject: [PATCH] SOLR-10408: v2 API introspect should return useful message for non-existent command --- solr/CHANGES.txt | 2 + .../src/java/org/apache/solr/api/ApiBag.java | 7 +- .../solr/handler/V2ApiIntegrationTest.java | 67 +++++++------------ 3 files changed, 31 insertions(+), 45 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 530a0650512..9608da1b5bb 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -100,6 +100,8 @@ Bug Fixes * SOLR-9837: Fix 55% performance regression of FieldCache uninvert time of numeric fields. (yonik) +* SOLR-10408: v2 API introspect should return useful message for non-existent command (Cao Manh Dat) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/api/ApiBag.java b/solr/core/src/java/org/apache/solr/api/ApiBag.java index 14d029f807a..4ea8d0db0af 100644 --- a/solr/core/src/java/org/apache/solr/api/ApiBag.java +++ b/solr/core/src/java/org/apache/solr/api/ApiBag.java @@ -154,7 +154,12 @@ public class ApiBag { ValidatingJsonMap commands = specCopy.getMap("commands", null); if (commands != null) { ValidatingJsonMap m = commands.getMap(cmd, null); - specCopy.put("commands", Collections.singletonMap(cmd, m)); + if (m == null) { + specCopy.put("commands", Collections.singletonMap(cmd, "Command not found!")); + } else { + specCopy.put("commands", Collections.singletonMap(cmd, m)); + } + } result = specCopy; } diff --git a/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java b/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java index 4eb3de23de9..e478b0c54ba 100644 --- a/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java @@ -18,16 +18,19 @@ package org.apache.solr.handler; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.apache.solr.client.solrj.embedded.JettySolrRunner; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.V2Request; import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.Utils; -import org.apache.solr.core.TestSolrConfigHandler; -import org.apache.solr.util.RESTfulServerProvider; import org.apache.solr.util.RestTestHarness; import org.junit.BeforeClass; import org.junit.Test; @@ -37,29 +40,6 @@ public class V2ApiIntegrationTest extends SolrCloudTestCase { private static String COLL_NAME = "collection1"; - private void setupHarnesses() { - for (final JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) { - RestTestHarness harness = new RestTestHarness(new ServerProvider(jettySolrRunner)); - restTestHarnesses.add(harness); - } - } - static class ServerProvider implements RESTfulServerProvider { - - final JettySolrRunner jettySolrRunner; - String baseurl; - - ServerProvider(JettySolrRunner jettySolrRunner) { - this.jettySolrRunner = jettySolrRunner; - baseurl = jettySolrRunner.getBaseUrl().toString() + "/" + COLL_NAME; - } - - @Override - public String getBaseURL() { - return baseurl; - } - - } - @BeforeClass public static void createCluster() throws Exception { System.setProperty("managed.schema.mutable", "true"); @@ -71,28 +51,27 @@ public class V2ApiIntegrationTest extends SolrCloudTestCase { } @Test - public void test() throws Exception { - try { - setupHarnesses(); - testApis(); - - } finally { - for (RestTestHarness r : restTestHarnesses) { - r.close(); - } - } + public void testIntrospect() throws Exception { + ModifiableSolrParams params = new ModifiableSolrParams(); + params.set("command","XXXX"); + params.set("method", "POST"); + Map result = resAsMap(cluster.getSolrClient(), + new V2Request.Builder("/c/"+COLL_NAME+"/_introspect") + .withParams(params).build()); + assertEquals("Command not found!", Utils.getObjectByPath(result, false, "/spec[0]/commands/XXXX")); } - private void testApis() throws Exception { - RestTestHarness restHarness = restTestHarnesses.get(0); - ServerProvider serverProvider = (ServerProvider) restHarness.getServerProvider(); - serverProvider.baseurl = serverProvider.jettySolrRunner.getBaseUrl()+"/____v2/c/"+ COLL_NAME; - Map result = TestSolrConfigHandler.getRespMap("/get/_introspect", restHarness); + @Test + public void testCollectionsApi() throws Exception { + CloudSolrClient client = cluster.getSolrClient(); + Map result = resAsMap(client, new V2Request.Builder("/c/"+COLL_NAME+"/get/_introspect").build()); assertEquals("/c/collection1/get", Utils.getObjectByPath(result, true, "/spec[0]/url/paths[0]")); - serverProvider.baseurl = serverProvider.jettySolrRunner.getBaseUrl()+"/____v2/collections/"+ COLL_NAME; - result = TestSolrConfigHandler.getRespMap("/get/_introspect", restHarness); + result = resAsMap(client, new V2Request.Builder("/collections/"+COLL_NAME+"/get/_introspect").build()); assertEquals("/collections/collection1/get", Utils.getObjectByPath(result, true, "/spec[0]/url/paths[0]")); + } - + private Map resAsMap(CloudSolrClient client, V2Request request) throws SolrServerException, IOException { + NamedList rsp = client.request(request); + return rsp.asMap(100); } }