Skip to content

Commit

Permalink
SOLR-13721: TestApiFramework#testFramework failing in master consiste…
Browse files Browse the repository at this point in the history
…ntly
  • Loading branch information
noblepaul committed Aug 27, 2019
1 parent a9607b2 commit 7e5c071
Showing 1 changed file with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.api.Api;
import org.apache.solr.api.ApiBag;
import org.apache.solr.api.V2HttpCall;
import org.apache.solr.api.V2HttpCall.CompositeApi;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.util.CommandOperation;
import org.apache.solr.common.util.PathTrie;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.common.util.Utils;
import org.apache.solr.common.util.ValidatingJsonMap;
Expand All @@ -39,10 +45,6 @@
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.api.Api;
import org.apache.solr.api.V2HttpCall;
import org.apache.solr.common.util.CommandOperation;
import org.apache.solr.common.util.PathTrie;

import static org.apache.solr.api.ApiBag.EMPTY_SPEC;
import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
Expand Down Expand Up @@ -71,7 +73,7 @@ public void testFramework() {
Map<String, String> parts = new HashMap<>();
String fullPath = "/collections/hello/shards";
Api api = V2HttpCall.getApiInfo(containerHandlers, fullPath, "POST",
fullPath, parts);
fullPath, parts);
assertNotNull(api);
assertConditions(api.getSpec(), Utils.makeMap(
"/methods[0]", "POST",
Expand All @@ -81,7 +83,7 @@ public void testFramework() {

parts = new HashMap<>();
api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards", "POST",
null, parts);
null, parts);
assertConditions(api.getSpec(), Utils.makeMap(
"/methods[0]", "POST",
"/commands/split", NOT_NULL,
Expand All @@ -102,7 +104,7 @@ public void testFramework() {

parts = new HashMap<>();
api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello", "POST",
null, parts);
null, parts);
assertConditions(api.getSpec(), Utils.makeMap(
"/methods[0]", "POST",
"/commands/add-replica-property", NOT_NULL,
Expand All @@ -111,7 +113,7 @@ public void testFramework() {
assertEquals("hello", parts.get("collection"));

api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1/replica1", "DELETE",
null, parts);
null, parts);
assertConditions(api.getSpec(), Utils.makeMap(
"/methods[0]", "DELETE",
"/url/params/onlyIfDown/type", "boolean"
Expand All @@ -122,18 +124,21 @@ public void testFramework() {

SolrQueryResponse rsp = invoke(containerHandlers, null, "/collections/_introspect", GET, mockCC);

assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
"/spec[0]/methods[0]", "DELETE",
"/spec[1]/methods[0]", "POST",
"/spec[2]/methods[0]", "GET"
Set<String> methodNames = new HashSet<>();
methodNames.add(rsp.getValues()._getStr("/spec[0]/methods[0]", null));
methodNames.add(rsp.getValues()._getStr("/spec[1]/methods[0]", null));
methodNames.add(rsp.getValues()._getStr("/spec[2]/methods[0]", null));
assertTrue(methodNames.contains("DELETE"));
assertTrue(methodNames.contains("POST"));
assertTrue(methodNames.contains("GET"));

));
methodNames = new HashSet<>();

rsp = invoke(coreHandlers, "/schema/_introspect", "/collections/hello/schema/_introspect", GET, mockCC);
assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
"/spec[0]/methods[0]", "POST",
"/spec[0]/commands", NOT_NULL,
"/spec[1]/methods[0]", "GET"));
methodNames.add(rsp.getValues()._getStr("/spec[0]/methods[0]", null));
methodNames.add(rsp.getValues()._getStr("/spec[1]/methods[0]", null));
assertTrue(methodNames.contains("POST"));
assertTrue(methodNames.contains("GET"));

rsp = invoke(coreHandlers, "/", "/collections/hello/_introspect", GET, mockCC);
assertConditions(rsp.getValues().asMap(2), Utils.makeMap(
Expand All @@ -146,23 +151,25 @@ public void testFramework() {
));

}
public void testTrailingTemplatePaths(){
PathTrie<Api> registry = new PathTrie<>();

public void testTrailingTemplatePaths() {
PathTrie<Api> registry = new PathTrie<>();
Api api = new Api(EMPTY_SPEC) {
@Override
public void call(SolrQueryRequest req, SolrQueryResponse rsp) {

}
};
Api intropsect = new ApiBag.IntrospectApi(api,false);
ApiBag.registerIntrospect(Collections.emptyMap(),registry,"/c/.system/blob/{name}",intropsect);
Api intropsect = new ApiBag.IntrospectApi(api, false);
ApiBag.registerIntrospect(Collections.emptyMap(), registry, "/c/.system/blob/{name}", intropsect);
ApiBag.registerIntrospect(Collections.emptyMap(), registry, "/c/.system/{x}/{name}", intropsect);
assertEquals(intropsect, registry.lookup("/c/.system/blob/random_string/_introspect", new HashMap<>()));
assertEquals(intropsect, registry.lookup("/c/.system/blob/_introspect", new HashMap<>()));
assertEquals(intropsect, registry.lookup("/c/.system/_introspect", new HashMap<>()));
assertEquals(intropsect, registry.lookup("/c/.system/v1/_introspect", new HashMap<>()));
assertEquals(intropsect, registry.lookup("/c/.system/v1/v2/_introspect", new HashMap<>()));
}

private SolrQueryResponse invoke(PluginBag<SolrRequestHandler> reqHandlers, String path,
String fullPath, SolrRequest.METHOD method,
CoreContainer mockCC) {
Expand All @@ -184,14 +191,14 @@ private SolrQueryResponse invoke(PluginBag<SolrRequestHandler> reqHandlers, Stri
}

SolrQueryResponse rsp = new SolrQueryResponse();
LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>())){
LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>())) {
@Override
public List<CommandOperation> getCommands(boolean validateInput) {
return Collections.emptyList();
}
};

api.call(req,rsp);
api.call(req, rsp);
return rsp;

}
Expand All @@ -201,12 +208,12 @@ private void assertConditions(Map root, Map conditions) {
for (Object o : conditions.entrySet()) {
Map.Entry e = (Map.Entry) o;
String path = (String) e.getKey();
List<String> parts = StrUtils.splitSmart(path, path.charAt(0) == '/' ? '/':' ', true);
List<String> parts = StrUtils.splitSmart(path, path.charAt(0) == '/' ? '/' : ' ', true);
Object val = Utils.getObjectByPath(root, false, parts);
if (e.getValue() instanceof ValidatingJsonMap.PredicateWithErrMsg) {
ValidatingJsonMap.PredicateWithErrMsg value = (ValidatingJsonMap.PredicateWithErrMsg) e.getValue();
String err = value.test(val);
if(err != null){
if (err != null) {
assertEquals(err + " for " + e.getKey() + " in :" + Utils.toJSONString(root), e.getValue(), val);
}

Expand Down

0 comments on commit 7e5c071

Please sign in to comment.