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/05/10 18:45:57 UTC

svn commit: r1101539 - in /lucene/dev/trunk/lucene/src: test-framework/org/apache/lucene/store/MockDirectoryWrapper.java test/org/apache/lucene/index/Test2BTerms.java test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java

Author: rmuir
Date: Tue May 10 16:45:57 2011
New Revision: 1101539

URL: http://svn.apache.org/viewvc?rev=1101539&view=rev
Log:
MockDirectoryWrapper should randomly swap in ThrottledIndexOutput

Modified:
    lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/Test2BTerms.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java

Modified: lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1101539&r1=1101538&r2=1101539&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java Tue May 10 16:45:57 2011
@@ -71,6 +71,7 @@ public class MockDirectoryWrapper extend
   Set<String> openFilesForWrite = new HashSet<String>();
   volatile boolean crashed;
   private ThrottledIndexOutput throttledOutput;
+  private Throttling throttling = Throttling.SOMETIMES;
 
   // use this for tracking files for crash.
   // additionally: provides debugging information in case you leave one open
@@ -104,6 +105,8 @@ public class MockDirectoryWrapper extend
     // called from different threads; else test failures may
     // not be reproducible from the original seed
     this.randomState = new Random(random.nextInt());
+    this.throttledOutput = new ThrottledIndexOutput(ThrottledIndexOutput
+        .mBitsToBytes(40 + randomState.nextInt(10)), 5 + randomState.nextInt(5), null);
     init();
   }
 
@@ -117,8 +120,17 @@ public class MockDirectoryWrapper extend
     preventDoubleWrite = value;
   }
   
-  public void setThrottledIndexOutput(ThrottledIndexOutput throttledOutput) {
-    this.throttledOutput = throttledOutput;
+  public static enum Throttling {
+    /** always emulate a slow hard disk. could be very slow! */
+    ALWAYS,
+    /** sometimes (2% of the time) emulate a slow hard disk. */
+    SOMETIMES,
+    /** never throttle output */
+    NEVER
+  };
+  
+  public void setThrottling(Throttling throttling) {
+    this.throttling = throttling;
   }
 
   @Override
@@ -354,7 +366,17 @@ public class MockDirectoryWrapper extend
     IndexOutput io = new MockIndexOutputWrapper(this, delegate.createOutput(name), name);
     openFileHandles.put(io, new RuntimeException("unclosed IndexOutput"));
     openFilesForWrite.add(name);
-    return throttledOutput == null ? io : throttledOutput.newFromDelegate(io);
+    
+    // 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)) {
+      if (LuceneTestCase.VERBOSE) {
+        System.out.println("MockDirectoryWrapper: throttling indexOutput");
+      }
+      return throttledOutput.newFromDelegate(io);
+    } else {
+      return io;
+    }
   }
 
   @Override

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/Test2BTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/Test2BTerms.java?rev=1101539&r1=1101538&r2=1101539&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/Test2BTerms.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/Test2BTerms.java Tue May 10 16:45:57 2011
@@ -153,7 +153,8 @@ public class Test2BTerms extends LuceneT
 
     List<BytesRef> savedTerms = null;
 
-    Directory dir = newFSDirectory(_TestUtil.getTempDir("2BTerms"));
+    MockDirectoryWrapper dir = newFSDirectory(_TestUtil.getTempDir("2BTerms"));
+    dir.setThrottling(MockDirectoryWrapper.Throttling.NEVER);
     //Directory dir = newFSDirectory(new File("/p/lucene/indices/2bindex"));
 
     if (true) {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java?rev=1101539&r1=1101538&r2=1101539&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestFlushByRamOrCountsPolicy.java Tue May 10 16:45:57 2011
@@ -233,8 +233,7 @@ public class TestFlushByRamOrCountsPolic
       AtomicInteger numDocs = new AtomicInteger(numDocumentsToIndex);
       MockDirectoryWrapper dir = newDirectory();
       // mock a very slow harddisk here so that flushing is very slow
-      dir.setThrottledIndexOutput(new ThrottledIndexOutput(ThrottledIndexOutput
-          .mBitsToBytes(40 + random.nextInt(10)), 5 + random.nextInt(5), null));
+      dir.setThrottling(MockDirectoryWrapper.Throttling.ALWAYS);
       IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT,
           new MockAnalyzer(random));
       iwc.setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH);