< prev index next >

test/hotspot/jtreg/runtime/8176717/TestInheritFD.java

8205054: Could not find "lsof" on test machine
Reviewed-by: goetz

8205054: Could not find "lsof" on test machine
Reviewed-by:
-import static java.io.File.createTempFile;
-import static java.lang.Long.parseLong;
-import static java.lang.System.getProperty;
-import static java.nio.file.Files.readAllBytes;
-import static java.util.Arrays.stream;
-import static java.util.stream.Collectors.joining;
-import static java.util.stream.Collectors.toList;
-import static jdk.test.lib.process.ProcessTools.createJavaProcessBuilder;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Collection;
-import java.util.stream.Stream;
-
 /*
  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it

@@ -37,10 +19,30 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ +import static java.io.File.createTempFile; +import static java.lang.Long.parseLong; +import static java.lang.System.getProperty; +import static java.nio.file.Files.readAllBytes; +import static java.util.Arrays.stream; +import static java.util.Collections.emptyList; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static jdk.test.lib.process.ProcessTools.createJavaProcessBuilder; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Stream; + /* * @test TestInheritFD * @bug 8176717 8176809 * @summary a new process should not inherit open file descriptors * @library /test/lib
@@ -161,23 +163,23 } } static Collection<String> outputContainingFilenames() { long pid = ProcessHandle.current().pid(); - String[] command = stream(new String[][]{ + Optional<String[]> command = stream(new String[][]{ {"/usr/bin/lsof", "-p"}, {"/usr/sbin/lsof", "-p"}, {"/bin/lsof", "-p"}, {"/sbin/lsof", "-p"}, {"/usr/local/bin/lsof", "-p"}, {"/usr/bin/pfiles", "-F"}}) // Solaris .filter(args -> new File(args[0]).exists()) - .findFirst() - .orElseThrow(() -> new RuntimeException("could not find lsof-like command")); + .findFirst(); - System.out.println("using command: " + command[0] + " " + command[1]); - return run(command[0], command[1], "" + pid).collect(toList()); + System.out.println("using command: " + command.map((c) -> c[0] + " " + c[1]).orElse("<not found>")); + // if command can not be found return list without log file (some machines does not have "lsof" in the expected place) + return command.map(c -> run(c[0], c[1], "" + pid).collect(toList())).orElse(emptyList()); } static boolean findOpenLogFile(Collection<String> fileNames) { return fileNames.stream() .filter(fileName -> fileName.contains(LOG_SUFFIX))
< prev index next >