Simplify testPutFileParallel

Create only one temporary file and use explicit delete instead
finalization to remove it.
This commit is contained in:
Andrew Gaul 2013-08-26 23:19:57 -07:00
parent 8e16ecb3ec
commit e2489f3942
1 changed files with 4 additions and 7 deletions

View File

@ -127,8 +127,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
public void testPutFileParallel() throws InterruptedException, IOException, TimeoutException {
File payloadFile = File.createTempFile("testPutFileParallel", "png");
Files.copy(createTestInput(), payloadFile);
payloadFile.deleteOnExit();
Files.write(createTestInput(), payloadFile);
final Payload testPayload = Payloads.newFilePayload(payloadFile);
final byte[] md5 = md5Supplier(testPayload);
@ -165,6 +164,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
assert exceptions.size() == 0 : exceptions;
} finally {
payloadFile.delete();
returnContainer(container);
}
}
@ -604,13 +604,10 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
assertEquals(metadata.getContentMetadata().getContentMD5(), md5().hashString(TEST_STRING, UTF_8).asBytes());
}
private File createTestInput() throws IOException {
File file = File.createTempFile("testimg", "png");
file.deleteOnExit();
private byte[] createTestInput() throws IOException {
Random random = new Random();
byte[] buffer = new byte[random.nextInt(2 * 1024 * 1024)];
random.nextBytes(buffer);
Files.copy(ByteStreams.newInputStreamSupplier(buffer), file);
return file;
return buffer;
}
}