You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/10/01 23:07:38 UTC

svn commit: r1392604 - in /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene: store/MockDirectoryWrapper.java store/MockIndexOutputWrapper.java util/ThrottledIndexOutput.java

Author: mikemccand
Date: Mon Oct  1 21:07:37 2012
New Revision: 1392604

URL: http://svn.apache.org/viewvc?rev=1392604&view=rev
Log:
only use rateLimiter for sleeping in MDW/MockIO

Removed:
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/ThrottledIndexOutput.java
Modified:
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1392604&r1=1392603&r2=1392604&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java Mon Oct  1 21:07:37 2012
@@ -37,7 +37,6 @@ import org.apache.lucene.index.Directory
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.ThrottledIndexOutput;
 import org.apache.lucene.util._TestUtil;
 
 /**
@@ -73,7 +72,6 @@ public class MockDirectoryWrapper extend
   private Set<String> openFilesForWrite = new HashSet<String>();
   Set<String> openLocks = Collections.synchronizedSet(new HashSet<String>());
   volatile boolean crashed;
-  private ThrottledIndexOutput throttledOutput;
   private Throttling throttling = Throttling.SOMETIMES;
 
   final AtomicInteger inputCloneCount = new AtomicInteger();
@@ -112,22 +110,16 @@ 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);
     // force wrapping of lockfactory
     this.lockFactory = new MockLockFactoryWrapper(this, delegate.getLockFactory());
 
-    // 2% of the time use rate limiter
-    if (randomState.nextInt(50) == 17) {
-      // Use RateLimiter
-      double maxMBPerSec = 10 + 5*(randomState.nextDouble()-0.5);
-      if (LuceneTestCase.VERBOSE) {
-        System.out.println("MockDirectoryWrapper: will rate limit output IO to " + maxMBPerSec + " MB/sec");
-      }
-      rateLimiter = new RateLimiter(maxMBPerSec);
-    } else {
-      rateLimiter = null;
+    // NOTE: we init rateLimiter always but we only
+    // sometimes use it (by default) in createOutput:
+    double maxMBPerSec = 10 + 5*(randomState.nextDouble()-0.5);
+    if (LuceneTestCase.VERBOSE) {
+      System.out.println("MockDirectoryWrapper: will rate limit output IO to " + maxMBPerSec + " MB/sec");
     }
+    rateLimiter = new RateLimiter(maxMBPerSec);
 
     init();
   }
@@ -441,22 +433,25 @@ public class MockDirectoryWrapper extend
         ramdir.fileMap.put(name, file);
       }
     }
-    
-    //System.out.println(Thread.currentThread().getName() + ": MDW: create " + name);
-    IndexOutput io = new MockIndexOutputWrapper(this, delegate.createOutput(name, LuceneTestCase.newIOContext(randomState, context)), name);
-    addFileHandle(io, name, Handle.Output);
-    openFilesForWrite.add(name);
-    
+
+    RateLimiter thisRateLimiter;
+
     // throttling REALLY slows down tests, so don't do it very often for SOMETIMES.
     if (throttling == Throttling.ALWAYS || 
         (throttling == Throttling.SOMETIMES && rateLimiter == null && randomState.nextInt(50) == 0)) {
       if (LuceneTestCase.VERBOSE) {
         System.out.println("MockDirectoryWrapper: throttling indexOutput");
       }
-      return throttledOutput.newFromDelegate(io);
+      thisRateLimiter = rateLimiter;
     } else {
-      return io;
+      thisRateLimiter = null;
     }
+
+    //System.out.println(Thread.currentThread().getName() + ": MDW: create " + name);
+    IndexOutput io = new MockIndexOutputWrapper(this, delegate.createOutput(name, LuceneTestCase.newIOContext(randomState, context)), name, thisRateLimiter);
+    addFileHandle(io, name, Handle.Output);
+    openFilesForWrite.add(name);
+    return io;
   }
   
   private static enum Handle {

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java?rev=1392604&r1=1392603&r2=1392604&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java Mon Oct  1 21:07:37 2012
@@ -32,15 +32,17 @@ public class MockIndexOutputWrapper exte
   private MockDirectoryWrapper dir;
   private final IndexOutput delegate;
   private boolean first=true;
+  private final RateLimiter rateLimiter;
   final String name;
   
   byte[] singleByte = new byte[1];
 
   /** Construct an empty output buffer. */
-  public MockIndexOutputWrapper(MockDirectoryWrapper dir, IndexOutput delegate, String name) {
+  public MockIndexOutputWrapper(MockDirectoryWrapper dir, IndexOutput delegate, String name, RateLimiter rateLimiter) {
     this.dir = dir;
     this.name = name;
     this.delegate = delegate;
+    this.rateLimiter = rateLimiter;
   }
 
   @Override
@@ -78,8 +80,8 @@ public class MockIndexOutputWrapper exte
     long freeSpace = dir.maxSize == 0 ? 0 : dir.maxSize - dir.sizeInBytes();
     long realUsage = 0;
 
-    if (dir.rateLimiter != null && len >= 1000) {
-      dir.rateLimiter.pause(len);
+    if (rateLimiter != null && len >= 1000) {
+      rateLimiter.pause(len);
     }
 
     // If MockRAMDir crashed since we were opened, then