Search in sources :

Example 71 with SolrQueryResponse

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();
}
Also used : Path(java.nio.file.Path) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) File(java.io.File) Test(org.junit.Test)

Example 72 with SolrQueryResponse

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());
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 73 with SolrQueryResponse

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();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) XMLLoader(org.apache.solr.handler.loader.XMLLoader) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 74 with SolrQueryResponse

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();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) XMLLoader(org.apache.solr.handler.loader.XMLLoader) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Example 75 with SolrQueryResponse

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();
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) XMLLoader(org.apache.solr.handler.loader.XMLLoader) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) Test(org.junit.Test)

Aggregations

SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)258 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)128 Test (org.junit.Test)100 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)80 NamedList (org.apache.solr.common.util.NamedList)68 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)58 SolrCore (org.apache.solr.core.SolrCore)52 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)40 SolrException (org.apache.solr.common.SolrException)32 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)29 ArrayList (java.util.ArrayList)26 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)22 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)21 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)20 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)20 JsonLoader (org.apache.solr.handler.loader.JsonLoader)17 IOException (java.io.IOException)16 HashMap (java.util.HashMap)16