mirror of
https://github.com/apache/lucene.git
synced 2025-02-07 02:28:49 +00:00
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:
parent
5dc7e920f3
commit
7d6821bc76
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user