use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class DefaultValueUpdateProcessorTest method processAdd.
/**
* Runs a document through the specified chain, and returns the final
* document used when the chain is completed (NOTE: some chains may
* modify the document in place
*/
SolrInputDocument processAdd(final String chain, final SolrInputDocument docIn) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
AddUpdateCommand cmd = new AddUpdateCommand(req);
cmd.solrDoc = docIn;
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
processor.processAdd(cmd);
return cmd.solrDoc;
} finally {
SolrRequestInfo.clearRequestInfo();
req.close();
}
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class XsltUpdateRequestHandlerTest method testUpdate.
@Test
public void testUpdate() throws Exception {
String xml = "<random>" + " <document>" + " <node name=\"id\" value=\"12345\"/>" + " <node name=\"name\" value=\"kitten\"/>" + " <node name=\"text\" enhance=\"3\" value=\"some other day\"/>" + " <node name=\"title\" enhance=\"4\" value=\"A story\"/>" + " <node name=\"timestamp\" enhance=\"5\" value=\"2011-07-01T10:31:57.140Z\"/>" + " </document>" + "</random>";
Map<String, String> args = new HashMap<>();
args.put(CommonParams.TR, "xsl-update-handler-test.xsl");
SolrCore core = h.getCore();
LocalSolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
ArrayList<ContentStream> streams = new ArrayList<>();
streams.add(new ContentStreamBase.StringStream(xml));
req.setContentStreams(streams);
SolrQueryResponse rsp = new SolrQueryResponse();
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(new NamedList<String>());
handler.handleRequestBody(req, rsp);
StringWriter sw = new StringWriter(32000);
QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
responseWriter.write(sw, req, rsp);
req.close();
String response = sw.toString();
assertU(response);
assertU(commit());
assertQ("test document was correctly committed", req("q", "*:*"), "//result[@numFound='1']", "//int[@name='id'][.='12345']");
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class MBeansHandlerTest method testDiff.
@Test
public void testDiff() throws Exception {
String xml = h.query(req(CommonParams.QT, "/admin/mbeans", "stats", "true", CommonParams.WT, "xml"));
List<ContentStream> streams = new ArrayList<>();
streams.add(new ContentStreamBase.StringStream(xml));
LocalSolrQueryRequest req = lrf.makeRequest(CommonParams.QT, "/admin/mbeans", "stats", "true", CommonParams.WT, "xml", "diff", "true");
req.setContentStreams(streams);
xml = h.query(req);
NamedList<NamedList<NamedList<Object>>> diff = SolrInfoMBeanHandler.fromXML(xml);
// The stats bean for SolrInfoMBeanHandler
NamedList stats = (NamedList) diff.get("ADMIN").get("/admin/mbeans").get("stats");
//System.out.println("stats:"+stats);
Pattern p = Pattern.compile("Was: (?<was>[0-9]+), Now: (?<now>[0-9]+), Delta: (?<delta>[0-9]+)");
String response = stats.get("ADMIN./admin/mbeans.requests").toString();
Matcher m = p.matcher(response);
if (!m.matches()) {
fail("Response did not match pattern: " + response);
}
assertEquals(1, Integer.parseInt(m.group("delta")));
int was = Integer.parseInt(m.group("was"));
int now = Integer.parseInt(m.group("now"));
assertEquals(1, now - was);
xml = h.query(req(CommonParams.QT, "/admin/mbeans", "stats", "true", "key", "org.apache.solr.handler.admin.CollectionsHandler"));
NamedList<NamedList<NamedList<Object>>> nl = SolrInfoMBeanHandler.fromXML(xml);
assertNotNull(nl.get("ADMIN").get("org.apache.solr.handler.admin.CollectionsHandler"));
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class SolrIndexSplitterTest method testSplitByPaths.
@Test
public void testSplitByPaths() throws Exception {
LocalSolrQueryRequest request = null;
try {
// add two docs
String id1 = "dorothy";
assertU(adoc("id", id1));
String id2 = "kansas";
assertU(adoc("id", id2));
assertU(commit());
assertJQ(req("q", "*:*"), "/response/numFound==2");
// find minHash/maxHash hash ranges
List<DocRouter.Range> ranges = getRanges(id1, id2);
request = lrf.makeRequest("q", "dummy");
SplitIndexCommand command = new SplitIndexCommand(request, Lists.newArrayList(indexDir1.getAbsolutePath(), indexDir2.getAbsolutePath()), null, ranges, new PlainIdRouter(), null, null);
new SolrIndexSplitter(command).split();
Directory directory = h.getCore().getDirectoryFactory().get(indexDir1.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
DirectoryReader reader = DirectoryReader.open(directory);
assertEquals("id:dorothy should be present in split index1", 1, reader.docFreq(new Term("id", "dorothy")));
assertEquals("id:kansas should not be present in split index1", 0, reader.docFreq(new Term("id", "kansas")));
assertEquals("split index1 should have only one document", 1, reader.numDocs());
reader.close();
h.getCore().getDirectoryFactory().release(directory);
directory = h.getCore().getDirectoryFactory().get(indexDir2.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
reader = DirectoryReader.open(directory);
assertEquals("id:dorothy should not be present in split index2", 0, reader.docFreq(new Term("id", "dorothy")));
assertEquals("id:kansas should be present in split index2", 1, reader.docFreq(new Term("id", "kansas")));
assertEquals("split index2 should have only one document", 1, reader.numDocs());
reader.close();
h.getCore().getDirectoryFactory().release(directory);
} finally {
// decrefs the searcher
if (request != null)
request.close();
}
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class SolrIndexSplitterTest method testSplitAlternately.
@Test
public void testSplitAlternately() throws Exception {
LocalSolrQueryRequest request = null;
Directory directory = null;
try {
// add an even number of docs
int max = (1 + random().nextInt(10)) * 3;
log.info("Adding {} number of documents", max);
for (int i = 0; i < max; i++) {
assertU(adoc("id", String.valueOf(i)));
}
assertU(commit());
request = lrf.makeRequest("q", "dummy");
SplitIndexCommand command = new SplitIndexCommand(request, Lists.newArrayList(indexDir1.getAbsolutePath(), indexDir2.getAbsolutePath(), indexDir3.getAbsolutePath()), null, null, new PlainIdRouter(), null, null);
new SolrIndexSplitter(command).split();
directory = h.getCore().getDirectoryFactory().get(indexDir1.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
DirectoryReader reader = DirectoryReader.open(directory);
assertEquals("split index1 has wrong number of documents", max / 3, reader.numDocs());
reader.close();
h.getCore().getDirectoryFactory().release(directory);
directory = h.getCore().getDirectoryFactory().get(indexDir2.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
reader = DirectoryReader.open(directory);
assertEquals("split index2 has wrong number of documents", max / 3, reader.numDocs());
reader.close();
h.getCore().getDirectoryFactory().release(directory);
directory = h.getCore().getDirectoryFactory().get(indexDir3.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
reader = DirectoryReader.open(directory);
assertEquals("split index3 has wrong number of documents", max / 3, reader.numDocs());
reader.close();
h.getCore().getDirectoryFactory().release(directory);
directory = null;
} finally {
// decrefs the searcher
if (request != null)
request.close();
if (directory != null) {
// perhaps an assert failed, release the directory
h.getCore().getDirectoryFactory().release(directory);
}
}
}
Aggregations