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 03:09:57 UTC
svn commit: r1215024 - in /lucene/dev/branches/branch_3x: ./ lucene/
lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
lucene/src/test/org/apache/lucene/index/TestCrash.java
lucene/src/test/org/apache/lucene/index/TestDoc.java
Author: rmuir
Date: Fri Dec 16 02:09:57 2011
New Revision: 1215024
URL: http://svn.apache.org/viewvc?rev=1215024&view=rev
Log:
LUCENE-3374: sometimes turn on NRTCachingDirectory in tests
Modified:
lucene/dev/branches/branch_3x/ (props changed)
lucene/dev/branches/branch_3x/lucene/ (props changed)
lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java
Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java?rev=1215024&r1=1215023&r2=1215024&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java Fri Dec 16 02:09:57 2011
@@ -45,6 +45,7 @@ import org.apache.lucene.store.Directory
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.MockDirectoryWrapper;
+import org.apache.lucene.store.NRTCachingDirectory;
import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
import org.junit.After;
import org.junit.AfterClass;
@@ -943,8 +944,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());
return dir;
}
@@ -955,7 +966,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. */
@@ -965,6 +976,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)];
@@ -980,7 +996,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);
}
@@ -996,15 +1013,23 @@ 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);
}
- MockDirectoryWrapper dir = new MockDirectoryWrapper(r, impl);
+ MockDirectoryWrapper dir = new MockDirectoryWrapper(r, maybeWrap ? maybeNRTWrap(r, impl) : impl);
stores.put(dir, Thread.currentThread().getStackTrace());
return dir;
}
+
+ private static Directory maybeNRTWrap(Random random, Directory directory) {
+ if (rarely(random)) {
+ return new NRTCachingDirectory(directory, random.nextDouble(), random.nextDouble());
+ } else {
+ return directory;
+ }
+ }
/** Returns a new field instance.
* See {@link #newField(String, String, Field.Store, Field.Index, Field.TermVector)} for more information */
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java?rev=1215024&r1=1215023&r2=1215024&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestCrash.java Fri Dec 16 02:09:57 2011
@@ -31,7 +31,9 @@ import org.apache.lucene.document.Field;
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/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java?rev=1215024&r1=1215023&r2=1215024&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestDoc.java Fri Dec 16 02:09:57 2011
@@ -106,7 +106,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)).
@@ -140,7 +141,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)).