Search in sources :

Example 16 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class TestCoreContainer method testCoreInitFailuresFromEmptyContainer.

@Test
public void testCoreInitFailuresFromEmptyContainer() throws Exception {
    // reused state
    Map<String, CoreContainer.CoreLoadFailure> failures = null;
    Collection<String> cores = null;
    Exception fail = null;
    // ----
    // init the CoreContainer
    CoreContainer cc = init(CONFIGSETS_SOLR_XML);
    // check that we have the cores we expect
    cores = cc.getLoadedCoreNames();
    assertNotNull("core names is null", cores);
    assertEquals("wrong number of cores", 0, cores.size());
    // check that we have the failures we expect
    failures = cc.getCoreInitFailures();
    assertNotNull("core failures is a null map", failures);
    assertEquals("wrong number of core failures", 0, failures.size());
    // try to add a collection with a configset that doesn't exist
    try {
        ignoreException(Pattern.quote("bogus_path"));
        cc.create("bogus", ImmutableMap.of("configSet", "bogus_path"));
        fail("bogus inst dir failed to trigger exception from create");
    } catch (SolrException e) {
        Throwable cause = Throwables.getRootCause(e);
        assertTrue("init exception doesn't mention bogus dir: " + cause.getMessage(), 0 < cause.getMessage().indexOf("bogus_path"));
    }
    // check that we have the cores we expect
    cores = cc.getLoadedCoreNames();
    assertNotNull("core names is null", cores);
    assertEquals("wrong number of cores", 0, cores.size());
    // check that we have the failures we expect
    failures = cc.getCoreInitFailures();
    assertNotNull("core failures is a null map", failures);
    assertEquals("wrong number of core failures", 1, failures.size());
    fail = failures.get("bogus").exception;
    assertNotNull("null failure for test core", fail);
    assertTrue("init failure doesn't mention problem: " + fail.getMessage(), 0 < fail.getMessage().indexOf("bogus_path"));
    // check that we get null accessing a non-existent core
    assertNull(cc.getCore("does_not_exist"));
    // check that we get a 500 accessing the core with an init failure
    try {
        SolrCore c = cc.getCore("bogus");
        fail("Failed to get Exception on accessing core with init failure");
    } catch (SolrException ex) {
        assertEquals(500, ex.code());
        String cause = Throwables.getRootCause(ex).getMessage();
        assertTrue("getCore() ex cause doesn't mention init fail: " + cause, 0 < cause.indexOf("bogus_path"));
    }
    cc.shutdown();
}
Also used : JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) SolrException(org.apache.solr.common.SolrException) SAXParseException(org.xml.sax.SAXParseException) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 17 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class DistributedFacetExistsSmallTest method checkInvalidMincount.

private void checkInvalidMincount() throws SolrServerException, IOException {
    final ModifiableSolrParams params = buildParams();
    if (random().nextBoolean()) {
        params.remove("facet.exists");
        params.set("f." + FLD + ".facet.exists", "true");
    }
    if (random().nextBoolean()) {
        params.set("facet.mincount", "" + (2 + random().nextInt(100)));
    } else {
        params.set("f." + FLD + ".facet.mincount", "" + (2 + random().nextInt(100)));
    }
    try {
        if (random().nextBoolean()) {
            setDistributedParams(params);
            queryServer(params);
        } else {
            params.set("distrib", "false");
            controlClient.query(params);
        }
        fail();
    } catch (SolrException e) {
        // check that distr and single index search fail the same
        assertEquals(e.code(), ErrorCode.BAD_REQUEST.code);
        assertTrue(e.getMessage().contains("facet.exists"));
        assertTrue(e.getMessage().contains("facet.mincount"));
        assertTrue(e.getMessage().contains(FLD));
    }
}
Also used : ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 18 with SolrException

use of org.apache.solr.common.SolrException 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 19 with SolrException

use of org.apache.solr.common.SolrException 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 20 with SolrException

use of org.apache.solr.common.SolrException 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)

Aggregations

SolrException (org.apache.solr.common.SolrException)616 IOException (java.io.IOException)171 ArrayList (java.util.ArrayList)100 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)80 NamedList (org.apache.solr.common.util.NamedList)79 HashMap (java.util.HashMap)75 Map (java.util.Map)70 SolrParams (org.apache.solr.common.params.SolrParams)64 KeeperException (org.apache.zookeeper.KeeperException)60 Test (org.junit.Test)55 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)45 DocCollection (org.apache.solr.common.cloud.DocCollection)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)39 SchemaField (org.apache.solr.schema.SchemaField)39 List (java.util.List)38 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)36 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 SolrCore (org.apache.solr.core.SolrCore)33