You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2013/01/10 00:09:05 UTC

svn commit: r1431139 - /incubator/jspwiki/trunk/tests/org/apache/wiki/search/SearchManagerTest.java

Author: juanpablo
Date: Wed Jan  9 23:09:05 2013
New Revision: 1431139

URL: http://svn.apache.org/viewvc?rev=1431139&view=rev
Log:
Refactored test so it's ~75% faster.

Modified:
    incubator/jspwiki/trunk/tests/org/apache/wiki/search/SearchManagerTest.java

Modified: incubator/jspwiki/trunk/tests/org/apache/wiki/search/SearchManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/org/apache/wiki/search/SearchManagerTest.java?rev=1431139&r1=1431138&r2=1431139&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/org/apache/wiki/search/SearchManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/org/apache/wiki/search/SearchManagerTest.java Wed Jan  9 23:09:05 2013
@@ -32,7 +32,7 @@ import org.apache.wiki.WikiContext;
 
 public class SearchManagerTest extends TestCase
 {
-    private static final long SLEEP_TIME = 10000L;
+    private static final long SLEEP_TIME = 200L;
     TestEngine m_engine;
     SearchManager m_mgr;
     
@@ -66,6 +66,27 @@ public class SearchManagerTest extends T
                       m_mgr.getSearchEngine().getClass().getName() );    
     }
     
+    /**
+     * Should cover for both index and initial delay
+     */
+    Collection waitForIndex( String text ) throws Exception
+    {
+        Collection res = null;
+        for( long l = 0; l < 50; l++ ) 
+        {
+            if( res == null || res.isEmpty() ) 
+            {
+                Thread.sleep( SLEEP_TIME );
+            }
+            else 
+            {
+                break;
+            }
+            res = m_mgr.findPages( text );
+        }
+        return res;
+    }
+    
     public void testSimpleSearch()
         throws Exception
     {
@@ -74,10 +95,7 @@ public class SearchManagerTest extends T
         m_engine.saveText("TestPage", txt);
 
         Thread.yield();
-
-        Thread.sleep( SLEEP_TIME ); // Should cover for both index and initial delay
-        
-        Collection res = m_mgr.findPages( "mankind" );
+        Collection res = waitForIndex( "mankind" );
      
         assertNotNull( "null result", res );
         assertEquals( "no pages", 1, res.size() );
@@ -95,10 +113,7 @@ public class SearchManagerTest extends T
         m_engine.saveText("TestPage", txt + " 2");
         
         Thread.yield();
-
-        Thread.sleep( SLEEP_TIME ); // Should cover for both index and initial delay
-    
-        Collection res = m_mgr.findPages( "mankind" );
+        Collection res = waitForIndex( "mankind" );
  
         assertNotNull( "null result", res );
         assertEquals( "no pages", 1, res.size() );
@@ -122,8 +137,9 @@ public class SearchManagerTest extends T
      
         Thread.yield();
 
-        Thread.sleep( SLEEP_TIME ); // Should cover for both index and initial delay
- 
+        Thread.sleep( SLEEP_TIME * 50L ); // Should cover for both index and initial delay
+                                          // waitForIndex cannot be used here b/c it doesn't detect
+                                          // the second call to saveText
         Collection res = m_mgr.findPages( "mankind" );
 
         assertNotNull( "found results", res );
@@ -144,10 +160,7 @@ public class SearchManagerTest extends T
         m_engine.saveText("TestPage", txt);
      
         Thread.yield();
-
-        Thread.sleep( SLEEP_TIME ); // Should cover for both index and initial delay
- 
-        Collection res = m_mgr.findPages( "Test" );
+        Collection res = waitForIndex( "Test" );
 
         assertNotNull( "null result", res );
         assertEquals( "no pages", 1, res.size() );
@@ -163,10 +176,7 @@ public class SearchManagerTest extends T
         m_engine.saveText("TestPage", txt);
  
         Thread.yield();
-
-        Thread.sleep( SLEEP_TIME ); // Should cover for both index and initial delay
-
-        Collection res = m_mgr.findPages( "TestPage" );
+        Collection res = waitForIndex( "TestPage" );
 
         assertNotNull( "null result", res );
         assertEquals( "no pages", 1, res.size() );