< prev index next >

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

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.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;

@@ -12,10 +13,11 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; /* * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -161,23 +163,22 } } 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>")); + return command.map(c -> run(c[0], c[1], "" + pid).collect(toList())).orElse(emptyList()); // if command can not be found return list without log file (some machines does not have "lsof" in the expected place) } static boolean findOpenLogFile(Collection<String> fileNames) { return fileNames.stream() .filter(fileName -> fileName.contains(LOG_SUFFIX))
< prev index next >