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
numeric fields. (yonik)
* SOLR-10408: v2 API introspect should return useful message for non-existent command (Cao Manh Dat)
Optimizations
----------------------

View File

@ -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;
}

View File

@ -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<Object> rsp = client.request(request);
return rsp.asMap(100);
}
}