SOLR-5026: org.apache.solr.store.blockcache.BlockDirectoryTest.testRandomAccessWrites would pass a 0 to random#next on 0 file size

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1501781 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-07-10 15:05:52 +00:00
parent f007cde66d
commit 2310ab22f0
1 changed files with 16 additions and 2 deletions

View File

@ -179,11 +179,25 @@ public class BlockDirectoryTest extends LuceneTestCase {
assertEquals(fsInput.length(), hdfsInput.length());
int fileLength = (int) fsInput.length();
for (int i = 0; i < reads; i++) {
byte[] fsBuf = new byte[random.nextInt(Math.min(MAX_BUFFER_SIZE - MIN_BUFFER_SIZE, fileLength)) + MIN_BUFFER_SIZE];
int rnd;
if (fileLength == 0) {
rnd = 0;
} else {
rnd = random.nextInt(Math.min(MAX_BUFFER_SIZE - MIN_BUFFER_SIZE, fileLength));
}
byte[] fsBuf = new byte[rnd + MIN_BUFFER_SIZE];
byte[] hdfsBuf = new byte[fsBuf.length];
int offset = random.nextInt(fsBuf.length);
int length = random.nextInt(fsBuf.length - offset);
int pos = random.nextInt(fileLength - length);
int pos;
if (fileLength == 0) {
pos = 0;
} else {
pos = random.nextInt(fileLength - length);
}
fsInput.seek(pos);
fsInput.readBytes(fsBuf, offset, length);
hdfsInput.seek(pos);