Search in sources :

Example 26 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestCryptoKeys method setupHarnesses.

private void setupHarnesses() {
    for (final SolrClient client : clients) {
        RestTestHarness harness = new RestTestHarness(() -> ((HttpSolrClient) client).getBaseURL());
        restTestHarnesses.add(harness);
    }
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient)

Example 27 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestReqParamsAPI method setupHarnesses.

private void setupHarnesses() {
    for (final JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) {
        RestTestHarness harness = new RestTestHarness(() -> jettySolrRunner.getBaseUrl().toString() + "/" + COLL_NAME);
        if (true) {
            harness.setServerProvider(() -> jettySolrRunner.getBaseUrl().toString() + "/____v2/c/" + COLL_NAME);
        }
        restTestHarnesses.add(harness);
    }
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner)

Example 28 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestReqParamsAPI method testReqParams.

private void testReqParams() throws Exception {
    CloudSolrClient cloudClient = cluster.getSolrClient();
    DocCollection coll = cloudClient.getZkStateReader().getClusterState().getCollection(COLL_NAME);
    List<String> urls = new ArrayList<>();
    for (Slice slice : coll.getSlices()) {
        for (Replica replica : slice.getReplicas()) urls.add("" + replica.get(ZkStateReader.BASE_URL_PROP) + "/" + replica.get(ZkStateReader.CORE_NAME_PROP));
    }
    RestTestHarness writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    String payload = "{\n" + "'create-requesthandler' : { 'name' : '/dump0', 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/dump1', 'class': 'org.apache.solr.handler.DumpRequestHandler', 'useParams':'x' }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);
    AbstractFullDistribZkTestBase.waitForRecoveriesToFinish(COLL_NAME, cloudClient.getZkStateReader(), false, true, 90);
    payload = " {\n" + "  'set' : {'x': {" + "                    'a':'A val',\n" + "                    'b': 'B val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    Map result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "x", "a"), "A val", 10);
    compareValues(result, "B val", asList("response", "params", "x", "b"));
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/overlay?wt=json", cloudClient, asList("overlay", "requestHandler", "/dump0", "name"), "/dump0", 10);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump0?wt=json&useParams=x", cloudClient, asList("params", "a"), "A val", 5);
    compareValues(result, "", asList("params", RequestParams.USEPARAM));
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump0?wt=json&useParams=x&a=fomrequest", cloudClient, asList("params", "a"), "fomrequest", 5);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/overlay?wt=json", cloudClient, asList("overlay", "requestHandler", "/dump1", "name"), "/dump1", 10);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump1?wt=json", cloudClient, asList("params", "a"), "A val", 5);
    writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    payload = " {\n" + "  'set' : {'y':{\n" + "                'c':'CY val',\n" + "                'b': 'BY val', " + "                'i': 20, " + "                'd': ['val 1', 'val 2']}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "c"), "CY val", 10);
    compareValues(result, 20l, asList("response", "params", "y", "i"));
    compareValues(result, null, asList("response", "params", "y", "a"));
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump1?wt=json&useParams=y", cloudClient, asList("params", "c"), "CY val", 5);
    compareValues(result, "BY val", asList("params", "b"));
    compareValues(result, "A val", asList("params", "a"));
    compareValues(result, Arrays.asList("val 1", "val 2"), asList("params", "d"));
    compareValues(result, "20", asList("params", "i"));
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/requestHandler?componentName=/dump1&expandParams=true&wt=json&useParams=y&c=CC", cloudClient, asList("config", "requestHandler", "/dump1", "_useParamsExpanded_", "x", "a"), "A val", 5);
    compareValues(result, "B val", asList("config", "requestHandler", "/dump1", "_useParamsExpanded_", "x", "b"));
    compareValues(result, "CY val", asList("config", "requestHandler", "/dump1", "_useParamsExpanded_", "y", "c"));
    compareValues(result, "BY val", asList("config", "requestHandler", "/dump1", "_useParamsExpanded_", "y", "b"));
    compareValues(result, "A val", asList("config", "requestHandler", "/dump1", "_effectiveParams_", "a"));
    compareValues(result, "BY val", asList("config", "requestHandler", "/dump1", "_effectiveParams_", "b"));
    compareValues(result, "CC", asList("config", "requestHandler", "/dump1", "_effectiveParams_", "c"));
    payload = " {\n" + "  'update' : {'y': {\n" + "                'c':'CY val modified',\n" + "                'e':'EY val',\n" + "                'b': 'BY val'" + "}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "c"), "CY val modified", 10);
    compareValues(result, "EY val", asList("response", "params", "y", "e"));
    payload = " {\n" + "  'set' : {'y': {\n" + "                'p':'P val',\n" + "                'q': 'Q val'" + "}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "p"), "P val", 10);
    compareValues(result, null, asList("response", "params", "y", "c"));
    compareValues(result, 2l, asList("response", "params", "y", "", "v"));
    compareValues(result, 0l, asList("response", "params", "x", "", "v"));
    payload = "{update :{x : {_appends_ :{ add : 'first' },  _invariants_ : {fixed: f }}}}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "x", "_appends_", "add"), "first", 10);
    compareValues(result, "f", asList("response", "params", "x", "_invariants_", "fixed"));
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump1?wt=json&fixed=changeit&add=second", cloudClient, asList("params", "fixed"), "f", 5);
    compareValues(result, new Predicate() {

        @Override
        public boolean test(Object o) {
            List l = (List) o;
            return l.contains("first") && l.contains("second");
        }
    }, asList("params", "add"));
    payload = " {'delete' : 'y'}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "p"), null, 10);
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Predicate(java.util.function.Predicate) Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) DocCollection(org.apache.solr.common.cloud.DocCollection) Map(java.util.Map)

