SOLR-10408: v2 API introspect should return useful message for non-existent command

This commit is contained in:
Cao Manh Dat 2017-05-12 09:54:19 +07:00
parent 5a25ef0e77
commit f6b3337b65
3 changed files with 31 additions and 45 deletions

View File

@ -100,6 +100,8 @@ Bug Fixes
* SOLR-9837: Fix 55% performance regression of FieldCache uninvert time of * SOLR-9837: Fix 55% performance regression of FieldCache uninvert time of
numeric fields. (yonik) numeric fields. (yonik)
* SOLR-10408: v2 API introspect should return useful message for non-existent command (Cao Manh Dat)
Optimizations Optimizations
---------------------- ----------------------

View File

@ -154,7 +154,12 @@ public class ApiBag {
ValidatingJsonMap commands = specCopy.getMap("commands", null); ValidatingJsonMap commands = specCopy.getMap("commands", null);
if (commands != null) { if (commands != null) {
ValidatingJsonMap m = commands.getMap(cmd, 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; result = specCopy;
} }

View File

@ -18,16 +18,19 @@
package org.apache.solr.handler; package org.apache.solr.handler;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; 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.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.V2Request;
import org.apache.solr.cloud.SolrCloudTestCase; 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.common.util.Utils;
import org.apache.solr.core.TestSolrConfigHandler;
import org.apache.solr.util.RESTfulServerProvider;
import org.apache.solr.util.RestTestHarness; import org.apache.solr.util.RestTestHarness;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -37,29 +40,6 @@ public class V2ApiIntegrationTest extends SolrCloudTestCase {
private static String COLL_NAME = "collection1"; 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 @BeforeClass
public static void createCluster() throws Exception { public static void createCluster() throws Exception {
System.setProperty("managed.schema.mutable", "true"); System.setProperty("managed.schema.mutable", "true");
@ -71,28 +51,27 @@ public class V2ApiIntegrationTest extends SolrCloudTestCase {
} }
@Test @Test
public void test() throws Exception { public void testIntrospect() throws Exception {
try { ModifiableSolrParams params = new ModifiableSolrParams();
setupHarnesses(); params.set("command","XXXX");
testApis(); params.set("method", "POST");
Map result = resAsMap(cluster.getSolrClient(),
} finally { new V2Request.Builder("/c/"+COLL_NAME+"/_introspect")
for (RestTestHarness r : restTestHarnesses) { .withParams(params).build());
r.close(); assertEquals("Command not found!", Utils.getObjectByPath(result, false, "/spec[0]/commands/XXXX"));
}
}
} }
private void testApis() throws Exception { @Test
RestTestHarness restHarness = restTestHarnesses.get(0); public void testCollectionsApi() throws Exception {
ServerProvider serverProvider = (ServerProvider) restHarness.getServerProvider(); CloudSolrClient client = cluster.getSolrClient();
serverProvider.baseurl = serverProvider.jettySolrRunner.getBaseUrl()+"/____v2/c/"+ COLL_NAME; Map result = resAsMap(client, new V2Request.Builder("/c/"+COLL_NAME+"/get/_introspect").build());
Map result = TestSolrConfigHandler.getRespMap("/get/_introspect", restHarness);
assertEquals("/c/collection1/get", Utils.getObjectByPath(result, true, "/spec[0]/url/paths[0]")); assertEquals("/c/collection1/get", Utils.getObjectByPath(result, true, "/spec[0]/url/paths[0]"));
serverProvider.baseurl = serverProvider.jettySolrRunner.getBaseUrl()+"/____v2/collections/"+ COLL_NAME; result = resAsMap(client, new V2Request.Builder("/collections/"+COLL_NAME+"/get/_introspect").build());
result = TestSolrConfigHandler.getRespMap("/get/_introspect", restHarness);
assertEquals("/collections/collection1/get", Utils.getObjectByPath(result, true, "/spec[0]/url/paths[0]")); assertEquals("/collections/collection1/get", Utils.getObjectByPath(result, true, "/spec[0]/url/paths[0]"));
}
private Map resAsMap(CloudSolrClient client, V2Request request) throws SolrServerException, IOException {
NamedList<Object> rsp = client.request(request);
return rsp.asMap(100);
} }
} }