You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2015/03/05 06:43:44 UTC

svn commit: r1664230 - /jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/LuceneSupportTest.groovy

Author: chetanm
Date: Thu Mar  5 05:43:43 2015
New Revision: 1664230

URL: http://svn.apache.org/r1664230
Log:
OAK-2570 - Open indexes in IndexTracker non blocking way

Add retry loop in LuceneSupportTest to account for asynchronous nature of the Lucene indexes

Modified:
    jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/LuceneSupportTest.groovy

Modified: jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/LuceneSupportTest.groovy
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/LuceneSupportTest.groovy?rev=1664230&r1=1664229&r2=1664230&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/LuceneSupportTest.groovy (original)
+++ jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/LuceneSupportTest.groovy Thu Mar  5 05:43:43 2015
@@ -33,13 +33,13 @@ import org.junit.Test
 import javax.jcr.Node
 import javax.jcr.Session
 import javax.jcr.query.*
-import java.util.concurrent.TimeUnit
 
 import static com.google.common.collect.Lists.newArrayList
 import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT
 import static org.apache.jackrabbit.JcrConstants.NT_FILE
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME
 import static org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.REPOSITORY_CONFIG_FILE
+import static org.junit.Assert.fail
 
 class LuceneSupportTest extends AbstractRepositoryFactoryTest {
     Session session
@@ -65,16 +65,17 @@ class LuceneSupportTest extends Abstract
         session.save()
 
         //The lucene index is set to synched mode
-        TimeUnit.SECONDS.sleep(1)
+        retry(10, 200) {
+            String query = "SELECT * FROM [nt:base] as f WHERE CONTAINS (f.*, 'dog')"
+            assert [ '/myFile/jcr:content' ] as HashSet == execute ( query )
+
+            SimpleNodeAggregator agg = new SimpleNodeAggregator().newRuleWithName(
+                    NT_FILE, newArrayList(JCR_CONTENT, JCR_CONTENT + "/*"));
+            getRegistry ( ).registerService ( NodeAggregator.class.name, agg, null )
 
-        String query = "SELECT * FROM [nt:base] as f WHERE CONTAINS (f.*, 'dog')"
-        assert ['/myFile/jcr:content'] as HashSet == execute(query)
-
-        SimpleNodeAggregator agg = new SimpleNodeAggregator().newRuleWithName(
-                NT_FILE, newArrayList(JCR_CONTENT, JCR_CONTENT + "/*"));
-        getRegistry().registerService(NodeAggregator.class.name, agg, null)
-
-        assert ["/myFile", '/myFile/jcr:content'] as HashSet == execute(query)
+            assert [ "/myFile", '/myFile/jcr:content' ] as HashSet == execute ( query )
+            return true
+        }
     }
 
     Set<String> execute(String stmt){
@@ -97,7 +98,7 @@ class LuceneSupportTest extends Abstract
                         NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
                         if (!index.hasChildNode("lucene")) {
                             NodeBuilder nb = LuceneIndexHelper.newLuceneIndexDefinition(
-                                    index, "lucene", LuceneIndexHelper.JR_PROPERTY_INCLUDES)
+                                    index, "lucene", LuceneIndexHelper.JR_PROPERTY_INCLUDES, null, "async")
                             nb.setProperty(LuceneIndexConstants.COMPAT_MODE, IndexFormatVersion.V1.getVersion());
                         }
                     }
@@ -105,4 +106,24 @@ class LuceneSupportTest extends Abstract
             }, null);
         }
     }
+
+    private static retry(int timeoutSeconds, int intervalBetweenTriesMsec, Closure c) {
+        long timeout = System.currentTimeMillis() + timeoutSeconds * 1000L;
+        while (System.currentTimeMillis() < timeout) {
+            try {
+                if (c.call()) {
+                    return;
+                }
+            } catch (AssertionError ignore) {
+            } catch (Exception ignore) {
+            }
+
+            try {
+                Thread.sleep(intervalBetweenTriesMsec);
+            } catch (InterruptedException ignore) {
+            }
+        }
+
+        fail("RetryLoop failed, condition is false after " + timeoutSeconds + " seconds: ");
+    }
 }