randomly use RateLimiter in MDW

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1334628 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-05-06 13:52:04 +00:00
parent 5dc7e920f3
commit 7d6821bc76
2 changed files with 19 additions and 0 deletions

View File

@ -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();
}

View File

@ -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)