Use randomByteSource to generate test data

This avoids buffering the entire bolus of data in-memory.
This commit is contained in:
Andrew Gaul 2014-08-27 15:59:36 -07:00
parent ba9c4b972a
commit 550018a68d
2 changed files with 5 additions and 8 deletions

View File

@ -16,6 +16,7 @@
*/
package org.jclouds.filesystem.utils;
import static org.jclouds.utils.TestUtils.randomByteSource;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@ -214,9 +215,9 @@ public class TestUtils {
}
Random random = new Random();
for (File file : IMAGE_RESOURCES) {
byte[] buffer = new byte[random.nextInt(2 * 1024 * 1024)];
random.nextBytes(buffer);
ByteSource.wrap(buffer).copyTo(Files.asByteSink(file));
int length = random.nextInt(2 * 1024 * 1024);
ByteSource byteSource = randomByteSource().slice(0, length);
byteSource.copyTo(Files.asByteSink(file));
}
}

View File

@ -630,11 +630,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
}
/** @return ByteSource containing a random length 0..length of random bytes. */
@SuppressWarnings("unchecked")
private static ByteSource createTestInput(int length) {
Random random = new Random();
byte[] buffer = new byte[random.nextInt(length)];
random.nextBytes(buffer);
return ByteSource.wrap(buffer);
return TestUtils.randomByteSource().slice(0, new Random().nextInt(length));
}
}