提交 6bce28ac 编写于 作者: A alanb

7012823: TEST_BUG: java/nio/MappedByteBuffer tests leave file mappingsthat prevent clean-up (win)

Reviewed-by: forax
上级 59400f76
...@@ -37,14 +37,17 @@ public class Force { ...@@ -37,14 +37,17 @@ public class Force {
Random random = new Random(); Random random = new Random();
long filesize = random.nextInt(3*1024*1024); long filesize = random.nextInt(3*1024*1024);
int cut = random.nextInt((int)filesize); int cut = random.nextInt((int)filesize);
File file = new File("Blah"); File file = File.createTempFile("Blah", null);
RandomAccessFile raf = new RandomAccessFile(file, "rw"); file.deleteOnExit();
raf.setLength(filesize); try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
FileChannel fc = raf.getChannel(); raf.setLength(filesize);
MappedByteBuffer buf1 = fc.map( FileChannel fc = raf.getChannel();
FileChannel.MapMode.READ_WRITE, cut, filesize-cut); MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, cut, filesize-cut);
buf1.force(); mbb.force();
fc.close(); }
raf.close();
// improve chance that mapped buffer will be unmapped
System.gc();
Thread.sleep(500);
} }
} }
...@@ -37,16 +37,19 @@ public class ZeroMap { ...@@ -37,16 +37,19 @@ public class ZeroMap {
Random random = new Random(); Random random = new Random();
long filesize = random.nextInt(1024*1024); long filesize = random.nextInt(1024*1024);
int cut = random.nextInt((int)filesize); int cut = random.nextInt((int)filesize);
File file = new File("Blah"); File file = File.createTempFile("Blah", null);
RandomAccessFile raf = new RandomAccessFile(file, "rw"); file.deleteOnExit();
raf.setLength(filesize); try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
FileChannel fc = raf.getChannel(); raf.setLength(filesize);
MappedByteBuffer buf1 = fc.map( FileChannel fc = raf.getChannel();
FileChannel.MapMode.READ_WRITE, cut, 0); MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, cut, 0);
buf1.force(); mbb.force();
buf1.load(); mbb.load();
buf1.isLoaded(); mbb.isLoaded();
fc.close(); }
raf.close();
// improve chance that mapped buffer will be unmapped
System.gc();
Thread.sleep(500);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册