< prev index next >

test/jdk/java/io/FileOutputStream/UnreferencedFOSClosesFd.java

Print this page
rev 50699 : 8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"

*** 23,32 **** --- 23,34 ---- /** * * @test * @modules java.base/java.io:open + * @library /test/lib + * @build jdk.test.lib.util.FileUtils UnreferencedFOSClosesFd * @bug 6524062 * @summary Test to ensure that FOS.finalize() invokes the close() method as per * the specification. * @run main/othervm UnreferencedFOSClosesFd */
*** 39,53 **** --- 41,59 ---- import java.lang.management.OperatingSystemMXBean; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.lang.reflect.Field; + import java.nio.file.Path; + import java.util.ArrayDeque; import java.util.HashSet; import java.util.concurrent.atomic.AtomicInteger; import com.sun.management.UnixOperatingSystemMXBean; + import jdk.test.lib.util.FileUtils; + public class UnreferencedFOSClosesFd { enum CleanupType { CLOSE, // Cleanup is handled via calling close CLEANER} // Cleanup is handled via Cleaner
*** 131,142 **** inFile.createNewFile(); inFile.deleteOnExit(); String name = inFile.getPath(); long fdCount0 = getFdCount(); - System.out.printf("initial count of open file descriptors: %d%n", fdCount0); int failCount = 0; failCount += test(new FileOutputStream(name), CleanupType.CLEANER); failCount += test(new StreamOverrides(name), CleanupType.CLEANER); --- 137,148 ---- inFile.createNewFile(); inFile.deleteOnExit(); String name = inFile.getPath(); + FileUtils.listFileDescriptors(System.out); long fdCount0 = getFdCount(); int failCount = 0; failCount += test(new FileOutputStream(name), CleanupType.CLEANER); failCount += test(new StreamOverrides(name), CleanupType.CLEANER);
*** 151,164 **** throw new AssertionError("Failed test count: " + failCount); } // Check the final count of open file descriptors long fdCount = getFdCount(); - System.out.printf("final count of open file descriptors: %d%n", fdCount); if (fdCount != fdCount0) { ! throw new AssertionError("raw fd count wrong: expected: " + fdCount0 ! + ", actual: " + fdCount); } } // Get the count of open file descriptors, or -1 if not available private static long getFdCount() { --- 157,170 ---- throw new AssertionError("Failed test count: " + failCount); } // Check the final count of open file descriptors long fdCount = getFdCount(); if (fdCount != fdCount0) { ! System.out.printf("initial count of open file descriptors: %d%n", fdCount0); ! System.out.printf("final count of open file descriptors: %d%n", fdCount); ! FileUtils.listFileDescriptors(System.out); } } // Get the count of open file descriptors, or -1 if not available private static long getFdCount() {
< prev index next >