use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class TestIndexSearcher method testDontUseColdSearcher.
public void testDontUseColdSearcher() throws Exception {
MockSearchComponent.registerFirstSearcherListener = false;
MockSearchComponent.registerNewSearcherListener = false;
MockSearchComponent.registerSlowSearcherListener = true;
final AtomicBoolean querySucceeded = new AtomicBoolean(false);
SlowSearcherListener.numberOfTimesCalled = new AtomicInteger(0);
SlowSearcherListener.latch = new CountDownLatch(1);
CoreContainer cores = h.getCoreContainer();
CoreDescriptor cd = h.getCore().getCoreDescriptor();
final SolrCore newCore;
boolean coreCreated = false;
try {
// Create a new core, this should call all the firstSearcherListeners
newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
coreCreated = true;
//validate that the new core was created with the correct solrconfig
assertNotNull(newCore.getSearchComponent("mock"));
assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
assertFalse(newCore.getSolrConfig().useColdSearcher);
Thread t = new Thread() {
public void run() {
try {
doQuery(newCore);
querySucceeded.set(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
;
};
t.start();
if (System.getProperty(SYSPROP_NIGHTLY) != null) {
// even if we wait here, the SearcherListener should not finish
Thread.sleep(500);
}
// validate that the searcher warmer didn't finish yet.
assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
assertFalse("Query should be waiting for warming to finish", querySucceeded.get());
// Let warmer finish
SlowSearcherListener.latch.countDown();
// Validate that the query eventually succeeds
for (int i = 0; i <= 1000; i++) {
if (querySucceeded.get()) {
break;
}
if (i == 1000) {
fail("Query didn't succeed after 10 secoonds");
}
Thread.sleep(10);
}
} finally {
if (coreCreated) {
cores.unload("core1");
}
}
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class DocumentBuilderTest method testExceptions.
@Test
public void testExceptions() {
SolrCore core = h.getCore();
// make sure a null value is not indexed
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "123");
doc.addField("unknown", "something");
try {
DocumentBuilder.toDocument(doc, core.getLatestSchema());
fail("added an unknown field");
} catch (Exception ex) {
assertTrue("should have document ID", ex.getMessage().indexOf("doc=123") > 0);
}
doc.remove("unknown");
doc.addField("weight", "not a number");
try {
DocumentBuilder.toDocument(doc, core.getLatestSchema());
fail("invalid 'float' field value");
} catch (Exception ex) {
assertTrue("should have document ID", ex.getMessage().indexOf("doc=123") > 0);
assertTrue("cause is number format", ex.getCause() instanceof NumberFormatException);
}
// now make sure it is OK
doc.setField("weight", "1.34");
DocumentBuilder.toDocument(doc, core.getLatestSchema());
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class HardAutoCommitTest 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.commitTracker;
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 == 2 second
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
};
req.setContentStreams(AutoCommitTest.toContentStreams(adoc(2000, "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(AutoCommitTest.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(AutoCommitTest.toContentStreams(delI("529", "commitWithin", "1000"), 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(AutoCommitTest.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(AutoCommitTest.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.core.SolrCore in project lucene-solr by apache.
the class AutoCommitTest method testMaxTime.
public void testMaxTime() throws Exception {
SolrCore core = h.getCore();
NewSearcherListener trigger = new NewSearcherListener();
core.registerNewSearcherListener(trigger);
DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
CommitTracker tracker = updater.softCommitTracker;
// too low of a number can cause a slow host to commit before the test code checks that it
// isn't there... causing a failure at "shouldn't find any"
tracker.setTimeUpperBound(1500);
tracker.setDocsUpperBound(-1);
// updater.commitCallbacks.add(trigger);
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
// Add a single document
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
};
req.setContentStreams(toContentStreams(adoc("id", "529", "field_t", "what's inside?", "subject", "info"), null));
trigger.reset();
handler.handleRequest(req, rsp);
// Check it it is in the index
assertQ("shouldn't find any", req("id:529"), "//result[@numFound=0]");
// Wait longer than the autocommit time
assertTrue(trigger.waitForNewSearcher(45000));
trigger.reset();
req.setContentStreams(toContentStreams(adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null));
handler.handleRequest(req, rsp);
// Now make sure we can find it
assertQ("should find one", req("id:529"), "//result[@numFound=1]");
// But not this one
assertQ("should find none", req("id:530"), "//result[@numFound=0]");
// Delete the document
assertU(delI("529"));
assertQ("deleted, but should still be there", req("id:529"), "//result[@numFound=1]");
// Wait longer than the autocommit time
assertTrue(trigger.waitForNewSearcher(30000));
trigger.reset();
req.setContentStreams(toContentStreams(adoc("id", "550", "field_t", "what's inside?", "subject", "info"), null));
handler.handleRequest(req, rsp);
assertEquals(2, tracker.getCommitCount());
assertQ("deleted and time has passed", req("id:529"), "//result[@numFound=0]");
// now make the call 10 times really fast and make sure it
// only commits once
req.setContentStreams(toContentStreams(adoc("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]");
// Wait longer than the autocommit time
assertTrue(trigger.waitForNewSearcher(45000));
trigger.reset();
req.setContentStreams(toContentStreams(adoc("id", "531", "field_t", "what's inside?", "subject", "info"), null));
handler.handleRequest(req, rsp);
assertEquals(3, tracker.getCommitCount());
assertQ("now it should", req("id:500"), "//result[@numFound=1]");
}
use of org.apache.solr.core.SolrCore 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());
}
Aggregations