Search in sources :

Example 66 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class TestConfigsApi method testCommands.

public void testCommands() throws Exception {
    ConfigSetsHandler handler = new ConfigSetsHandler(null) {

        @Override
        protected void sendToZk(SolrQueryResponse rsp, ConfigSetOperation operation, Map<String, Object> result) throws KeeperException, InterruptedException {
            result.put(QUEUE_OPERATION, operation.action.toLower());
            rsp.add(ZkNodeProps.class.getName(), new ZkNodeProps(result));
        }
    };
    ApiBag apiBag = new ApiBag(false);
    for (Api api : handler.getApis()) apiBag.register(api, EMPTY_MAP);
    compareOutput(apiBag, "/cluster/configs/sample", DELETE, null, null, "{name :sample, operation:delete}");
    compareOutput(apiBag, "/cluster/configs", POST, "{create:{name : newconf, baseConfigSet: sample }}", null, "{operation:create, name :newconf,  baseConfigSet: sample, immutable: false }");
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) ApiBag(org.apache.solr.api.ApiBag) Api(org.apache.solr.api.Api) Map(java.util.Map)

Example 67 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class DebugComponentTest method ensureRidPresent.

@SuppressWarnings("unchecked")
private void ensureRidPresent(ResponseBuilder rb, String expectedRid) {
    SolrQueryRequest req = rb.req;
    SolrQueryResponse resp = rb.rsp;
    //a generated request ID should be added to the request
    String rid = req.getParams().get(CommonParams.REQUEST_ID);
    if (expectedRid == null) {
        assertTrue(rid + " Doesn't match expected pattern.", Pattern.matches(".*-collection1-[0-9]*-[0-9]+", rid));
    } else {
        assertEquals("Expecting " + expectedRid + " but found " + rid, expectedRid, rid);
    }
    //The request ID is added to the debug/track section
    assertEquals(rid, ((NamedList<Object>) rb.getDebugInfo().get("track")).get(CommonParams.REQUEST_ID));
    //RID must be added to the toLog, so that it's included in the main request log
    assertEquals(rid, resp.getToLog().get(CommonParams.REQUEST_ID));
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse)

Example 68 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class ShowFileRequestHandlerTest method test404Locally.

public void test404Locally() throws Exception {
    // we need to test that executing the handler directly does not 
    // throw an exception, just sets the exception on the response.
    initCore("solrconfig.xml", "schema.xml");
    try {
        // bypass TestHarness since it will throw any exception found in the
        // response.
        SolrCore core = h.getCore();
        SolrQueryResponse rsp = new SolrQueryResponse();
        core.execute(core.getRequestHandler("/admin/file"), req("file", "does-not-exist-404.txt"), rsp);
        assertNotNull("no exception in response", rsp.getException());
        assertTrue("wrong type of exception: " + rsp.getException().getClass(), rsp.getException() instanceof SolrException);
        assertEquals(404, ((SolrException) rsp.getException()).code());
    } catch (Exception e) {
        assertNull("Should not have caught an exception", e);
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrCore(org.apache.solr.core.SolrCore) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException)

Example 69 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class CoreAdminHandlerTest method testNonexistentCoreReload.

@Test
public void testNonexistentCoreReload() throws Exception {
    final CoreAdminHandler admin = new CoreAdminHandler(h.getCoreContainer());
    SolrQueryResponse resp = new SolrQueryResponse();
    try {
        admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.RELOAD.toString(), CoreAdminParams.CORE, "non-existent-core"), resp);
        fail("Was able to successfully reload non-existent-core");
    } catch (Exception e) {
        String e1 = e.getCause().getMessage();
        assertEquals("Expected error message for non-existent core.", "No such core: non-existent-core", e.getCause().getMessage());
    }
    // test null core
    try {
        admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.RELOAD.toString()), resp);
        fail("Was able to successfully reload null core");
    } catch (Exception e) {
        if (!(e instanceof SolrException)) {
            fail("Expected SolrException but got " + e);
        }
        assertEquals("Expected error message for non-existent core.", "Missing required parameter: core", e.getMessage());
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 70 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class CoreAdminHandlerTest method testCreateWithSysVars.

@Test
public void testCreateWithSysVars() throws Exception {
    // I require FS-based indexes for this test.
    useFactory(null);
    final File workDir = createTempDir(getCoreName()).toFile();
    String coreName = "with_sys_vars";
    File instDir = new File(workDir, coreName);
    File subHome = new File(instDir, "conf");
    assertTrue("Failed to make subdirectory ", subHome.mkdirs());
    // Be sure we pick up sysvars when we create this
    String srcDir = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
    FileUtils.copyFile(new File(srcDir, "schema-tiny.xml"), new File(subHome, "schema_ren.xml"));
    FileUtils.copyFile(new File(srcDir, "solrconfig-minimal.xml"), new File(subHome, "solrconfig_ren.xml"));
    FileUtils.copyFile(new File(srcDir, "solrconfig.snippet.randomindexconfig.xml"), new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));
    final CoreContainer cores = h.getCoreContainer();
    final CoreAdminHandler admin = new CoreAdminHandler(cores);
    // create a new core (using CoreAdminHandler) w/ properties
    System.setProperty("INSTDIR_TEST", instDir.getAbsolutePath());
    System.setProperty("CONFIG_TEST", "solrconfig_ren.xml");
    System.setProperty("SCHEMA_TEST", "schema_ren.xml");
    File dataDir = new File(workDir.getAbsolutePath(), "data_diff");
    System.setProperty("DATA_TEST", dataDir.getAbsolutePath());
    SolrQueryResponse resp = new SolrQueryResponse();
    admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.NAME, getCoreName(), CoreAdminParams.INSTANCE_DIR, "${INSTDIR_TEST}", CoreAdminParams.CONFIG, "${CONFIG_TEST}", CoreAdminParams.SCHEMA, "${SCHEMA_TEST}", CoreAdminParams.DATA_DIR, "${DATA_TEST}"), resp);
    assertNull("Exception on create", resp.getException());
    // Now assert that certain values are properly dereferenced in the process of creating the core, see
    // SOLR-4982.
    // Should NOT be a datadir named ${DATA_TEST} (literal). This is the bug after all
    File badDir = new File(instDir, "${DATA_TEST}");
    assertFalse("Should have substituted the sys var, found file " + badDir.getAbsolutePath(), badDir.exists());
    // For the other 3 vars, we couldn't get past creating the core fi dereferencing didn't work correctly.
    // Should have segments in the directory pointed to by the ${DATA_TEST}.
    File test = new File(dataDir, "index");
    assertTrue("Should have found index dir at " + test.getAbsolutePath(), test.exists());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) File(java.io.File) 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