You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2011/12/16 02:52:42 UTC

svn commit: r1215018 - in /lucene/dev/trunk/lucene/src: test-framework/java/org/apache/lucene/util/LuceneTestCase.java test/org/apache/lucene/index/TestCrash.java test/org/apache/lucene/index/TestDoc.java

Author: rmuir
Date: Fri Dec 16 01:52:41 2011
New Revision: 1215018

URL: http://svn.apache.org/viewvc?rev=1215018&view=rev
Log:
LUCENE-3374: sometimes turn on NRTCachingDirectory in tests

Modified:
    lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCrash.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java

Modified: lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java?rev=1215018&r1=1215017&r2=1215018&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java Fri Dec 16 01:52:41 2011
@@ -58,6 +58,7 @@ import org.apache.lucene.store.LockFacto
 import org.apache.lucene.store.MergeInfo;
 import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.store.MockDirectoryWrapper.Throttling;
+import org.apache.lucene.store.NRTCachingDirectory;
 import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
 import org.junit.*;
 import org.junit.rules.MethodRule;
@@ -1006,8 +1007,18 @@ public abstract class LuceneTestCase ext
    * See {@link #newDirectory()} for more information.
    */
   public static MockDirectoryWrapper newDirectory(Random r) throws IOException {
+    return newDirectory(r, true);
+  }
+  
+  /**
+   * Returns a new Directory instance, using the specified random. You
+   * can specify maybeWrap as to whether the directory might be also
+   * wrapped by NRTCachingDirectory or FileSwitchDirectory
+   * See {@link #newDirectory()} for more information.
+   */
+  public static MockDirectoryWrapper newDirectory(Random r, boolean maybeWrap) throws IOException {
     Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
-    MockDirectoryWrapper dir = new MockDirectoryWrapper(r, impl);
+    MockDirectoryWrapper dir = new MockDirectoryWrapper(r, maybeWrap ? maybeNRTWrap(r, impl) : impl);
     stores.put(dir, Thread.currentThread().getStackTrace());
     dir.setThrottling(TEST_THROTTLING);
     return dir;
@@ -1019,7 +1030,7 @@ public abstract class LuceneTestCase ext
    * information.
    */
   public static MockDirectoryWrapper newDirectory(Directory d) throws IOException {
-    return newDirectory(random, d);
+    return newDirectory(random, d, true);
   }
 
   /** Returns a new FSDirectory instance over the given file, which must be a folder. */
@@ -1029,6 +1040,11 @@ public abstract class LuceneTestCase ext
 
   /** Returns a new FSDirectory instance over the given file, which must be a folder. */
   public static MockDirectoryWrapper newFSDirectory(File f, LockFactory lf) throws IOException {
+    return newFSDirectory(f, lf, true);
+  }
+
+  /** Returns a new FSDirectory instance over the given file, which must be a folder. */
+  public static MockDirectoryWrapper newFSDirectory(File f, LockFactory lf, boolean maybeWrap) throws IOException {
     String fsdirClass = TEST_DIRECTORY;
     if (fsdirClass.equals("random")) {
       fsdirClass = FS_DIRECTORIES[random.nextInt(FS_DIRECTORIES.length)];
@@ -1044,7 +1060,8 @@ public abstract class LuceneTestCase ext
         clazz = CommandLineUtil.loadFSDirectoryClass(fsdirClass);
       }
       
-      MockDirectoryWrapper dir = new MockDirectoryWrapper(random, newFSDirectoryImpl(clazz, f));
+      Directory fsdir = newFSDirectoryImpl(clazz, f);
+      MockDirectoryWrapper dir = new MockDirectoryWrapper(random, maybeWrap ? maybeNRTWrap(random, fsdir) : fsdir);
       if (lf != null) {
         dir.setLockFactory(lf);
       }
@@ -1061,17 +1078,25 @@ public abstract class LuceneTestCase ext
    * with contents copied from the provided directory. See 
    * {@link #newDirectory()} for more information.
    */
-  public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
+  public static MockDirectoryWrapper newDirectory(Random r, Directory d, boolean maybeWrap) throws IOException {
     Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
     for (String file : d.listAll()) {
      d.copy(impl, file, file, newIOContext(r));
     }
-    MockDirectoryWrapper dir = new MockDirectoryWrapper(r, impl);
+    MockDirectoryWrapper dir = new MockDirectoryWrapper(r, maybeWrap ? maybeNRTWrap(r, impl) : impl);
     stores.put(dir, Thread.currentThread().getStackTrace());
     dir.setThrottling(TEST_THROTTLING);
     return dir;
   }
   
+  private static Directory maybeNRTWrap(Random random, Directory directory) {
+    if (rarely(random)) {
+      return new NRTCachingDirectory(directory, random.nextDouble(), random.nextDouble());
+    } else {
+      return directory;
+    }
+  }
+  
   public static Field newField(String name, String value, FieldType type) {
     return newField(random, name, value, type);
   }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCrash.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCrash.java?rev=1215018&r1=1215017&r2=1215018&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCrash.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestCrash.java Fri Dec 16 01:52:41 2011
@@ -30,7 +30,9 @@ import org.apache.lucene.document.TextFi
 public class TestCrash extends LuceneTestCase {
 
   private IndexWriter initIndex(Random random, boolean initialCommit) throws IOException {
-    return initIndex(random, newDirectory(), initialCommit);
+    // note: we pass 'false' here so our crashing/deleting won't trigger assertions in NRTCachingDir
+    // TODO: don't remember why this is ok... maybe we should check again that it really actually is.
+    return initIndex(random, newDirectory(random, false), initialCommit);
   }
 
   private IndexWriter initIndex(Random random, MockDirectoryWrapper dir, boolean initialCommit) throws IOException {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java?rev=1215018&r1=1215017&r2=1215018&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDoc.java Fri Dec 16 01:52:41 2011
@@ -114,7 +114,8 @@ public class TestDoc extends LuceneTestC
       StringWriter sw = new StringWriter();
       PrintWriter out = new PrintWriter(sw, true);
       
-      Directory directory = newFSDirectory(indexDir);
+      // TODO: why does this test trigger NRTCachingDirectory's assert?
+      Directory directory = newFSDirectory(indexDir, null, false);
       IndexWriter writer = new IndexWriter(
           directory,
           newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).
@@ -148,7 +149,8 @@ public class TestDoc extends LuceneTestC
       sw = new StringWriter();
       out = new PrintWriter(sw, true);
 
-      directory = newFSDirectory(indexDir);
+      // TODO: why does this test trigger NRTCachingDirectory's assert?
+      directory = newFSDirectory(indexDir, null, false);
       writer = new IndexWriter(
           directory,
           newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).