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