changeset 4531:18e4e42d9d6d

Make sure that the regression test openjdk/jdk/test/java/nio/MappedByteBuffer/Basic.java deletes all its work files.
author ptisnovs
date Thu, 11 Aug 2011 17:22:31 +0200
parents 55a2cf00dc6a
children ac0f32da8dca
files test/java/nio/MappedByteBuffer/Basic.java
diffstat 1 files changed, 52 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- 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();
+            }
+        }
     }
 }