Search in sources :

Example 21 with RestTestHarness

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

the class TestNamedUpdateProcessors 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 22 with RestTestHarness

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

the class TestSolrConfigHandler method testUserProp.

public void testUserProp() throws Exception {
    RestTestHarness harness = restTestHarness;
    String payload = "{\n" + " 'set-user-property' : { 'my.custom.variable.a':'MODIFIEDA'," + " 'my.custom.variable.b':'MODIFIEDB' } \n" + " }";
    runConfigCommand(harness, "/config?wt=json", payload);
    Map m = (Map) getRespMap("/config/overlay?wt=json", harness).get("overlay");
    Map props = (Map) m.get("userProps");
    assertNotNull(props);
    assertEquals(props.get("my.custom.variable.a"), "MODIFIEDA");
    assertEquals(props.get("my.custom.variable.b"), "MODIFIEDB");
    m = (Map) getRespMap("/dump?wt=json&json.nl=map&initArgs=true", harness).get("initArgs");
    m = (Map) m.get(PluginInfo.DEFAULTS);
    assertEquals("MODIFIEDA", m.get("a"));
    assertEquals("MODIFIEDB", m.get("b"));
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString) HashMap(java.util.HashMap) Map(java.util.Map) ValidatingJsonMap(org.apache.solr.common.util.ValidatingJsonMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 23 with RestTestHarness

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

the class TestSolrConfigHandler method testReqParams.

public void testReqParams() throws Exception {
    RestTestHarness harness = restTestHarness;
    String payload = " {\n" + "  'set' : {'x': {" + "                    'a':'A val',\n" + "                    'b': 'B val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(harness, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/params?wt=json", null, Arrays.asList("response", "params", "x", "a"), "A val", 10);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/params?wt=json", null, Arrays.asList("response", "params", "x", "b"), "B val", 10);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/d', registerPath :'/solr,/v2' , 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(harness, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "/d", "name"), "/d", 10);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/d?wt=json&useParams=x", null, Arrays.asList("params", "a"), "A val", 5);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/d?wt=json&useParams=x&a=fomrequest", null, Arrays.asList("params", "a"), "fomrequest", 5);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/dump1', registerPath :'/solr,/v2' , 'class': 'org.apache.solr.handler.DumpRequestHandler', 'useParams':'x' }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(harness, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "/dump1", "name"), "/dump1", 10);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/dump1?wt=json", null, Arrays.asList("params", "a"), "A val", 5);
    payload = " {\n" + "  'set' : {'y':{\n" + "                'c':'CY val',\n" + "                'b': 'BY val', " + "                'd': ['val 1', 'val 2']}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(harness, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/params?wt=json", null, Arrays.asList("response", "params", "y", "c"), "CY val", 10);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/dump1?wt=json&useParams=y", null, Arrays.asList("params", "c"), "CY val", 5);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/dump1?wt=json&useParams=y", null, Arrays.asList("params", "b"), "BY val", 5);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/dump1?wt=json&useParams=y", null, Arrays.asList("params", "a"), "A val", 5);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/dump1?wt=json&useParams=y", null, Arrays.asList("params", "d"), Arrays.asList("val 1", "val 2"), 5);
    payload = " {\n" + "  'update' : {'y': {\n" + "                'c':'CY val modified',\n" + "                'e':'EY val',\n" + "                'b': 'BY val'" + "}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(harness, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/params?wt=json", null, Arrays.asList("response", "params", "y", "c"), "CY val modified", 10);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/params?wt=json", null, Arrays.asList("response", "params", "y", "e"), "EY val", 10);
    payload = " {\n" + "  'set' : {'y': {\n" + "                'p':'P val',\n" + "                'q': 'Q val'" + "}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(harness, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/params?wt=json", null, Arrays.asList("response", "params", "y", "p"), "P val", 10);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/params?wt=json", null, Arrays.asList("response", "params", "y", "c"), null, 10);
    payload = " {'delete' : 'y'}";
    TestSolrConfigHandler.runConfigCommand(harness, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/params?wt=json", null, Arrays.asList("response", "params", "y", "p"), null, 10);
    payload = "{\n" + "  'create-requesthandler': {\n" + "    'name': 'aRequestHandler',\n" + "    'registerPath': '/v2',\n" + "    'class': 'org.apache.solr.handler.DumpRequestHandler',\n" + "    'spec': {\n" + "      'methods': [\n" + "        'GET',\n" + "        'POST'\n" + "      ],\n" + "      'url': {\n" + "        'paths': [\n" + "          '/something/{part1}/fixed/{part2}'\n" + "        ]\n" + "      }\n" + "    }\n" + "  }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(harness, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(harness, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "requestHandler", "aRequestHandler", "class"), "org.apache.solr.handler.DumpRequestHandler", 10);
    RESTfulServerProvider oldProvider = restTestHarness.getServerProvider();
    restTestHarness.setServerProvider(() -> jetty.getBaseUrl().toString() + "/____v2/cores/" + DEFAULT_TEST_CORENAME);
    Map rsp = TestSolrConfigHandler.testForResponseElement(harness, null, "/something/part1_Value/fixed/part2_Value?urlTemplateValues=part1&urlTemplateValues=part2", null, Arrays.asList("urlTemplateValues"), new ValidatingJsonMap.PredicateWithErrMsg() {

        @Override
        public String test(Object o) {
            if (o instanceof Map) {
                Map m = (Map) o;
                if ("part1_Value".equals(m.get("part1")) && "part2_Value".equals(m.get("part2")))
                    return null;
            }
            return "no match";
        }

        @Override
        public String toString() {
            return "{part1:part1_Value, part2 : part2_Value]";
        }
    }, 10);
    restTestHarness.setServerProvider(oldProvider);
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) ValidatingJsonMap(org.apache.solr.common.util.ValidatingJsonMap) RESTfulServerProvider(org.apache.solr.util.RESTfulServerProvider) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString) HashMap(java.util.HashMap) Map(java.util.Map) ValidatingJsonMap(org.apache.solr.common.util.ValidatingJsonMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 24 with RestTestHarness

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

the class TestCustomStream 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) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient)

