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);
}
}
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"));
}
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);
}
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);
}
}
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"));
}
Aggregations