< prev index next >
test/jdk/java/io/RandomAccessFile/UnreferencedRAFClosesFd.java
Print this page
rev 50699 : 8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
*** 22,46 ****
--- 22,53 ----
*/
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
+ import java.io.IOException;
import java.io.RandomAccessFile;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.ref.Cleaner;
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 com.sun.management.UnixOperatingSystemMXBean;
+ import jdk.test.lib.util.FileUtils;
+
/**
* @test
* @bug 8080225
+ * @library /test/lib
+ * @build jdk.test.lib.util.FileUtils UnreferencedRAFClosesFd
* @modules java.base/java.io:open
* @summary Test to ensure that an unclosed and unreferenced RandomAccessFile closes the fd
* @run main/othervm UnreferencedRAFClosesFd
*/
public class UnreferencedRAFClosesFd {
*** 52,63 ****
File inFile= new File(System.getProperty("test.dir", "."), FILE_NAME);
inFile.createNewFile();
inFile.deleteOnExit();
long fdCount0 = getFdCount();
- System.out.printf("initial count of open file descriptors: %d%n", fdCount0);
String name = inFile.getPath();
RandomAccessFile raf;
try {
// raf is explicitly *not* closed to allow cleaner to work
--- 59,70 ----
File inFile= new File(System.getProperty("test.dir", "."), FILE_NAME);
inFile.createNewFile();
inFile.deleteOnExit();
+ FileUtils.listFileDescriptors(System.out);
long fdCount0 = getFdCount();
String name = inFile.getPath();
RandomAccessFile raf;
try {
// raf is explicitly *not* closed to allow cleaner to work
*** 99,112 ****
Reference.reachabilityFence(raf);
Reference.reachabilityFence(pending);
// 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
--- 106,119 ----
Reference.reachabilityFence(raf);
Reference.reachabilityFence(pending);
// 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
< prev index next >