Apache Lucene open-source search software
randomly use RateLimiter in MDW
Michael McCandless7d6821bc76af
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.javaindex 2edd985d9f3..5bc0e48ce4f 100644--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java@@ -94,6 +94,8 @@ public class MockDirectoryWrapper extends Directory {// is made to delete an open file, we enroll it here.private Set<String> openFilesDeleted;+ final RateLimiter rateLimiter;+private synchronized void init() {if (openFiles == null) {openFiles = new HashMap<String,Integer>();@@ -120,6 +122,19 @@ public class MockDirectoryWrapper extends Directory {} catch (IOException e) {throw new RuntimeException(e);}++ // 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;+ }+init();}diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.javaindex 83f29b75d48..9658110e006 100644--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java@@ -78,6 +78,10 @@ public class MockIndexOutputWrapper extends IndexOutput {long freeSpace = dir.maxSize == 0 ? 0 : dir.maxSize - dir.sizeInBytes();long realUsage = 0;+ if (dir.rateLimiter != null) {+ dir.rateLimiter.pause(len);+ }+// If MockRAMDir crashed since we were opened, then// don't write anything:if (dir.crashed)