Example 29 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestSolrConfigHandlerCloud method testAdminPath.

private void testAdminPath() throws Exception {
    String testServerBaseUrl = getRandomServer(cloudClient, "collection1");
    RestTestHarness writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    String payload = "{\n" + "'create-requesthandler' : { 'name' : '/admin/luke', " + "'class': 'org.apache.solr.handler.DumpRequestHandler'}}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(writeHarness, testServerBaseUrl, "/config/overlay?wt=json", cloudClient, Arrays.asList("overlay", "requestHandler", "/admin/luke", "class"), "org.apache.solr.handler.DumpRequestHandler", 10);
    NamedList<Object> rsp = cloudClient.request(new LukeRequest());
    System.out.println(rsp);
}
Also used : LukeRequest(org.apache.solr.client.solrj.request.LukeRequest) RestTestHarness(org.apache.solr.util.RestTestHarness) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString)

Example 30 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestSolrConfigHandlerCloud method testReqParams.

private void testReqParams() throws Exception {
    DocCollection coll = cloudClient.getZkStateReader().getClusterState().getCollection("collection1");
    List<String> urls = new ArrayList<>();
    for (Slice slice : coll.getSlices()) {
        for (Replica replica : slice.getReplicas()) urls.add("" + replica.get(ZkStateReader.BASE_URL_PROP) + "/" + replica.get(ZkStateReader.CORE_NAME_PROP));
    }
    RestTestHarness writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    String payload = " {\n" + "  'set' : {'x': {" + "                    'a':'A val',\n" + "                    'b': 'B val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    Map result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "x", "a"), "A val", 10);
    compareValues(result, "B val", asList("response", "params", "x", "b"));
    payload = "{\n" + "'update-requesthandler' : { 'name' : '/dump', 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/overlay?wt=json", cloudClient, asList("overlay", "requestHandler", "/dump", "name"), "/dump", 10);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump?wt=json&useParams=x", cloudClient, asList("params", "a"), "A val", 5);
    compareValues(result, "", asList("params", RequestParams.USEPARAM));
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump?wt=json&useParams=x&a=fomrequest", cloudClient, asList("params", "a"), "fomrequest", 5);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/dump1', 'class': 'org.apache.solr.handler.DumpRequestHandler', 'useParams':'x' }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/overlay?wt=json", cloudClient, asList("overlay", "requestHandler", "/dump1", "name"), "/dump1", 10);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump1?wt=json", cloudClient, asList("params", "a"), "A val", 5);
    writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    payload = " {\n" + "  'set' : {'y':{\n" + "                'c':'CY val',\n" + "                'b': 'BY val', " + "                'i': 20, " + "                'd': ['val 1', 'val 2']}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "c"), "CY val", 10);
    compareValues(result, 20l, asList("response", "params", "y", "i"));
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump?wt=json&useParams=y", cloudClient, asList("params", "c"), "CY val", 5);
    compareValues(result, "BY val", asList("params", "b"));
    compareValues(result, null, asList("params", "a"));
    compareValues(result, Arrays.asList("val 1", "val 2"), asList("params", "d"));
    compareValues(result, "20", asList("params", "i"));
    payload = " {\n" + "  'update' : {'y': {\n" + "                'c':'CY val modified',\n" + "                'e':'EY val',\n" + "                'b': 'BY val'" + "}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "c"), "CY val modified", 10);
    compareValues(result, "EY val", asList("response", "params", "y", "e"));
    payload = " {\n" + "  'set' : {'y': {\n" + "                'p':'P val',\n" + "                'q': 'Q val'" + "}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "p"), "P val", 10);
    compareValues(result, null, asList("response", "params", "y", "c"));
    payload = " {'delete' : 'y'}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "p"), null, 10);
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString) Replica(org.apache.solr.common.cloud.Replica) Map(java.util.Map)

Aggregations

RestTestHarness (org.apache.solr.util.RestTestHarness)40 Map (java.util.Map)19 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)15 StringReader (java.io.StringReader)12 JSONParser (org.noggit.JSONParser)12 SolrClient (org.apache.solr.client.solrj.SolrClient)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)6 List (java.util.List)6 TestBlobHandler.getAsString (org.apache.solr.handler.TestBlobHandler.getAsString)6 Test (org.junit.Test)6 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)5 Replica (org.apache.solr.common.cloud.Replica)4 Slice (org.apache.solr.common.cloud.Slice)4 HashMap (java.util.HashMap)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 DocCollection (org.apache.solr.common.cloud.DocCollection)3 ValidatingJsonMap (org.apache.solr.common.util.ValidatingJsonMap)3 ByteBuffer (java.nio.ByteBuffer)2