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/17 03:19:27 UTC

svn commit: r1103975 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ lucene/src/test-framework/org/apache/lucene/store/ lucene/src/test-framework/org/apache/lucene/util/ lucene/src/test/org/apache/lucene/index/ solr/

Author: rmuir
Date: Tue May 17 01:19:27 2011
New Revision: 1103975

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

Added:
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java   (contents, props changed)
      - copied, changed from r1103971, lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java
Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1103975&r1=1103974&r2=1103975&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/store/MockDirectoryWrapper.java Tue May 17 01:19:27 2011
@@ -33,6 +33,7 @@ import java.util.Set;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.ThrottledIndexOutput;
 import org.apache.lucene.util._TestUtil;
 
 /**
@@ -68,6 +69,8 @@ public class MockDirectoryWrapper extend
   private Set<String> createdFiles;
   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
@@ -101,6 +104,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();
   }
 
@@ -124,6 +129,19 @@ public class MockDirectoryWrapper extend
     unSyncedFiles.remove(name);
     delegate.sync(name);
   }
+  
+  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
   public synchronized void sync(Collection<String> names) throws IOException {
@@ -358,7 +376,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 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

Copied: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java (from r1103971, lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java?p2=lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java&p1=lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java&r1=1103971&r2=1103975&rev=1103975&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/ThrottledIndexOutput.java Tue May 17 01:19:27 2011
@@ -18,7 +18,7 @@ package org.apache.lucene.util;
  */
 import java.io.IOException;
 
-import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
 
 public class ThrottledIndexOutput extends IndexOutput {
@@ -141,7 +141,7 @@ public class ThrottledIndexOutput extend
   }
 
   @Override
-  public void copyBytes(DataInput input, long numBytes) throws IOException {
+  public void copyBytes(IndexInput input, long numBytes) throws IOException {
     delegate.copyBytes(input, numBytes);
   }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java?rev=1103975&r1=1103974&r2=1103975&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/Test2BTerms.java Tue May 17 01:19:27 2011
@@ -91,7 +91,8 @@ public class Test2BTerms extends LuceneT
 
     List<String> 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) {