# HG changeset patch # User ptisnovs # Date 1313076151 -7200 # Node ID 18e4e42d9d6d6929d64e90d45e9b60edcc4f4ccc # Parent 55a2cf00dc6a1966d1cefd8d2ff15210369cd159 Make sure that the regression test openjdk/jdk/test/java/nio/MappedByteBuffer/Basic.java deletes all its work files. diff -r 55a2cf00dc6a -r 18e4e42d9d6d test/java/nio/MappedByteBuffer/Basic.java --- a/test/java/nio/MappedByteBuffer/Basic.java Thu Aug 11 15:00:46 2011 +0200 +++ b/test/java/nio/MappedByteBuffer/Basic.java Thu Aug 11 17:22:31 2011 +0200 @@ -35,50 +35,61 @@ byte[] srcData = new byte[20]; for (int i=0; i<20; i++) srcData[i] = 3; - File blah = File.createTempFile("blah", null); - blah.deleteOnExit(); - FileOutputStream fos = new FileOutputStream(blah); - FileChannel fc = fos.getChannel(); - fc.write(ByteBuffer.wrap(srcData)); - fc.close(); - fos.close(); + File blah = null; + try { + blah = File.createTempFile("blah", null); + blah.deleteOnExit(); + FileOutputStream fos = new FileOutputStream(blah); + FileChannel fc = fos.getChannel(); + fc.write(ByteBuffer.wrap(srcData)); + fc.close(); + fos.close(); - FileInputStream fis = new FileInputStream(blah); - fc = fis.getChannel(); - MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10); - mbb.load(); - mbb.isLoaded(); - mbb.force(); - if (!mbb.isReadOnly()) - throw new RuntimeException("Incorrect isReadOnly"); + FileInputStream fis = new FileInputStream(blah); + fc = fis.getChannel(); + MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10); + mbb.load(); + mbb.isLoaded(); + mbb.force(); + if (!mbb.isReadOnly()) { + throw new RuntimeException("Incorrect isReadOnly"); + } + + // repeat with unaligned position in file + mbb = fc.map(FileChannel.MapMode.READ_ONLY, 1, 10); + mbb.load(); + mbb.isLoaded(); + mbb.force(); + fc.close(); + fis.close(); - // repeat with unaligned position in file - mbb = fc.map(FileChannel.MapMode.READ_ONLY, 1, 10); - mbb.load(); - mbb.isLoaded(); - mbb.force(); - fc.close(); - fis.close(); + RandomAccessFile raf = new RandomAccessFile(blah, "r"); + fc = raf.getChannel(); + mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10); + if (!mbb.isReadOnly()) { + throw new RuntimeException("Incorrect isReadOnly"); + } + fc.close(); + raf.close(); - RandomAccessFile raf = new RandomAccessFile(blah, "r"); - fc = raf.getChannel(); - mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10); - if (!mbb.isReadOnly()) - throw new RuntimeException("Incorrect isReadOnly"); - fc.close(); - raf.close(); + raf = new RandomAccessFile(blah, "rw"); + fc = raf.getChannel(); + mbb = fc.map(FileChannel.MapMode.READ_WRITE, 0, 10); + if (mbb.isReadOnly()) { + throw new RuntimeException("Incorrect isReadOnly"); + } + fc.close(); + raf.close(); - raf = new RandomAccessFile(blah, "rw"); - fc = raf.getChannel(); - mbb = fc.map(FileChannel.MapMode.READ_WRITE, 0, 10); - if (mbb.isReadOnly()) - throw new RuntimeException("Incorrect isReadOnly"); - fc.close(); - raf.close(); - - // clean-up - mbb = null; - System.gc(); - Thread.sleep(500); + // clean-up + mbb = null; + System.gc(); + Thread.sleep(500); + } + finally { + if (blah != null) { + blah.delete(); + } + } } }