@@ -119,6 +119,26 @@ public abstract class AbstractGenericLuceneTest {
119119
120120 protected abstract void configure (LuceneSail sail ) throws IOException ;
121121
122+ /**
123+ * How long to wait after a commit() to ensure index is updated.
124+ *
125+ * @return milliseconds to wait
126+ */
127+ protected long waitAfterCommitMillis () {
128+ return 0 ;
129+ }
130+
131+ protected final void sleepAfterCommitIfNeeded () {
132+ long waitMillis = waitAfterCommitMillis ();
133+ if (waitMillis > 0 ) {
134+ try {
135+ Thread .sleep (waitMillis );
136+ } catch (InterruptedException e ) {
137+ Thread .currentThread ().interrupt ();
138+ }
139+ }
140+ }
141+
122142 @ BeforeEach
123143 public void setUp () throws Exception {
124144 // set logging, uncomment this to get better logging for debugging
@@ -166,6 +186,7 @@ public void tearDown() throws RepositoryException {
166186
167187 @ Test
168188 public void testComplexQueryTwo () throws MalformedQueryException , RepositoryException , QueryEvaluationException {
189+ sleepAfterCommitIfNeeded ();
169190 // prepare the query
170191 StringBuilder buffer = new StringBuilder ();
171192 buffer .append ("SELECT ?Resource ?Matching ?Score " );
@@ -275,6 +296,7 @@ private void evaluate(String[] queries, ArrayList<List<Map<String, String>>> exp
275296 @ Test
276297 public void testPredicateLuceneQueries ()
277298 throws MalformedQueryException , RepositoryException , QueryEvaluationException {
299+ sleepAfterCommitIfNeeded ();
278300 // prepare the query
279301 String [] queries = new String [] {
280302 "SELECT ?Resource ?Score ?Snippet \n "
@@ -337,6 +359,7 @@ public void testPredicateLuceneQueries()
337359
338360 @ Test
339361 public void testSnippetQueries () throws MalformedQueryException , RepositoryException , QueryEvaluationException {
362+ sleepAfterCommitIfNeeded ();
340363 // prepare the query
341364 // search for the term "one", but only in predicate 1
342365 StringBuilder buffer = new StringBuilder ();
@@ -396,6 +419,7 @@ public void testSnippetLimitedToPredicate()
396419 localConnection .add (SUBJECT_1 , PREDICATE_1 , vf .createLiteral ("but the unicorn charly said to goaway" ));
397420 localConnection .add (SUBJECT_1 , PREDICATE_2 , vf .createLiteral ("there was poor charly without a kidney" ));
398421 localConnection .commit ();
422+ sleepAfterCommitIfNeeded ();
399423 }
400424
401425 // prepare the query
@@ -471,6 +495,7 @@ public void testCharlyTerm() {
471495 localConnection .add (SUBJECT_1 , PREDICATE_1 , vf .createLiteral ("but the unicorn charly said to goaway" ));
472496 localConnection .add (SUBJECT_1 , PREDICATE_2 , vf .createLiteral ("there was poor charly without a kidney" ));
473497 localConnection .commit ();
498+ sleepAfterCommitIfNeeded ();
474499 }
475500 // search for the term "charly" in all predicates
476501 StringBuilder buffer = new StringBuilder ();
@@ -529,6 +554,7 @@ public void testCharlyTerm() {
529554
530555 @ Test
531556 public void testGraphQuery () throws QueryEvaluationException , MalformedQueryException , RepositoryException {
557+ sleepAfterCommitIfNeeded ();
532558 IRI score = vf .createIRI (LuceneSailSchema .NAMESPACE + "score" );
533559 StringBuilder query = new StringBuilder ();
534560
@@ -577,6 +603,7 @@ public void testGraphQuery() throws QueryEvaluationException, MalformedQueryExce
577603 @ Test
578604 public void testQueryWithSpecifiedSubject ()
579605 throws RepositoryException , MalformedQueryException , QueryEvaluationException {
606+ sleepAfterCommitIfNeeded ();
580607 // fire a query with the subject pre-specified
581608 TupleQuery query = connection .prepareTupleQuery (QUERY_STRING );
582609 query .setBinding ("Subject" , SUBJECT_1 );
@@ -594,6 +621,7 @@ public void testQueryWithSpecifiedSubject()
594621
595622 @ Test
596623 public void testUnionQuery () throws RepositoryException , MalformedQueryException , QueryEvaluationException {
624+ sleepAfterCommitIfNeeded ();
597625 String queryStr = "" ;
598626 queryStr += "PREFIX search: <http://www.openrdf.org/contrib/lucenesail#> " ;
599627 queryStr += "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " ;
@@ -626,6 +654,7 @@ public void testContextHandling() {
626654 connection .add (SUBJECT_5 , PREDICATE_1 , vf .createLiteral ("sfiveponectwo" ), CONTEXT_2 );
627655 connection .add (SUBJECT_5 , PREDICATE_2 , vf .createLiteral ("sfiveptwoctwo" ), CONTEXT_2 );
628656 connection .commit ();
657+ sleepAfterCommitIfNeeded ();
629658 // connection.close();
630659 // connection = repository.getConnection();
631660 // connection.setAutoCommit(false);
@@ -640,6 +669,7 @@ public void testContextHandling() {
640669 // remove a context
641670 connection .clear (CONTEXT_1 );
642671 connection .commit ();
672+ sleepAfterCommitIfNeeded ();
643673 assertNoQueryResult ("sfourponecone" );
644674 assertNoQueryResult ("sfourptwocone" );
645675 assertNoQueryResult ("sfiveponecone" );
@@ -659,6 +689,7 @@ public void testNullContextHandling() {
659689 connection .add (SUBJECT_5 , PREDICATE_1 , vf .createLiteral ("sfiveponectwo" ), CONTEXT_2 );
660690 connection .add (SUBJECT_5 , PREDICATE_2 , vf .createLiteral ("sfiveptwoctwo" ), CONTEXT_2 );
661691 connection .commit ();
692+ sleepAfterCommitIfNeeded ();
662693 // connection.close();
663694 // connection = repository.getConnection();
664695 // connection.setAutoCommit(false);
@@ -673,6 +704,7 @@ public void testNullContextHandling() {
673704 // remove a context
674705 connection .clear ((Resource ) null );
675706 connection .commit ();
707+ sleepAfterCommitIfNeeded ();
676708 assertNoQueryResult ("sfourponecone" );
677709 assertNoQueryResult ("sfourptwocone" );
678710 assertNoQueryResult ("sfiveponecone" );
@@ -682,6 +714,7 @@ public void testNullContextHandling() {
682714
683715 @ Test
684716 public void testFuzzyQuery () throws MalformedQueryException , RepositoryException , QueryEvaluationException {
717+ sleepAfterCommitIfNeeded ();
685718 // prepare the query
686719 // search for the term "one" with 80% fuzzyness
687720 StringBuilder buffer = new StringBuilder ();
@@ -729,11 +762,13 @@ public void testFuzzyQuery() throws MalformedQueryException, RepositoryException
729762 @ Test
730763 public void testReindexing () {
731764 sail .reindex ();
765+ sleepAfterCommitIfNeeded ();
732766 testComplexQueryTwo ();
733767 }
734768
735769 @ Test
736770 public void testPropertyVar () throws MalformedQueryException , RepositoryException , QueryEvaluationException {
771+ sleepAfterCommitIfNeeded ();
737772 StringBuilder buffer = new StringBuilder ();
738773 buffer .append ("SELECT ?Resource ?Property \n " );
739774 buffer .append ("WHERE { \n " );
0 commit comments