use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class AutoCommitTest method testCommitWithin.
public void testCommitWithin() throws Exception {
SolrCore core = h.getCore();
NewSearcherListener trigger = new NewSearcherListener();
core.registerNewSearcherListener(trigger);
DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
CommitTracker tracker = updater.softCommitTracker;
tracker.setTimeUpperBound(0);
tracker.setDocsUpperBound(-1);
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
// Add a single document with commitWithin == 4 second
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
};
req.setContentStreams(toContentStreams(adoc(4000, "id", "529", "field_t", "what's inside?", "subject", "info"), null));
trigger.reset();
handler.handleRequest(req, rsp);
// Check it isn't in the index
assertQ("shouldn't find any", req("id:529"), "//result[@numFound=0]");
// Wait longer than the commitWithin time
assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
// Add one document without commitWithin
req.setContentStreams(toContentStreams(adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null));
trigger.reset();
handler.handleRequest(req, rsp);
// Check it isn't in the index
assertQ("shouldn't find any", req("id:530"), "//result[@numFound=0]");
// Delete one document with commitWithin
trigger.pause();
req.setContentStreams(toContentStreams(delI("529", "commitWithin", "2000"), null));
trigger.reset();
handler.handleRequest(req, rsp);
// Now make sure we can find it
assertQ("should find one", req("id:529"), "//result[@numFound=1]");
trigger.unpause();
// Wait for the commit to happen
assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
// Now we shouldn't find it
assertQ("should find none", req("id:529"), "//result[@numFound=0]");
// ... but we should find the new one
assertQ("should find one", req("id:530"), "//result[@numFound=1]");
trigger.reset();
// now make the call 10 times really fast and make sure it
// only commits once
req.setContentStreams(toContentStreams(adoc(2000, "id", "500"), null));
for (int i = 0; i < 10; i++) {
handler.handleRequest(req, rsp);
}
assertQ("should not be there yet", req("id:500"), "//result[@numFound=0]");
// the same for the delete
req.setContentStreams(toContentStreams(delI("530", "commitWithin", "1000"), null));
for (int i = 0; i < 10; i++) {
handler.handleRequest(req, rsp);
}
assertQ("should be there", req("id:530"), "//result[@numFound=1]");
assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
assertQ("should be there", req("id:500"), "//result[@numFound=1]");
assertQ("should not be there", req("id:530"), "//result[@numFound=0]");
assertEquals(3, tracker.getCommitCount());
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class AutoCommitTest method testMaxDocs.
public void testMaxDocs() throws Exception {
SolrCore core = h.getCore();
NewSearcherListener trigger = new NewSearcherListener();
DirectUpdateHandler2 updateHandler = (DirectUpdateHandler2) core.getUpdateHandler();
CommitTracker tracker = updateHandler.softCommitTracker;
tracker.setTimeUpperBound(-1);
tracker.setDocsUpperBound(14);
core.registerNewSearcherListener(trigger);
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
// Add documents
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
};
for (int i = 0; i < 14; i++) {
req.setContentStreams(toContentStreams(adoc("id", Integer.toString(i), "subject", "info"), null));
handler.handleRequest(req, rsp);
}
// It should not be there right away
assertQ("shouldn't find any", req("id:1"), "//result[@numFound=0]");
assertEquals(0, tracker.getCommitCount());
req.setContentStreams(toContentStreams(adoc("id", "14", "subject", "info"), null));
handler.handleRequest(req, rsp);
assertTrue(trigger.waitForNewSearcher(15000));
req.setContentStreams(toContentStreams(adoc("id", "15", "subject", "info"), null));
handler.handleRequest(req, rsp);
// Now make sure we can find it
assertQ("should find one", req("id:14"), "//result[@numFound=1]");
assertEquals(1, tracker.getCommitCount());
// But not the one added afterward
assertQ("should not find one", req("id:15"), "//result[@numFound=0]");
assertEquals(1, tracker.getCommitCount());
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class JsonLoaderTest method testSimpleFormat.
public void testSimpleFormat() throws Exception {
String str = "[{'id':'1'},{'id':'2'}]".replace('\'', '"');
SolrQueryRequest req = req("commitWithin", "100", "overwrite", "false");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
assertEquals(2, p.addCommands.size());
AddUpdateCommand add = p.addCommands.get(0);
SolrInputDocument d = add.solrDoc;
SolrInputField f = d.getField("id");
assertEquals("1", f.getValue());
assertEquals(add.commitWithin, 100);
assertEquals(add.overwrite, false);
add = p.addCommands.get(1);
d = add.solrDoc;
f = d.getField("id");
assertEquals("2", f.getValue());
assertEquals(add.commitWithin, 100);
assertEquals(add.overwrite, false);
req.close();
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class JsonLoaderTest method testExtendedFieldValues.
public void testExtendedFieldValues() throws Exception {
String str = "[{'id':'1', 'val_s':{'add':'foo'}}]".replace('\'', '"');
SolrQueryRequest req = req();
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
assertEquals(1, p.addCommands.size());
AddUpdateCommand add = p.addCommands.get(0);
assertEquals(add.commitWithin, -1);
assertEquals(add.overwrite, true);
SolrInputDocument d = add.solrDoc;
SolrInputField f = d.getField("id");
assertEquals("1", f.getValue());
f = d.getField("val_s");
Map<String, Object> map = (Map<String, Object>) f.getValue();
assertEquals("foo", map.get("add"));
req.close();
}
use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.
the class JsonLoaderTest method testGrandChildDocs.
@Test
public void testGrandChildDocs() throws Exception {
String str = "{\n" + " \"add\": {\n" + " \"doc\": {\n" + " \"id\": \"1\",\n" + " \"_childDocuments_\": [\n" + " {\n" + " \"id\": \"2\",\n" + " \"_childDocuments_\": [\n" + " {\n" + " \"id\": \"4\",\n" + " \"foo_s\": \"Baz\"\n" + " }\n" + " ],\n" + " \"foo_s\": \"Yaz\"\n" + " },\n" + " {\n" + " \"id\": \"3\",\n" + " \"foo_s\": \"Bar\"\n" + " }\n" + " ]\n" + " }\n" + " }\n" + "}";
SolrQueryRequest req = req("commit", "true");
SolrQueryResponse rsp = new SolrQueryResponse();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
JsonLoader loader = new JsonLoader();
loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
assertEquals(1, p.addCommands.size());
AddUpdateCommand add = p.addCommands.get(0);
SolrInputDocument one = add.solrDoc;
assertEquals("1", one.getFieldValue("id"));
SolrInputDocument two = one.getChildDocuments().get(0);
assertEquals("2", two.getFieldValue("id"));
assertEquals("Yaz", two.getFieldValue("foo_s"));
SolrInputDocument four = two.getChildDocuments().get(0);
assertEquals("4", four.getFieldValue("id"));
assertEquals("Baz", four.getFieldValue("foo_s"));
SolrInputDocument three = one.getChildDocuments().get(1);
assertEquals("3", three.getFieldValue("id"));
assertEquals("Bar", three.getFieldValue("foo_s"));
req.close();
}
Aggregations