[Test] make sure to close the file at the end of the test

This commit is contained in:
Shay Banon 2014-05-27 11:08:29 +02:00
parent cd94af2c9e
commit 13f49237df
1 changed files with 10 additions and 8 deletions

View File

@ -258,11 +258,12 @@ public class PagedBytesReferenceTest extends ElasticsearchTestCase {
int length = randomIntBetween(10, PAGE_SIZE * 4);
BytesReference pbr = getRandomizedPagedBytesReference(length);
File tFile = newTempFile();
RandomAccessFile file = new RandomAccessFile(tFile, "rw");
try (RandomAccessFile file = new RandomAccessFile(tFile, "rw")) {
pbr.writeTo(file.getChannel());
assertEquals(pbr.length(), file.length());
assertArrayEquals(pbr.toBytes(), Streams.copyToByteArray(tFile));
}
}
public void testSliceWriteToOutputStream() throws IOException {
int length = randomIntBetween(10, PAGE_SIZE * randomIntBetween(2, 5));
@ -284,11 +285,12 @@ public class PagedBytesReferenceTest extends ElasticsearchTestCase {
int sliceLength = length - sliceOffset;
BytesReference slice = pbr.slice(sliceOffset, sliceLength);
File tFile = newTempFile();
RandomAccessFile file = new RandomAccessFile(tFile, "rw");
try (RandomAccessFile file = new RandomAccessFile(tFile, "rw")) {
slice.writeTo(file.getChannel());
assertEquals(slice.length(), file.length());
assertArrayEquals(slice.toBytes(), Streams.copyToByteArray(tFile));
}
}
public void testToBytes() {
int[] sizes = {0, randomInt(PAGE_SIZE), PAGE_SIZE, randomIntBetween(2, PAGE_SIZE * randomIntBetween(2, 5))};