use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class CoreAdminRequestStatusTest method testCoreAdminRequestStatus.
@Test
public void testCoreAdminRequestStatus() throws Exception {
final File workDir = createTempDir().toFile();
final CoreContainer cores = h.getCoreContainer();
final CoreAdminHandler admin = new CoreAdminHandler(cores);
Path instDir;
try (SolrCore template = cores.getCore("collection1")) {
assertNotNull(template);
instDir = template.getCoreDescriptor().getInstanceDir();
}
assertTrue("instDir doesn't exist: " + instDir, Files.exists(instDir));
final File instPropFile = new File(workDir, "instProp");
FileUtils.copyDirectory(instDir.toFile(), instPropFile);
// create a new core (using CoreAdminHandler) w/ properties
SolrQueryResponse resp = new SolrQueryResponse();
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.INSTANCE_DIR, instPropFile.getAbsolutePath(), CoreAdminParams.NAME, "dummycore", CommonAdminParams.ASYNC, "42"), resp);
assertNull("Exception on create", resp.getException());
int maxRetries = 10;
while (maxRetries-- > 0) {
resp = new SolrQueryResponse();
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(), CoreAdminParams.REQUESTID, "42"), resp);
if (resp.getValues().get("STATUS") != null && resp.getValues().get("STATUS").equals("completed"))
break;
Thread.sleep(1000);
}
assertEquals("The status of request was expected to be completed", "completed", resp.getValues().get("STATUS"));
resp = new SolrQueryResponse();
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(), CoreAdminParams.REQUESTID, "9999999"), resp);
assertEquals("Was expecting it to be invalid but found a task with the id.", "notfound", resp.getValues().get("STATUS"));
admin.shutdown();
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class InfoHandlerTest method testCoreAdminHandler.
@Test
public void testCoreAdminHandler() throws Exception {
final CoreContainer cores = h.getCoreContainer();
InfoHandler infoHandler = cores.getInfoHandler();
SolrQueryResponse rsp = handleRequest(infoHandler, "properties");
assertNotNull(rsp.getValues().get("system.properties"));
rsp = handleRequest(infoHandler, "threads");
assertNotNull(rsp.getValues().get("system"));
rsp = handleRequest(infoHandler, "logging");
assertNotNull(rsp.getValues().get("watcher"));
try {
rsp = handleRequest(infoHandler, "info");
fail("Should have failed with not found");
} catch (SolrException e) {
assertEquals(404, e.code());
}
try {
rsp = handleRequest(infoHandler, "");
fail("Should have failed with not found");
} catch (SolrException e) {
assertEquals(404, e.code());
}
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class XmlUpdateRequestHandlerTest method testExternalEntities.
@Test
public void testExternalEntities() throws Exception {
String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
String xml = "<?xml version=\"1.0\"?>" + // check that external entities are not resolved!
"<!DOCTYPE foo [<!ENTITY bar SYSTEM \"" + file + "\">]>" + "<add>" + " &bar;" + " <doc>" + " <field name=\"id\">12345</field>" + " <field name=\"name\">kitten</field>" + " </doc>" + "</add>";
SolrQueryRequest req = req();
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
XMLLoader loader = new XMLLoader().init(null);
loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p);
AddUpdateCommand add = p.addCommands.get(0);
assertEquals("12345", add.solrDoc.getField("id").getFirstValue());
req.close();
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class XmlUpdateRequestHandlerTest method testRequestParams.
@Test
public void testRequestParams() throws Exception {
String xml = "<add>" + " <doc>" + " <field name=\"id\">12345</field>" + " <field name=\"name\">kitten</field>" + " </doc>" + "</add>";
SolrQueryRequest req = req("commitWithin", "100", "overwrite", "false");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
XMLLoader loader = new XMLLoader().init(null);
loader.load(req, rsp, new ContentStreamBase.StringStream(xml), p);
AddUpdateCommand add = p.addCommands.get(0);
assertEquals(100, add.commitWithin);
assertEquals(false, add.overwrite);
req.close();
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class XmlUpdateRequestHandlerTest method testReadDelete.
@Test
public void testReadDelete() throws Exception {
String xml = "<update>" + " <delete>" + " <query>id:150</query>" + " <id>150</id>" + " <id>200</id>" + " <query>id:200</query>" + " </delete>" + " <delete commitWithin=\"500\">" + " <query>id:150</query>" + " </delete>" + " <delete>" + " <id>150</id>" + " </delete>" + " <delete>" + " <id version=\"42\">300</id>" + " </delete>" + " <delete>" + " <id _route_=\"shard1\">400</id>" + " </delete>" + " <delete>" + " <id _route_=\"shard1\" version=\"42\">500</id>" + " </delete>" + "</update>";
MockUpdateRequestProcessor p = new MockUpdateRequestProcessor(null);
p.expectDelete(null, "id:150", -1, 0, null);
p.expectDelete("150", null, -1, 0, null);
p.expectDelete("200", null, -1, 0, null);
p.expectDelete(null, "id:200", -1, 0, null);
p.expectDelete(null, "id:150", 500, 0, null);
p.expectDelete("150", null, -1, 0, null);
p.expectDelete("300", null, -1, 42, null);
p.expectDelete("400", null, -1, 0, "shard1");
p.expectDelete("500", null, -1, 42, "shard1");
XMLLoader loader = new XMLLoader().init(null);
loader.load(req(), new SolrQueryResponse(), new ContentStreamBase.StringStream(xml), p);
p.assertNoCommandsPending();
}
Aggregations