Example 25 with RestTestHarness

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

the class TestNamedUpdateProcessors method test.

@Test
public void test() throws Exception {
    System.setProperty("enable.runtime.lib", "true");
    setupHarnesses();
    String blobName = "colltest";
    HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
    String baseURL = randomClient.getBaseURL();
    final String solrClientUrl = baseURL.substring(0, baseURL.lastIndexOf('/'));
    TestBlobHandler.createSystemCollection(getHttpSolrClient(solrClientUrl, randomClient.getHttpClient()));
    waitForRecoveriesToFinish(".system", true);
    TestBlobHandler.postAndCheck(cloudClient, baseURL.substring(0, baseURL.lastIndexOf('/')), blobName, TestDynamicLoading.generateZip(RuntimeUrp.class), 1);
    String payload = "{\n" + "'add-runtimelib' : { 'name' : 'colltest' ,'version':1}\n" + "}";
    RestTestHarness client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(client, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "runtimeLib", blobName, "version"), 1l, 10);
    payload = "{\n" + "'create-updateprocessor' : { 'name' : 'firstFld', 'class': 'solr.FirstFieldValueUpdateProcessorFactory', 'fieldName':'test_s'}, \n" + "'create-updateprocessor' : { 'name' : 'test', 'class': 'org.apache.solr.update.processor.RuntimeUrp', 'runtimeLib':true }, \n" + "'create-updateprocessor' : { 'name' : 'maxFld', 'class': 'solr.MaxFieldValueUpdateProcessorFactory', 'fieldName':'mul_s'} \n" + "}";
    client = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    TestSolrConfigHandler.runConfigCommand(client, "/config?wt=json", payload);
    for (RestTestHarness restTestHarness : restTestHarnesses) {
        TestSolrConfigHandler.testForResponseElement(restTestHarness, null, "/config/overlay?wt=json", null, Arrays.asList("overlay", "updateProcessor", "firstFld", "fieldName"), "test_s", 10);
    }
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "123");
    doc.addField("test_s", Arrays.asList("one", "two"));
    doc.addField("mul_s", Arrays.asList("aaa", "bbb"));
    randomClient.add(doc);
    randomClient.commit(true, true);
    QueryResponse result = randomClient.query(new SolrQuery("id:123"));
    assertEquals(2, ((Collection) result.getResults().get(0).getFieldValues("test_s")).size());
    assertEquals(2, ((Collection) result.getResults().get(0).getFieldValues("mul_s")).size());
    doc = new SolrInputDocument();
    doc.addField("id", "456");
    doc.addField("test_s", Arrays.asList("three", "four"));
    doc.addField("mul_s", Arrays.asList("aaa", "bbb"));
    UpdateRequest ur = new UpdateRequest();
    ur.add(doc).setParam("processor", "firstFld,maxFld,test");
    randomClient.request(ur);
    randomClient.commit(true, true);
    result = randomClient.query(new SolrQuery("id:456"));
    SolrDocument d = result.getResults().get(0);
    assertEquals(1, d.getFieldValues("test_s").size());
    assertEquals(1, d.getFieldValues("mul_s").size());
    assertEquals("three", d.getFieldValues("test_s").iterator().next());
    assertEquals("bbb", d.getFieldValues("mul_s").iterator().next());
    String processors = (String) d.getFirstValue("processors_s");
    assertNotNull(processors);
    assertEquals(StrUtils.splitSmart(processors, '>'), Arrays.asList("FirstFieldValueUpdateProcessorFactory", "MaxFieldValueUpdateProcessorFactory", "RuntimeUrp", "LogUpdateProcessorFactory", "DistributedUpdateProcessorFactory", "RunUpdateProcessorFactory"));
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) RestTestHarness(org.apache.solr.util.RestTestHarness) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

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