try to harden this test more

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1159649 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2011-08-19 14:38:50 +00:00
parent 8887431241
commit a4ec6c4177
1 changed files with 71 additions and 22 deletions

View File

@ -31,10 +31,24 @@ import org.apache.solr.handler.XmlUpdateRequestHandler;
import org.apache.solr.request.SolrQueryRequestBase; import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.update.NewSearcherListener.TriggerOn;
import org.apache.solr.util.AbstractSolrTestCase; import org.apache.solr.util.AbstractSolrTestCase;
class NewSearcherListener implements SolrEventListener { class NewSearcherListener implements SolrEventListener {
enum TriggerOn {Both, Soft, Hard}
private volatile boolean triggered = false; private volatile boolean triggered = false;
private volatile TriggerOn lastType;
private volatile TriggerOn triggerOnType;
public NewSearcherListener() {
this(TriggerOn.Both);
}
public NewSearcherListener(TriggerOn type) {
this.triggerOnType = type;
}
@Override @Override
public void init(NamedList args) {} public void init(NamedList args) {}
@ -42,14 +56,24 @@ class NewSearcherListener implements SolrEventListener {
@Override @Override
public void newSearcher(SolrIndexSearcher newSearcher, public void newSearcher(SolrIndexSearcher newSearcher,
SolrIndexSearcher currentSearcher) { SolrIndexSearcher currentSearcher) {
if (triggerOnType == TriggerOn.Soft && lastType == TriggerOn.Soft) {
triggered = true; triggered = true;
} else if (triggerOnType == TriggerOn.Hard && lastType == TriggerOn.Hard) {
triggered = true;
} else if (triggerOnType == TriggerOn.Both) {
triggered = true;
}
} }
@Override @Override
public void postCommit() {} public void postCommit() {
lastType = TriggerOn.Hard;
}
@Override @Override
public void postSoftCommit() {} public void postSoftCommit() {
lastType = TriggerOn.Soft;
}
public void reset() { public void reset() {
triggered = false; triggered = false;
@ -217,20 +241,26 @@ public class AutoCommitTest extends AbstractSolrTestCase {
public void testSoftCommitMaxDocs() throws Exception { public void testSoftCommitMaxDocs() throws Exception {
SolrCore core = h.getCore(); SolrCore core = h.getCore();
NewSearcherListener trigger = new NewSearcherListener(); NewSearcherListener trigger = new NewSearcherListener(TriggerOn.Hard);
core.registerNewSearcherListener(trigger);
DirectUpdateHandler2 updateHandler = (DirectUpdateHandler2)core.getUpdateHandler(); DirectUpdateHandler2 updateHandler = (DirectUpdateHandler2)core.getUpdateHandler();
updateHandler.registerCommitCallback(trigger);
CommitTracker tracker = updateHandler.commitTracker; CommitTracker tracker = updateHandler.commitTracker;
tracker.setTimeUpperBound(-1); tracker.setTimeUpperBound(-1);
tracker.setDocsUpperBound(8); tracker.setDocsUpperBound(8);
NewSearcherListener softTrigger = new NewSearcherListener(); NewSearcherListener softTrigger = new NewSearcherListener(TriggerOn.Soft);
updateHandler.registerSoftCommitCallback(softTrigger);
core.registerNewSearcherListener(softTrigger);
CommitTracker softTracker = updateHandler.softCommitTracker; CommitTracker softTracker = updateHandler.softCommitTracker;
softTracker.setTimeUpperBound(-1); softTracker.setTimeUpperBound(-1);
softTracker.setDocsUpperBound(4); softTracker.setDocsUpperBound(4);
core.registerNewSearcherListener(softTrigger);
XmlUpdateRequestHandler handler = new XmlUpdateRequestHandler(); XmlUpdateRequestHandler handler = new XmlUpdateRequestHandler();
handler.init( null ); handler.init( null );
@ -254,8 +284,7 @@ public class AutoCommitTest extends AbstractSolrTestCase {
handler.handleRequest( req, rsp ); handler.handleRequest( req, rsp );
assertTrue(softTrigger.waitForNewSearcher(10000)); assertTrue(softTrigger.waitForNewSearcher(10000));
softTrigger.reset();
core.registerNewSearcherListener(trigger);
assertQ("should find 5", req("*:*") ,"//result[@numFound=5]" ); assertQ("should find 5", req("*:*") ,"//result[@numFound=5]" );
assertEquals( 1, softTracker.getCommitCount()); assertEquals( 1, softTracker.getCommitCount());
@ -279,6 +308,8 @@ public class AutoCommitTest extends AbstractSolrTestCase {
} }
req.close(); req.close();
assertTrue(softTrigger.waitForNewSearcher(10000));
softTrigger.reset();
assertTrue(trigger.waitForNewSearcher(10000)); assertTrue(trigger.waitForNewSearcher(10000));
assertQ("should find 10", req("*:*") ,"//result[@numFound=10]" ); assertQ("should find 10", req("*:*") ,"//result[@numFound=10]" );
@ -365,17 +396,25 @@ public class AutoCommitTest extends AbstractSolrTestCase {
public void testSoftAndHardCommitMaxTime() throws Exception { public void testSoftAndHardCommitMaxTime() throws Exception {
SolrCore core = h.getCore(); SolrCore core = h.getCore();
NewSearcherListener trigger = new NewSearcherListener(); NewSearcherListener softTrigger = new NewSearcherListener(TriggerOn.Soft);
core.registerNewSearcherListener(trigger); NewSearcherListener hardTrigger = new NewSearcherListener(TriggerOn.Hard);
core.registerNewSearcherListener(softTrigger);
core.registerNewSearcherListener(hardTrigger);
DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler(); DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
updater.registerCommitCallback(softTrigger);
updater.registerSoftCommitCallback(softTrigger);
updater.registerCommitCallback(hardTrigger);
updater.registerSoftCommitCallback(hardTrigger);
CommitTracker hardTracker = updater.commitTracker; CommitTracker hardTracker = updater.commitTracker;
CommitTracker softTracker = updater.softCommitTracker; CommitTracker softTracker = updater.softCommitTracker;
// too low of a number can cause a slow host to commit before the test code checks that it // 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" // isn't there... causing a failure at "shouldn't find any"
softTracker.setTimeUpperBound(100); softTracker.setTimeUpperBound(300);
softTracker.setDocsUpperBound(-1); softTracker.setDocsUpperBound(-1);
hardTracker.setTimeUpperBound(500); hardTracker.setTimeUpperBound(1200);
hardTracker.setDocsUpperBound(-1); hardTracker.setDocsUpperBound(-1);
// updater.commitCallbacks.add(trigger); // updater.commitCallbacks.add(trigger);
@ -389,15 +428,15 @@ public class AutoCommitTest extends AbstractSolrTestCase {
SolrQueryRequestBase req = new SolrQueryRequestBase( core, params ) {}; SolrQueryRequestBase req = new SolrQueryRequestBase( core, params ) {};
req.setContentStreams( toContentStreams( req.setContentStreams( toContentStreams(
adoc("id", "529", "field_t", "what's inside?", "subject", "info"), null ) ); adoc("id", "529", "field_t", "what's inside?", "subject", "info"), null ) );
trigger.reset();
handler.handleRequest( req, rsp ); handler.handleRequest( req, rsp );
// Check if it is in the index // Check if it is in the index
assertQ("shouldn't find any", req("id:529") ,"//result[@numFound=0]" ); assertQ("shouldn't find any", req("id:529") ,"//result[@numFound=0]" );
// Wait longer than the autocommit time // Wait longer than the autocommit time
assertTrue(trigger.waitForNewSearcher(30000)); assertTrue(softTrigger.waitForNewSearcher(30000));
trigger.reset(); softTrigger.reset();
req.setContentStreams( toContentStreams( req.setContentStreams( toContentStreams(
adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null ) ); adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null ) );
handler.handleRequest( req, rsp ); handler.handleRequest( req, rsp );
@ -410,9 +449,12 @@ public class AutoCommitTest extends AbstractSolrTestCase {
// Delete the document // Delete the document
assertU( delI("529") ); assertU( delI("529") );
assertQ("deleted, but should still be there", req("id:529") ,"//result[@numFound=1]" ); assertQ("deleted, but should still be there", req("id:529") ,"//result[@numFound=1]" );
// Wait longer than the autocommit time
assertTrue(trigger.waitForNewSearcher(15000)); // Wait longer than the autocommit time - wait twice to ensure latest is picked up
trigger.reset(); assertTrue(softTrigger.waitForNewSearcher(15000));
softTrigger.reset();
req.setContentStreams( toContentStreams( req.setContentStreams( toContentStreams(
adoc("id", "550", "field_t", "what's inside?", "subject", "info"), null ) ); adoc("id", "550", "field_t", "what's inside?", "subject", "info"), null ) );
handler.handleRequest( req, rsp ); handler.handleRequest( req, rsp );
@ -430,8 +472,8 @@ public class AutoCommitTest extends AbstractSolrTestCase {
assertQ("should not be there yet", req("id:500") ,"//result[@numFound=0]" ); assertQ("should not be there yet", req("id:500") ,"//result[@numFound=0]" );
// Wait longer than the autocommit time // Wait longer than the autocommit time
assertTrue(trigger.waitForNewSearcher(15000)); assertTrue(softTrigger.waitForNewSearcher(15000));
trigger.reset(); softTrigger.reset();
req.setContentStreams( toContentStreams( req.setContentStreams( toContentStreams(
adoc("id", "531", "field_t", "what's inside?", "subject", "info"), null ) ); adoc("id", "531", "field_t", "what's inside?", "subject", "info"), null ) );
@ -441,12 +483,19 @@ public class AutoCommitTest extends AbstractSolrTestCase {
int softCommitCnt = softTracker.getCommitCount(); int softCommitCnt = softTracker.getCommitCount();
assertTrue("commit cnt:" + softCommitCnt, softCommitCnt == 2 assertTrue("commit cnt:" + softCommitCnt, softCommitCnt == 2
|| softCommitCnt == 3); || softCommitCnt == 3);
// depending on timing, you might see 1 or 2 hard commits // depending on timing, you might see 1 or 2 hard commits
assertTrue(hardTrigger.waitForNewSearcher(15000));
hardTrigger.reset();
int hardCommitCnt = hardTracker.getCommitCount(); int hardCommitCnt = hardTracker.getCommitCount();
assertTrue("commit cnt:" + hardCommitCnt, hardCommitCnt == 1 assertTrue("commit cnt:" + hardCommitCnt, hardCommitCnt == 1
|| hardCommitCnt == 2); || hardCommitCnt == 2);
assertTrue(softTrigger.waitForNewSearcher(15000));
softTrigger.reset();
assertQ("now it should", req("id:500") ,"//result[@numFound=1]" ); assertQ("now it should", req("id:500") ,"//result[@numFound=1]" );
assertQ("but not this", req("id:531") ,"//result[@numFound=0]" ); assertQ("but not this", req("id:531") ,"//result[@numFound=1]" );
} }
} }