LUCENE-3601: beef up crash() to use random actions (not based on file count) and to sometimes leave zero-byte files

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1207103 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-11-28 12:23:15 +00:00
parent 4dd6b5fbed
commit 739ff5dacc
1 changed files with 11 additions and 6 deletions

View File

@ -194,12 +194,12 @@ public class MockDirectoryWrapper extends Directory {
f.close();
} catch (Exception ignored) {}
int count = 0;
while(it.hasNext()) {
String name = it.next();
if (count % 3 == 0) {
int damage = randomState.nextInt(4);
if (damage == 0) {
deleteFile(name, true);
} else if (count % 3 == 1) {
} else if (damage == 1) {
// Zero out file entirely
long length = fileLength(name);
byte[] zeroes = new byte[256];
@ -211,13 +211,18 @@ public class MockDirectoryWrapper extends Directory {
upto += limit;
}
out.close();
} else if (count % 3 == 2) {
// Truncate the file:
} else if (damage == 2) {
// Partially Truncate the file:
IndexOutput out = delegate.createOutput(name, LuceneTestCase.newIOContext(randomState));
out.setLength(fileLength(name)/2);
out.close();
} else {
// Totally truncate the file to zero bytes
deleteFile(name, true);
IndexOutput out = delegate.createOutput(name, LuceneTestCase.newIOContext(randomState));
out.setLength(0);
out.close();
}
count++;
}
}