[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,10 +258,11 @@ 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");
pbr.writeTo(file.getChannel());
assertEquals(pbr.length(), file.length());
assertArrayEquals(pbr.toBytes(), Streams.copyToByteArray(tFile));
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 {
@ -284,10 +285,11 @@ public class PagedBytesReferenceTest extends ElasticsearchTestCase {
int sliceLength = length - sliceOffset;
BytesReference slice = pbr.slice(sliceOffset, sliceLength);
File tFile = newTempFile();
RandomAccessFile file = new RandomAccessFile(tFile, "rw");
slice.writeTo(file.getChannel());
assertEquals(slice.length(), file.length());
assertArrayEquals(slice.toBytes(), Streams.copyToByteArray(tFile));
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() {