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