lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1591728 - in /lucene/dev/branches/lucene_solr_4_8: ./ lucene/ lucene/core/ lucene/core/src/test/org/apache/lucene/index/ lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/ lucene/test-framework/src/java/...
Date Thu, 01 May 2014 18:39:40 GMT
Author: rmuir
Date: Thu May  1 18:39:39 2014
New Revision: 1591728

URL: http://svn.apache.org/r1591728
Log:
LUCENE-5635: speed up and improve test

Modified:
    lucene/dev/branches/lucene_solr_4_8/   (props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/   (props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/core/   (props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions2.java
  (contents, props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/   (props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/
  (props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyStoredFieldsFormat.java
    lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyTermVectorsFormat.java
    lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java

Modified: lucene/dev/branches/lucene_solr_4_8/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_8/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions2.java?rev=1591728&r1=1591727&r2=1591728&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_8/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions2.java
(original)
+++ lucene/dev/branches/lucene_solr_4_8/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions2.java
Thu May  1 18:39:39 2014
@@ -27,11 +27,13 @@ import org.apache.lucene.analysis.Cranky
 import org.apache.lucene.analysis.MockTokenizer;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.codecs.asserting.AssertingCodec;
 import org.apache.lucene.codecs.cranky.CrankyCodec;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.NumericDocValuesField;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
@@ -42,16 +44,17 @@ import org.apache.lucene.util.Rethrow;
  * Causes a bunch of non-aborting and aborting exceptions and checks that
  * no index corruption is ever created
  */
-// TODO: not sure which fails are test bugs or real bugs yet...
-// reproduce with: ant test  -Dtestcase=TestIndexWriterExceptions2 -Dtests.method=testSimple
-Dtests.seed=9D05AC6DFF3CC9A4 -Dtests.multiplier=10 -Dtests.locale=fi_FI -Dtests.timezone=Canada/Pacific
-Dtests.file.encoding=ISO-8859-1
-// also sometimes when it fails, the exception-stream printing doesnt seem to be working
yet
-// 
 @SuppressCodecs("Lucene3x")
 public class TestIndexWriterExceptions2 extends LuceneTestCase {
   
   // just one thread, serial merge policy, hopefully debuggable
   public void testBasics() throws Exception {
+    // disable slow things: we don't rely upon sleeps here.
     Directory dir = newDirectory();
+    if (dir instanceof MockDirectoryWrapper) {
+      ((MockDirectoryWrapper)dir).setThrottling(MockDirectoryWrapper.Throttling.NEVER);
+      ((MockDirectoryWrapper)dir).setUseSlowOpenClosers(false);
+    }
     
     // log all exceptions we hit, in case we fail (for debugging)
     ByteArrayOutputStream exceptionLog = new ByteArrayOutputStream();
@@ -71,15 +74,16 @@ public class TestIndexWriterExceptions2 
     };
     
     // create lots of aborting exceptions with a broken codec
-    Codec codec = new CrankyCodec(Codec.getDefault(), new Random(random().nextLong()));
+    // we don't need a random codec, as we aren't trying to find bugs in the codec here.
+    Codec inner = RANDOM_MULTIPLIER > 1 ? Codec.getDefault() : new AssertingCodec();
+    Codec codec = new CrankyCodec(inner, new Random(random().nextLong()));
     
     IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
     // just for now, try to keep this test reproducible
     conf.setMergeScheduler(new SerialMergeScheduler());
     conf.setCodec(codec);
     
-    // TODO: too much?
-    int numDocs = RANDOM_MULTIPLIER * 1000;
+    int numDocs = atLeast(2500);
     
     IndexWriter iw = new IndexWriter(dir, conf);
     try {

Modified: lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyStoredFieldsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyStoredFieldsFormat.java?rev=1591728&r1=1591727&r2=1591728&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyStoredFieldsFormat.java
(original)
+++ lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyStoredFieldsFormat.java
Thu May  1 18:39:39 2014
@@ -66,6 +66,9 @@ class CrankyStoredFieldsFormat extends S
     @Override
     public void abort() {
       delegate.abort();
+      if (random.nextInt(100) == 0) {
+        throw new RuntimeException(new IOException("Fake IOException from StoredFieldsWriter.abort()"));
+      }
     }
 
     @Override

Modified: lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyTermVectorsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyTermVectorsFormat.java?rev=1591728&r1=1591727&r2=1591728&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyTermVectorsFormat.java
(original)
+++ lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyTermVectorsFormat.java
Thu May  1 18:39:39 2014
@@ -67,6 +67,9 @@ class CrankyTermVectorsFormat extends Te
     @Override
     public void abort() {
       delegate.abort();
+      if (random.nextInt(100) == 0) {
+        throw new RuntimeException(new IOException("Fake IOException from TermVectorsWriter.abort()"));
+      }
     }
     
     @Override

Modified: lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1591728&r1=1591727&r2=1591728&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
(original)
+++ lucene/dev/branches/lucene_solr_4_8/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
Thu May  1 18:39:39 2014
@@ -74,6 +74,7 @@ public class MockDirectoryWrapper extend
   boolean preventDoubleWrite = true;
   boolean trackDiskUsage = false;
   boolean wrapLockFactory = true;
+  boolean useSlowOpenClosers = true;
   boolean allowRandomFileNotFoundException = true;
   boolean allowReadingFilesStillOpenForWrite = false;
   private Set<String> unSyncedFiles;
@@ -172,6 +173,15 @@ public class MockDirectoryWrapper extend
   public void setThrottling(Throttling throttling) {
     this.throttling = throttling;
   }
+  
+  /** 
+   * By default, opening and closing has a rare small sleep to catch race conditions
+   * <p>
+   * You can disable this if you dont need it
+   */
+  public void setUseSlowOpenClosers(boolean v) {
+    useSlowOpenClosers = v;
+  }
 
   /**
    * Returns true if {@link #in} must sync its files.
@@ -525,7 +535,7 @@ public class MockDirectoryWrapper extend
     
     // throttling REALLY slows down tests, so don't do it very often for SOMETIMES.
     if (throttling == Throttling.ALWAYS || 
-        (throttling == Throttling.SOMETIMES && randomState.nextInt(50) == 0) &&
!(in instanceof RateLimitedDirectoryWrapper)) {
+        (throttling == Throttling.SOMETIMES && randomState.nextInt(200) == 0) &&
!(in instanceof RateLimitedDirectoryWrapper)) {
       if (LuceneTestCase.VERBOSE) {
         System.out.println("MockDirectoryWrapper: throttling indexOutput (" + name + ")");
       }
@@ -579,12 +589,12 @@ public class MockDirectoryWrapper extend
 
     final IndexInput ii;
     int randomInt = randomState.nextInt(500);
-    if (randomInt == 0) {
+    if (useSlowOpenClosers && randomInt == 0) {
       if (LuceneTestCase.VERBOSE) {
         System.out.println("MockDirectoryWrapper: using SlowClosingMockIndexInputWrapper
for file " + name);
       }
       ii = new SlowClosingMockIndexInputWrapper(this, name, delegateInput);
-    } else if (randomInt  == 1) { 
+    } else if (useSlowOpenClosers && randomInt  == 1) { 
       if (LuceneTestCase.VERBOSE) {
         System.out.println("MockDirectoryWrapper: using SlowOpeningMockIndexInputWrapper
for file " + name);
       }



Mime
View raw message